From d00926780176604c030ba04fb4efb0f1a24c82cf Mon Sep 17 00:00:00 2001
From: Olcan <olcans@gmail.com>
Date: Sun, 1 Jun 2025 16:52:31 -0700
Subject: more strict italics: delimiters cannot be preceded/followed by \w or
 [./\\]\S (#677)

---
 packages/cli/src/ui/utils/MarkdownDisplay.tsx | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

(limited to 'packages/cli/src/ui/utils/MarkdownDisplay.tsx')

diff --git a/packages/cli/src/ui/utils/MarkdownDisplay.tsx b/packages/cli/src/ui/utils/MarkdownDisplay.tsx
index 83fb46ee..d93b5be2 100644
--- a/packages/cli/src/ui/utils/MarkdownDisplay.tsx
+++ b/packages/cli/src/ui/utils/MarkdownDisplay.tsx
@@ -231,9 +231,17 @@ const RenderInlineInternal: React.FC<RenderInlineProps> = ({ text }) => {
           </Text>
         );
       } else if (
+        fullMatch.length > ITALIC_MARKER_LENGTH * 2 &&
         ((fullMatch.startsWith('*') && fullMatch.endsWith('*')) ||
           (fullMatch.startsWith('_') && fullMatch.endsWith('_'))) &&
-        fullMatch.length > ITALIC_MARKER_LENGTH * 2
+        !/\w/.test(text.substring(match.index - 1, match.index)) &&
+        !/\w/.test(
+          text.substring(inlineRegex.lastIndex, inlineRegex.lastIndex + 1),
+        ) &&
+        !/\S[./\\]/.test(text.substring(match.index - 2, match.index)) &&
+        !/[./\\]\S/.test(
+          text.substring(inlineRegex.lastIndex, inlineRegex.lastIndex + 2),
+        )
       ) {
         renderedNode = (
           <Text key={key} italic>
-- 
cgit v1.2.3

