git.iko.soy/typeable/pandoc
on master help sign in
Muse writer: escape -, ; and > in the beginning of strings
commitcb28cab489279c48f0afd7113a75ccd96f43eaba authorAlexander Krotov <ilabdsf@gmail.com> dateTue 11 Sep 2018, 11:35 (8 years ago) parent67bcb3d
2 files changed+16−3
src/Text/Pandoc/Writers/Muse.hs+6−3 test/Tests/Writers/Muse.hs+10
src/Text/Pandoc/Writers/Muse.hs+6−3
@@ -437,12 +437,15 @@ stringStartsWithSpace [] = False
437437
438438fixOrEscape :: Bool -> Inline -> Bool
439439fixOrEscape sp (Str "-") = sp
440−fixOrEscape sp (Str ";") = not sp
441−fixOrEscape _ (Str ">") = True
440+fixOrEscape sp (Str s@('-':x:_)) = (sp && isSpace x) || isHorizontalRule s
441+fixOrEscape sp (Str (";")) = not sp
442+fixOrEscape sp (Str (';':x:_)) = not sp && isSpace x
443+fixOrEscape _ (Str (">")) = True
444+fixOrEscape _ (Str ('>':x:_)) = isSpace x
442445fixOrEscape sp (Str s) = (sp && (startsWithMarker isDigit s ||
443446 startsWithMarker isAsciiLower s ||
444447 startsWithMarker isAsciiUpper s))
445− || isHorizontalRule s || stringStartsWithSpace s
448+ || stringStartsWithSpace s
446449fixOrEscape _ Space = True
447450fixOrEscape _ SoftBreak = True
448451fixOrEscape _ _ = False
test/Tests/Writers/Muse.hs+10
@@ -283,6 +283,7 @@ tests = [ testGroup "block elements"
283283 , "don't escape horizontal inside paragraph" =: para (text "foo ---- bar") =?> "foo ---- bar"
284284 , "escape nonbreaking space" =: para (text "~~") =?> "<verbatim>~~</verbatim>"
285285 , "escape > in the beginning of line" =: para (text "> foo bar") =?> "<verbatim></verbatim>> foo bar"
286+ , "escape string with > and space in the beginning of line" =: para (str "> foo bar") =?> "<verbatim></verbatim>> foo bar"
286287 , testGroup "tables"
287288 [ "table without header" =:
288289 let rows = [[para $ text "Para 1.1", para $ text "Para 1.2"]
@@ -348,6 +349,14 @@ tests = [ testGroup "block elements"
348349 , ""
349350 , " <verbatim></verbatim>- bar"
350351 ]
352+ , "escape strings starting with - inside a list" =:
353+ bulletList [ para (str "foo") <>
354+ para (str "- bar")
355+ ] =?>
356+ unlines [ " - foo"
357+ , ""
358+ , " <verbatim></verbatim>- bar"
359+ ]
351360 , "escape - inside a note" =:
352361 note (para (text "- foo")) =?>
353362 unlines [ "[1]"
@@ -355,6 +364,7 @@ tests = [ testGroup "block elements"
355364 , "[1] <verbatim></verbatim>- foo"
356365 ]
357366 , "escape ; to avoid accidental comments" =: text "; foo" =?> "<verbatim></verbatim>; foo"
367+ , "escape strings starting with ; and space" =: str "; foo" =?> "<verbatim></verbatim>; foo"
358368 , "escape ; after softbreak" =: text "foo" <> softbreak <> text "; bar" =?> "foo\n<verbatim></verbatim>; bar"
359369 , "escape ; after linebreak" =: text "foo" <> linebreak <> text "; bar" =?> "foo<br>\n<verbatim></verbatim>; bar"
360370 , "do not escape ; inside paragraph" =: text "foo ; bar" =?> "foo ; bar"