git.iko.soy/typeable/pandoc
on master help sign in
Muse reader: parse {{{ }}} example syntax
commit508c3a64d823989dc6613ac7656851989530af65 authorAlexander Krotov <ilabdsf@gmail.com> dateSun 10 Sep 2017, 22:35 (9 years ago) parent7df095f
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
@@ -177,6 +176,7 @@ blockElements :: PandocMonad m => MuseParser m (F Blocks)
177176blockElements = choice [ comment
178177 , separator
179178 , header
179+ , example
180180 , exampleTag
181181 , literal
182182 , centerTag
@@ -221,6 +221,13 @@ header = try $ do
221221 attr <- registerHeader ("", [], []) (runF content defaultParserState)
222222 return $ B.headerWith attr level <$> content
223223
224+example :: PandocMonad m => MuseParser m (F Blocks)
225+example = try $ do
226+ string "{{{"
227+ optionMaybe blankline
228+ contents <- manyTill anyChar $ try (optionMaybe blankline >> string "}}}")
229+ return $ return $ B.codeBlock contents
230+
224231exampleTag :: PandocMonad m => MuseParser m (F Blocks)
225232exampleTag = do
226233 (attr, contents) <- htmlElement "example"
test/Tests/Readers/Muse.hs+33
@@ -232,6 +232,39 @@ tests =
232232 lineBlock [ "Foo bar" ] <>
233233 lineBlock [ "Foo bar" ] <>
234234 lineBlock [ "\160\160\160Foo" ]
235+ , testGroup "Example"
236+ [ "Braces on separate lines" =:
237+ T.unlines [ "{{{"
238+ , "Example line"
239+ , "}}}"
240+ ] =?>
241+ codeBlock "Example line"
242+ , "Spaces after opening braces" =:
243+ T.unlines [ "{{{ "
244+ , "Example line"
245+ , "}}}"
246+ ] =?>
247+ codeBlock "Example line"
248+ , "One blank line in the beginning" =:
249+ T.unlines [ "{{{"
250+ , ""
251+ , "Example line"
252+ , "}}}"
253+ ] =?>
254+ codeBlock "\nExample line"
255+ , "One blank line in the end" =:
256+ T.unlines [ "{{{"
257+ , "Example line"
258+ , ""
259+ , "}}}"
260+ ] =?>
261+ codeBlock "Example line\n"
262+ -- Amusewiki requires braces to be on separate line,
263+ -- this is an extension.
264+ , "One line" =:
265+ "{{{Example line}}}" =?>
266+ codeBlock "Example line"
267+ ]
235268 , testGroup "Example tag"
236269 [ "Tags on separate lines" =:
237270 T.unlines [ "<example>"