git.iko.soy/typeable/pandoc
on master help sign in
Muse writer: replace newlines in strings with spaces
commit71776661cd0ceceb896ce668b99f1df373f6e1b0 authorAlexander Krotov <ilabdsf@gmail.com> dateSun 16 Sep 2018, 20:59 (8 years ago) parent18fed9f
2 files changed+8−1
src/Text/Pandoc/Writers/Muse.hs+7−1 test/Tests/Writers/Muse.hs+1
src/Text/Pandoc/Writers/Muse.hs+7−1
@@ -308,6 +308,12 @@ escapeString s =
308308 substitute "</verbatim>" "<</verbatim><verbatim>/verbatim>" s ++
309309 "</verbatim>"
310310
311+-- | Replace newlines with spaces
312+replaceNewlines :: String -> String
313+replaceNewlines ('\n':xs) = ' ':replaceNewlines xs
314+replaceNewlines (x:xs) = x:replaceNewlines xs
315+replaceNewlines [] = []
316+
311317startsWithMarker :: (Char -> Bool) -> String -> Bool
312318startsWithMarker f (' ':xs) = startsWithMarker f xs
313319startsWithMarker f (x:xs) =
@@ -517,7 +523,7 @@ inlineToMuse :: PandocMonad m
517523 => Inline
518524 -> Muse m Doc
519525inlineToMuse (Str str) = do
520− escapedStr <- conditionalEscapeString str
526+ escapedStr <- conditionalEscapeString $ replaceNewlines str
521527 let useTags = isAlphaNum $ last escapedStr -- escapedStr is never empty because empty strings are escaped
522528 modify $ \st -> st { stUseTags = useTags }
523529 return $ text escapedStr
test/Tests/Writers/Muse.hs+1
@@ -375,6 +375,7 @@ tests = [ testGroup "block elements"
375375 , "escape ; after softbreak" =: text "foo" <> softbreak <> text "; bar" =?> "foo\n<verbatim></verbatim>; bar"
376376 , "escape ; after linebreak" =: text "foo" <> linebreak <> text "; bar" =?> "foo<br>\n<verbatim></verbatim>; bar"
377377 , "do not escape ; inside paragraph" =: text "foo ; bar" =?> "foo ; bar"
378+ , "escape newlines" =: str "foo\nbar" =?> "foo bar"
378379 ]
379380 , testGroup "emphasis"
380381 [ "emphasis" =: emph (text "foo") =?> "*foo*"