Skip to content

Commit

Permalink
Mediawiki writer: escape line-initial characters...
Browse files Browse the repository at this point in the history
...that would otherwise be interpreted as list starts.

Closes #9700.
  • Loading branch information
jgm committed Dec 20, 2024
1 parent 74f64f3 commit cfb9bd5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/Text/Pandoc/Writers/MediaWiki.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 == '*'
14 changes: 14 additions & 0 deletions test/command/9700.md
Original file line number Diff line number Diff line change
@@ -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
```

0 comments on commit cfb9bd5

Please sign in to comment.