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

Muse reader: parse {{{ }}} example syntax

commitddecd727838c017f376cdd8d51e14db1b9652217 authorJohn MacFarlane <jgm@berkeley.edu> dateMon 11 Sep 2017, 14:01 (9 years ago) parent1307b02508c3a6
2 files changed+41−1
src/Text/Pandoc/Readers/Muse.hs+8−1 test/Tests/Readers/Muse.hs+33
src/Text/Pandoc/Readers/Muse.hs+8−1
@@ -30,7 +30,6 @@ Conversion of Muse text to 'Pandoc' document.
3030-}
3131{-
3232TODO:
33−- {{{ }}} syntax for <example>
3433- Page breaks (five "*")
3534- Headings with anchors (make it round trip with Muse writer)
3635- Org tables
@@ -178,6 +177,7 @@ blockElements :: PandocMonad m => MuseParser m (F Blocks)
178177blockElements = choice [ comment
179178 , separator
180179 , header
180+ , example
181181 , exampleTag
182182 , literal
183183 , centerTag
@@ -222,6 +222,13 @@ header = try $ do
222222 attr <- registerHeader ("", [], []) (runF content defaultParserState)
223223 return $ B.headerWith attr level <$> content
224224
225+example :: PandocMonad m => MuseParser m (F Blocks)
226+example = try $ do
227+ string "{{{"
228+ optionMaybe blankline
229+ contents <- manyTill anyChar $ try (optionMaybe blankline >> string "}}}")
230+ return $ return $ B.codeBlock contents
231+
225232exampleTag :: PandocMonad m => MuseParser m (F Blocks)
226233exampleTag = do
227234 (attr, contents) <- htmlElement "example"
test/Tests/Readers/Muse.hs+33
@@ -248,6 +248,39 @@ tests =
248248 lineBlock [ "Foo bar" ] <>
249249 lineBlock [ "Foo bar" ] <>
250250 lineBlock [ "\160\160\160Foo" ]
251+ , testGroup "Example"
252+ [ "Braces on separate lines" =:
253+ T.unlines [ "{{{"
254+ , "Example line"
255+ , "}}}"
256+ ] =?>
257+ codeBlock "Example line"
258+ , "Spaces after opening braces" =:
259+ T.unlines [ "{{{ "
260+ , "Example line"
261+ , "}}}"
262+ ] =?>
263+ codeBlock "Example line"
264+ , "One blank line in the beginning" =:
265+ T.unlines [ "{{{"
266+ , ""
267+ , "Example line"
268+ , "}}}"
269+ ] =?>
270+ codeBlock "\nExample line"
271+ , "One blank line in the end" =:
272+ T.unlines [ "{{{"
273+ , "Example line"
274+ , ""
275+ , "}}}"
276+ ] =?>
277+ codeBlock "Example line\n"
278+ -- Amusewiki requires braces to be on separate line,
279+ -- this is an extension.
280+ , "One line" =:
281+ "{{{Example line}}}" =?>
282+ codeBlock "Example line"
283+ ]
251284 , testGroup "Example tag"
252285 [ "Tags on separate lines" =:
253286 T.unlines [ "<example>"