git.iko.soy/typeable/pandoc
on master help sign in
Merge pull request #3908 from labdsf/muse-reader-example

Muse reader: trim newlines from <example>s

commit41a16a1e9dbfd62d430fb7c5a75b8c3e207d383f authorJohn MacFarlane <jgm@berkeley.edu> dateSun 10 Sep 2017, 06:41 (9 years ago) parentcbdeed9afedb41
2 files changed+35−1
src/Text/Pandoc/Readers/Muse.hs+10−1 test/Tests/Readers/Muse.hs+25
src/Text/Pandoc/Readers/Muse.hs+10−1
@@ -223,7 +223,16 @@ header = try $ do
223223 return $ B.headerWith attr level <$> content
224224
225225exampleTag :: PandocMonad m => MuseParser m (F Blocks)
226−exampleTag = liftM (return . uncurry B.codeBlockWith) $ htmlElement "example"
226+exampleTag = do
227+ (attr, contents) <- htmlElement "example"
228+ return $ return $ B.codeBlockWith attr $ chop contents
229+ where lchop s = case s of
230+ '\n':ss -> ss
231+ _ -> s
232+ rchop = reverse . lchop . reverse
233+ -- Trim up to one newline from the beginning and the end,
234+ -- in case opening and/or closing tags are on separate lines.
235+ chop = lchop . rchop
227236
228237literal :: PandocMonad m => MuseParser m (F Blocks)
229238literal = liftM (return . rawBlock) $ htmlElement "literal"
test/Tests/Readers/Muse.hs+25
@@ -230,6 +230,31 @@ tests =
230230 lineBlock [ "Foo bar" ] <>
231231 lineBlock [ "Foo bar" ] <>
232232 lineBlock [ "\160\160\160Foo" ]
233+ , testGroup "Example tag"
234+ [ "Tags on separate lines" =:
235+ T.unlines [ "<example>"
236+ , "Example line"
237+ , "</example>"
238+ ] =?>
239+ codeBlock "Example line"
240+ , "One line" =:
241+ "<example>Example line</example>" =?>
242+ codeBlock "Example line"
243+ , "One blank line in the beginning" =:
244+ T.unlines [ "<example>"
245+ , ""
246+ , "Example line"
247+ , "</example>"
248+ ] =?>
249+ codeBlock "\nExample line"
250+ , "One blank line in the end" =:
251+ T.unlines [ "<example>"
252+ , "Example line"
253+ , ""
254+ , "</example>"
255+ ] =?>
256+ codeBlock "Example line\n"
257+ ]
233258 , "Center" =: "<center>Hello, world</center>" =?> para (text "Hello, world")
234259 , "Right" =: "<right>Hello, world</right>" =?> para (text "Hello, world")
235260 , testGroup "Comments"