git.iko.soy/typeable/pandoc
on master help sign in
Muse writer: escape -, ; and > in the beginning of strings
cb28cabAlexander Krotov
src/Text/Pandoc/Writers/Muse.hs+6−3
@@ -437,12 +437,15 @@ stringStartsWithSpace [] = False
437
437
438fixOrEscape :: Bool -> Inline -> Bool
438fixOrEscape :: Bool -> Inline -> Bool
439fixOrEscape sp (Str "-") = sp
439fixOrEscape sp (Str "-") = sp
440−fixOrEscape sp (Str ";") = not sp
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
441−fixOrEscape _ (Str ">") = True
443+fixOrEscape _ (Str (">")) = True
444+fixOrEscape _ (Str ('>':x:_)) = isSpace x
442fixOrEscape sp (Str s) = (sp && (startsWithMarker isDigit s ||
445fixOrEscape sp (Str s) = (sp && (startsWithMarker isDigit s ||
443 startsWithMarker isAsciiLower s ||
446 startsWithMarker isAsciiLower s ||
444 startsWithMarker isAsciiUpper s))
447 startsWithMarker isAsciiUpper s))
445− || isHorizontalRule s || stringStartsWithSpace s
448+ || stringStartsWithSpace s
446fixOrEscape _ Space = True
449fixOrEscape _ Space = True
447fixOrEscape _ SoftBreak = True
450fixOrEscape _ SoftBreak = True
448fixOrEscape _ _ = False
451fixOrEscape _ _ = False
test/Tests/Writers/Muse.hs+10
@@ -283,6 +283,7 @@ tests = [ testGroup "block elements"
283 , "don't escape horizontal inside paragraph" =: para (text "foo ---- bar") =?> "foo ---- bar"
283 , "don't escape horizontal inside paragraph" =: para (text "foo ---- bar") =?> "foo ---- bar"
284 , "escape nonbreaking space" =: para (text "~~") =?> "<verbatim>~~</verbatim>"
284 , "escape nonbreaking space" =: para (text "~~") =?> "<verbatim>~~</verbatim>"
285 , "escape > in the beginning of line" =: para (text "> foo bar") =?> "<verbatim></verbatim>> foo bar"
285 , "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"
286 , testGroup "tables"
287 , testGroup "tables"
287 [ "table without header" =:
288 [ "table without header" =:
288 let rows = [[para $ text "Para 1.1", para $ text "Para 1.2"]
289 let rows = [[para $ text "Para 1.1", para $ text "Para 1.2"]
@@ -348,6 +349,14 @@ tests = [ testGroup "block elements"
348 , ""
349 , ""
349 , " <verbatim></verbatim>- bar"
350 , " <verbatim></verbatim>- bar"
350 ]
351 ]
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+ ]
351 , "escape - inside a note" =:
360 , "escape - inside a note" =:
352 note (para (text "- foo")) =?>
361 note (para (text "- foo")) =?>
353 unlines [ "[1]"
362 unlines [ "[1]"
@@ -355,6 +364,7 @@ tests = [ testGroup "block elements"
355 , "[1] <verbatim></verbatim>- foo"
364 , "[1] <verbatim></verbatim>- foo"
356 ]
365 ]
357 , "escape ; to avoid accidental comments" =: text "; foo" =?> "<verbatim></verbatim>; foo"
366 , "escape ; to avoid accidental comments" =: text "; foo" =?> "<verbatim></verbatim>; foo"
367+ , "escape strings starting with ; and space" =: str "; foo" =?> "<verbatim></verbatim>; foo"
358 , "escape ; after softbreak" =: text "foo" <> softbreak <> text "; bar" =?> "foo\n<verbatim></verbatim>; bar"
368 , "escape ; after softbreak" =: text "foo" <> softbreak <> text "; bar" =?> "foo\n<verbatim></verbatim>; bar"
359 , "escape ; after linebreak" =: text "foo" <> linebreak <> text "; bar" =?> "foo<br>\n<verbatim></verbatim>; bar"
369 , "escape ; after linebreak" =: text "foo" <> linebreak <> text "; bar" =?> "foo<br>\n<verbatim></verbatim>; bar"
360 , "do not escape ; inside paragraph" =: text "foo ; bar" =?> "foo ; bar"
370 , "do not escape ; inside paragraph" =: text "foo ; bar" =?> "foo ; bar"