diff options
| author | John MacFarlane <[email protected]> | 2024-12-20 10:31:43 -0800 |
|---|---|---|
| committer | John MacFarlane <[email protected]> | 2024-12-20 10:31:43 -0800 |
| commit | cfb9bd5cf30bb67fc662b67f8645c9d6ed3d72df (patch) | |
| tree | 2c33e0cb92fef8afd6b4f818c1deef7c4f19fc39 | |
| parent | 74f64f33e47fa61172cc94c23a8811a6b4c6eeec (diff) | |
Mediawiki writer: escape line-initial characters...
...that would otherwise be interpreted as list starts.
Closes #9700.
| -rw-r--r-- | src/Text/Pandoc/Writers/MediaWiki.hs | 11 | ||||
| -rw-r--r-- | test/command/9700.md | 14 |
2 files changed, 24 insertions, 1 deletions
diff --git a/src/Text/Pandoc/Writers/MediaWiki.hs b/src/Text/Pandoc/Writers/MediaWiki.hs index 5e8cbb095..10823c8db 100644 --- a/src/Text/Pandoc/Writers/MediaWiki.hs +++ b/src/Text/Pandoc/Writers/MediaWiki.hs @@ -117,9 +117,12 @@ blockToMediaWiki (Para inlines) = do tags <- asks useTags lev <- asks listLevel contents <- inlineListToMediaWiki inlines + let initEsc = if startsWithListMarker contents -- #9700 + then "\\" + else "" return $ if tags then "<p>" <> contents <> "</p>" - else contents <> if null lev then "\n" else "" + else initEsc <> contents <> if null lev then "\n" else "" blockToMediaWiki (LineBlock lns) = blockToMediaWiki $ linesToPara lns @@ -1144,3 +1147,9 @@ highlightingLangs = Set.fromList [ "yaml", "yaml+jinja", "zephir" ] + +startsWithListMarker :: Text -> Bool +startsWithListMarker t = + case T.uncons t of + Nothing -> False + Just (c,_) -> c == '#' || c == ':' || c == ';' || c == '*' diff --git a/test/command/9700.md b/test/command/9700.md new file mode 100644 index 000000000..f018164fe --- /dev/null +++ b/test/command/9700.md @@ -0,0 +1,14 @@ +``` +% pandoc -t mediawiki +This is a normal sentence with a manual text footnote\* + +\* The footnote explains why it couldn't just be inside parentheses + +\#foobar \#foobar +^D +This is a normal sentence with a manual text footnote* + +\* The footnote explains why it couldn’t just be inside parentheses + +\#foobar #foobar +``` |
