From 71776661cd0ceceb896ce668b99f1df373f6e1b0 Mon Sep 17 00:00:00 2001 From: Alexander Krotov Date: Sun, 16 Sep 2018 20:59:59 +0300 Subject: Muse writer: replace newlines in strings with spaces --- src/Text/Pandoc/Writers/Muse.hs | 8 +++++++- test/Tests/Writers/Muse.hs | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Text/Pandoc/Writers/Muse.hs b/src/Text/Pandoc/Writers/Muse.hs index 1f081348e..18aebc364 100644 --- a/src/Text/Pandoc/Writers/Muse.hs +++ b/src/Text/Pandoc/Writers/Muse.hs @@ -308,6 +308,12 @@ escapeString s = substitute "" "</verbatim>" s ++ "" +-- | Replace newlines with spaces +replaceNewlines :: String -> String +replaceNewlines ('\n':xs) = ' ':replaceNewlines xs +replaceNewlines (x:xs) = x:replaceNewlines xs +replaceNewlines [] = [] + startsWithMarker :: (Char -> Bool) -> String -> Bool startsWithMarker f (' ':xs) = startsWithMarker f xs startsWithMarker f (x:xs) = @@ -517,7 +523,7 @@ inlineToMuse :: PandocMonad m => Inline -> Muse m Doc inlineToMuse (Str str) = do - escapedStr <- conditionalEscapeString str + escapedStr <- conditionalEscapeString $ replaceNewlines str let useTags = isAlphaNum $ last escapedStr -- escapedStr is never empty because empty strings are escaped modify $ \st -> st { stUseTags = useTags } return $ text escapedStr diff --git a/test/Tests/Writers/Muse.hs b/test/Tests/Writers/Muse.hs index 614e9dbc6..f7287d57d 100644 --- a/test/Tests/Writers/Muse.hs +++ b/test/Tests/Writers/Muse.hs @@ -375,6 +375,7 @@ tests = [ testGroup "block elements" , "escape ; after softbreak" =: text "foo" <> softbreak <> text "; bar" =?> "foo\n; bar" , "escape ; after linebreak" =: text "foo" <> linebreak <> text "; bar" =?> "foo
\n; bar" , "do not escape ; inside paragraph" =: text "foo ; bar" =?> "foo ; bar" + , "escape newlines" =: str "foo\nbar" =?> "foo bar" ] , testGroup "emphasis" [ "emphasis" =: emph (text "foo") =?> "*foo*" -- cgit v1.2.3