Muse reader: trim newlines from <example>s
This commit is contained in:
parent
cbdeed9cfd
commit
afedb41b17
2 changed files with 35 additions and 1 deletions
|
@ -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"
|
||||
|
|
|
@ -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>"
|
||||
, "Example line"
|
||||
, "</example>"
|
||||
] =?>
|
||||
codeBlock "Example line"
|
||||
, "One line" =:
|
||||
"<example>Example line</example>" =?>
|
||||
codeBlock "Example line"
|
||||
, "One blank line in the beginning" =:
|
||||
T.unlines [ "<example>"
|
||||
, ""
|
||||
, "Example line"
|
||||
, "</example>"
|
||||
] =?>
|
||||
codeBlock "\nExample line"
|
||||
, "One blank line in the end" =:
|
||||
T.unlines [ "<example>"
|
||||
, "Example line"
|
||||
, ""
|
||||
, "</example>"
|
||||
] =?>
|
||||
codeBlock "Example line\n"
|
||||
]
|
||||
, "Center" =: "<center>Hello, world</center>" =?> para (text "Hello, world")
|
||||
, "Right" =: "<right>Hello, world</right>" =?> para (text "Hello, world")
|
||||
, testGroup "Comments"
|
||||
|
|
Loading…
Add table
Reference in a new issue