git.iko.soy/typeable/pandoc
on master help sign in
Muse writer: escape horizontal rule only if at the beginning of the line
commit87dda2109d01098dcf41c01559d3e91e2627cd10 authorAlexander Krotov <ilabdsf@gmail.com> dateThu 5 Apr 2018, 19:48 (9 years ago) parent1610488
2 files changed+11−4
src/Text/Pandoc/Writers/Muse.hs+8−3 test/Tests/Writers/Muse.hs+3−1
src/Text/Pandoc/Writers/Muse.hs+8−3
@@ -325,7 +325,6 @@ conditionalEscapeString :: Bool -> String -> String
325325conditionalEscapeString isInsideLinkDescription s =
326326 if any (`elem` ("#*<=>|" :: String)) s ||
327327 "::" `isInfixOf` s ||
328− "----" `isInfixOf` s ||
329328 "~~" `isInfixOf` s ||
330329 "[[" `isInfixOf` s ||
331330 ("]" `isInfixOf` s && isInsideLinkDescription) ||
@@ -395,12 +394,18 @@ urlEscapeBrackets (']':xs) = '%':'5':'D':urlEscapeBrackets xs
395394urlEscapeBrackets (x:xs) = x:urlEscapeBrackets xs
396395urlEscapeBrackets [] = []
397396
397+isHorizontalRule :: String -> Bool
398+isHorizontalRule s =
399+ ((length xs) >= 4) && null ys
400+ where (xs, ys) = span (== '-') s
401+
398402fixOrEscape :: Bool -> Inline -> Bool
399403fixOrEscape sp (Str "-") = sp
400404fixOrEscape sp (Str ";") = not sp
401−fixOrEscape sp (Str s) = sp && (startsWithMarker isDigit s ||
405+fixOrEscape sp (Str s) = (sp && (startsWithMarker isDigit s ||
402406 startsWithMarker isAsciiLower s ||
403− startsWithMarker isAsciiUpper s)
407+ startsWithMarker isAsciiUpper s))
408+ || isHorizontalRule s
404409fixOrEscape _ Space = True
405410fixOrEscape _ SoftBreak = True
406411fixOrEscape _ _ = False
test/Tests/Writers/Muse.hs+3−1
@@ -259,7 +259,9 @@ tests = [ testGroup "block elements"
259259 ]
260260 ]
261261 , "horizontal rule" =: horizontalRule =?> "----"
262− , "escape horizontal rule" =: para (text "----") =?> "<verbatim>----</verbatim>"
262+ , "escape horizontal rule" =: para (text "----") =?> "<verbatim></verbatim>----"
263+ , "escape long horizontal rule" =: para (text "----------") =?> "<verbatim></verbatim>----------"
264+ , "don't escape horizontal inside paragraph" =: para (text "foo ---- bar") =?> "foo ---- bar"
263265 , "escape nonbreaking space" =: para (text "~~") =?> "<verbatim>~~</verbatim>"
264266 , testGroup "tables"
265267 [ "table without header" =: