Skip to content

Commit 4e8a22e

Browse files
committed
fix(pd2norg): escape inline modifier content if starts with bar |
1 parent 51cb1f6 commit 4e8a22e

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

src/pd2norg.nim

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,21 +180,26 @@ proc toStr*(self: PDInlineLink): string =
180180
else:
181181
unreachable(&"PDInlineLink: {self.t=}")
182182

183+
proc escapeBar*(text: string): string =
184+
if text.startsWith('|') or text.endsWith('|'):
185+
return "|" & text & "|"
186+
return text
187+
183188
proc toStr*(self: PDInlineCode): string =
184189
let (attr, text) = self.c
185190
let lang = if attr.classes.len > 0: &"(code:{attr.classes[0]})" else: ""
186-
&"`{text}`{lang}"
191+
&"`{escapeBar(text)}`{lang}"
187192

188193
proc toStr*(self: PDInlineEmph): string =
189194
let symbol = symbols[self.t]
190-
defer: result = &"{symbol}{result}{symbol}"
195+
defer: result = &"{symbol}{escapeBar(result)}{symbol}"
191196
result = self.c.toStr()
192197
if result[^1] == '\n':
193198
return result[0 ..< ^1]
194199

195200
proc rawEmbed*(s: string, lang: string): string =
196201
if s.find('\n') < 0:
197-
return &"`| {s} |`(embed:{lang})"
202+
return &"`|{s}|`(embed:{lang})"
198203
else:
199204
return joinWithNewline("@embed " & lang, s.strip(), "@end")
200205

0 commit comments

Comments
 (0)