about summary refs log tree commit diff stats
path: root/adapter
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-02-01 17:01:13 +0100
committerbptato <nincsnevem662@gmail.com>2024-02-01 17:05:18 +0100
commitf05b41c13db271ba40feb0a64005f86b44c7a9e8 (patch)
treeac2935f50001db0b69c41179b34f79a786b2108c /adapter
parent452cb7323eae6c438cd828632748aaa13fb92b0e (diff)
downloadchawan-f05b41c13db271ba40feb0a64005f86b44c7a9e8.tar.gz
md2html: improved underscore ignoring rules
Only ignore when prev/next chars are not alnum.
Diffstat (limited to 'adapter')
-rw-r--r--adapter/format/md2html.nim6
1 files changed, 4 insertions, 2 deletions
diff --git a/adapter/format/md2html.nim b/adapter/format/md2html.nim
index 2dc14404..cd9cebab 100644
--- a/adapter/format/md2html.nim
+++ b/adapter/format/md2html.nim
@@ -47,7 +47,7 @@ proc getId(line: openArray[char]): string =
 type InlineState = enum
   isItalic, isBold, isCode, isComment
 
-const AsciiWhitespace = {' ', '\t', '\n', '\r'}
+const AsciiAlphaNumeric = {'0'..'9', 'A'..'Z', 'a'..'z'}
 proc parseInline(line: openArray[char]) =
   var state: set[InlineState] = {}
   var bs = bsNone
@@ -88,7 +88,9 @@ proc parseInline(line: openArray[char]) =
       else: append c
     elif c == '\\':
       quote = true
-    elif c == '*' or c == '_' and (i == 0 or line[i - 1] in AsciiWhitespace):
+    elif c == '*' or c == '_' and
+        (i == 0 or line[i - 1] notin AsciiAlphaNumeric or
+        i + 1 >= line.len or line[i + 1] notin AsciiAlphaNumeric + {'_'}):
       if i + 1 < line.len and line[i + 1] == c:
         if state.toggle(isBold):
           append "<B>"