diff options
| author | John MacFarlane <[email protected]> | 2023-10-26 09:18:56 -0700 |
|---|---|---|
| committer | John MacFarlane <[email protected]> | 2023-10-26 09:18:56 -0700 |
| commit | b671e0dfe5f578511954addaca84b832826d5915 (patch) | |
| tree | af22d4db86320f3de7f59d07343cf3040539a6b2 /src | |
| parent | 4457b775d3f815471b0cad72d516d86102d15895 (diff) | |
Org writer: escape literal `*`, `|`, `#` at beginning of line with ZWS.
Closes #9159.
Diffstat (limited to 'src')
| -rw-r--r-- | src/Text/Pandoc/Writers/Org.hs | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/src/Text/Pandoc/Writers/Org.hs b/src/Text/Pandoc/Writers/Org.hs index dc7a566bc..a283d0265 100644 --- a/src/Text/Pandoc/Writers/Org.hs +++ b/src/Text/Pandoc/Writers/Org.hs @@ -90,16 +90,19 @@ noteToOrg num note = do return $ hang (length marker) (text marker) contents -- | Escape special characters for Org. -escapeString :: Text -> Text +escapeString :: Text -> Doc Text escapeString t - | T.all (\c -> c < '\x2013' || c > '\x2026') t = t - | otherwise = T.concatMap escChar t + | T.all isAlphaNum t = literal t + | otherwise = mconcat $ map escChar (T.unpack t) where escChar '\x2013' = "--" escChar '\x2014' = "---" escChar '\x2019' = "'" escChar '\x2026' = "..." - escChar c = T.singleton c + escChar c + -- escape special chars with ZERO WIDTH SPACE as org manual suggests + | c == '*' || c == '#' || c == '|' = afterBreak "\x200B" <> char c + | otherwise = char c isRawFormat :: Format -> Bool isRawFormat f = @@ -489,7 +492,7 @@ inlineToOrg (Cite cs lst) = do return $ "[cite" <> sty <> ":" <> citeItems <> "]" else inlineListToOrg lst inlineToOrg (Code _ str) = return $ "=" <> literal str <> "=" -inlineToOrg (Str str) = return . literal $ escapeString str +inlineToOrg (Str str) = return $ escapeString str inlineToOrg (Math t str) = do modify $ \st -> st{ stHasMath = True } return $ if t == InlineMath |
