From 2c7c8a6f407a6299f7f7345ca9203fae6fb4bcde Mon Sep 17 00:00:00 2001 From: Alexander Krotov Date: Mon, 18 Feb 2019 15:21:17 +0300 Subject: [PATCH] Muse writer: escape secondary notes --- src/Text/Pandoc/Writers/Muse.hs | 17 ++++++++++------- test/Tests/Writers/Muse.hs | 1 + 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/Text/Pandoc/Writers/Muse.hs b/src/Text/Pandoc/Writers/Muse.hs index c09545e85..2ceeaab37 100644 --- a/src/Text/Pandoc/Writers/Muse.hs +++ b/src/Text/Pandoc/Writers/Muse.hs @@ -377,10 +377,11 @@ startsWithMarker f (x:xs) = startsWithDot _ = False startsWithMarker _ [] = False -containsFootnotes :: String -> Bool -containsFootnotes = p - where p ('[':xs) = q xs || p xs - p (_:xs) = p xs +containsNotes :: Char -> Char -> String -> Bool +containsNotes left right = p + where p (left':xs) + | left' == left = q xs || p xs + | otherwise = p xs p "" = False q (x:xs) | x `elem` ("123456789"::String) = r xs || p xs @@ -388,8 +389,9 @@ containsFootnotes = p q [] = False r ('0':xs) = r xs || p xs r xs = s xs || q xs || p xs - s (']':_) = True - s (_:xs) = p xs + s (right':xs) + | right' == right = True + | otherwise = p xs s [] = False -- | Return True if string should be escaped with tags @@ -404,7 +406,8 @@ shouldEscapeString s = do "~~" `isInfixOf` s || "[[" `isInfixOf` s || ("]" `isInfixOf` s && insideLink) || - containsFootnotes s + containsNotes '[' ']' s || + containsNotes '{' '}' s -- | Escape special characters for Muse if needed. conditionalEscapeString :: PandocMonad m diff --git a/test/Tests/Writers/Muse.hs b/test/Tests/Writers/Muse.hs index c2439b1a2..834422a59 100644 --- a/test/Tests/Writers/Muse.hs +++ b/test/Tests/Writers/Muse.hs @@ -428,6 +428,7 @@ tests = [ testGroup "block elements" [ testGroup "string" [ "string" =: str "foo" =?> "foo" , "escape footnote" =: str "[1]" =?> "[1]" + , "escape secondary note" =: str "{1}" =?> "{1}" , "do not escape brackets" =: str "[12ab]" =?> "[12ab]" , "escape verbatim close tag" =: str "foobar" =?> "foo</verbatim>bar"