mirror of
https://github.com/jgm/pandoc.git
synced 2026-08-28 17:20:47 +08:00
Org writer: escape literal *, |, # at beginning of line with ZWS.
Closes #9159.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
```
|
||||
% pandoc -t org -f markdown
|
||||
\* See Blah
|
||||
|
||||
\# not comment
|
||||
|
||||
\| not table \|
|
||||
^D
|
||||
* See Blah
|
||||
|
||||
# not comment
|
||||
|
||||
| not table |
|
||||
|
||||
```
|
||||
Reference in New Issue
Block a user