From afedb41b170cd9198ab589567f39e99717667a31 Mon Sep 17 00:00:00 2001 From: Alexander Krotov Date: Sun, 10 Sep 2017 12:42:24 +0300 Subject: Muse reader: trim newlines from s --- src/Text/Pandoc/Readers/Muse.hs | 11 ++++++++++- test/Tests/Readers/Muse.hs | 25 +++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/Text/Pandoc/Readers/Muse.hs b/src/Text/Pandoc/Readers/Muse.hs index 3b089772f..f70085c54 100644 --- a/src/Text/Pandoc/Readers/Muse.hs +++ b/src/Text/Pandoc/Readers/Muse.hs @@ -223,7 +223,16 @@ header = try $ do return $ B.headerWith attr level <$> content exampleTag :: PandocMonad m => MuseParser m (F Blocks) -exampleTag = liftM (return . uncurry B.codeBlockWith) $ htmlElement "example" +exampleTag = do + (attr, contents) <- htmlElement "example" + return $ return $ B.codeBlockWith attr $ chop contents + where lchop s = case s of + '\n':ss -> ss + _ -> s + rchop = reverse . lchop . reverse + -- Trim up to one newline from the beginning and the end, + -- in case opening and/or closing tags are on separate lines. + chop = lchop . rchop literal :: PandocMonad m => MuseParser m (F Blocks) literal = liftM (return . rawBlock) $ htmlElement "literal" diff --git a/test/Tests/Readers/Muse.hs b/test/Tests/Readers/Muse.hs index 6f602d7c3..43a1d0697 100644 --- a/test/Tests/Readers/Muse.hs +++ b/test/Tests/Readers/Muse.hs @@ -230,6 +230,31 @@ tests = lineBlock [ "Foo bar" ] <> lineBlock [ "Foo bar" ] <> lineBlock [ "\160\160\160Foo" ] + , testGroup "Example tag" + [ "Tags on separate lines" =: + T.unlines [ "" + , "Example line" + , "" + ] =?> + codeBlock "Example line" + , "One line" =: + "Example line" =?> + codeBlock "Example line" + , "One blank line in the beginning" =: + T.unlines [ "" + , "" + , "Example line" + , "" + ] =?> + codeBlock "\nExample line" + , "One blank line in the end" =: + T.unlines [ "" + , "Example line" + , "" + , "" + ] =?> + codeBlock "Example line\n" + ] , "Center" =: "
Hello, world
" =?> para (text "Hello, world") , "Right" =: "Hello, world" =?> para (text "Hello, world") , testGroup "Comments" -- cgit v1.2.3