git.iko.soy/typeable/pandoc
on master help sign in
Muse writer: escape secondary notes
2c7c8a6Alexander Krotov
src/Text/Pandoc/Writers/Muse.hs+10−7
@@ -377,10 +377,11 @@ startsWithMarker f (x:xs) =
377 startsWithDot _ = False
377 startsWithDot _ = False
378startsWithMarker _ [] = False
378startsWithMarker _ [] = False
379
379
380−containsFootnotes :: String -> Bool
380+containsNotes :: Char -> Char -> String -> Bool
381−containsFootnotes = p
381+containsNotes left right = p
382− where p ('[':xs) = q xs || p xs
382+ where p (left':xs)
383− p (_:xs) = p xs
383+ | left' == left = q xs || p xs
384+ | otherwise = p xs
384 p "" = False
385 p "" = False
385 q (x:xs)
386 q (x:xs)
386 | x `elem` ("123456789"::String) = r xs || p xs
387 | x `elem` ("123456789"::String) = r xs || p xs
@@ -388,8 +389,9 @@ containsFootnotes = p
388 q [] = False
389 q [] = False
389 r ('0':xs) = r xs || p xs
390 r ('0':xs) = r xs || p xs
390 r xs = s xs || q xs || p xs
391 r xs = s xs || q xs || p xs
392+ s (right':xs)
391− s (']':_) = True
393+ | right' == right = True
392− s (_:xs) = p xs
394+ | otherwise = p xs
393 s [] = False
395 s [] = False
394
396
395-- | Return True if string should be escaped with <verbatim> tags
397-- | Return True if string should be escaped with <verbatim> tags
@@ -404,7 +406,8 @@ shouldEscapeString s = do
404 "~~" `isInfixOf` s ||
406 "~~" `isInfixOf` s ||
405 "[[" `isInfixOf` s ||
407 "[[" `isInfixOf` s ||
406 ("]" `isInfixOf` s && insideLink) ||
408 ("]" `isInfixOf` s && insideLink) ||
407− containsFootnotes s
409+ containsNotes '[' ']' s ||
410+ containsNotes '{' '}' s
408
411
409-- | Escape special characters for Muse if needed.
412-- | Escape special characters for Muse if needed.
410conditionalEscapeString :: PandocMonad m
413conditionalEscapeString :: PandocMonad m
test/Tests/Writers/Muse.hs+1
@@ -428,6 +428,7 @@ tests = [ testGroup "block elements"
428 [ testGroup "string"
428 [ testGroup "string"
429 [ "string" =: str "foo" =?> "foo"
429 [ "string" =: str "foo" =?> "foo"
430 , "escape footnote" =: str "[1]" =?> "<verbatim>[1]</verbatim>"
430 , "escape footnote" =: str "[1]" =?> "<verbatim>[1]</verbatim>"
431+ , "escape secondary note" =: str "{1}" =?> "<verbatim>{1}</verbatim>"
431 , "do not escape brackets" =: str "[12ab]" =?> "[12ab]"
432 , "do not escape brackets" =: str "[12ab]" =?> "[12ab]"
432 , "escape verbatim close tag" =: str "foo</verbatim>bar"
433 , "escape verbatim close tag" =: str "foo</verbatim>bar"
433 =?> "<verbatim>foo<</verbatim><verbatim>/verbatim>bar</verbatim>"
434 =?> "<verbatim>foo<</verbatim><verbatim>/verbatim>bar</verbatim>"