git.iko.soy/typeable/pandoc
on master help sign in
Muse reader: parse {{{ }}} example syntax
508c3a6Alexander Krotov
src/Text/Pandoc/Readers/Muse.hs+8−1
@@ -30,7 +30,6 @@ Conversion of Muse text to 'Pandoc' document.
30-}
30-}
31{-
31{-
32TODO:
32TODO:
33−- {{{ }}} syntax for <example>
34- Page breaks (five "*")
33- Page breaks (five "*")
35- Headings with anchors (make it round trip with Muse writer)
34- Headings with anchors (make it round trip with Muse writer)
36- Org tables
35- Org tables
@@ -177,6 +176,7 @@ blockElements :: PandocMonad m => MuseParser m (F Blocks)
177blockElements = choice [ comment
176blockElements = choice [ comment
178 , separator
177 , separator
179 , header
178 , header
179+ , example
180 , exampleTag
180 , exampleTag
181 , literal
181 , literal
182 , centerTag
182 , centerTag
@@ -221,6 +221,13 @@ header = try $ do
221 attr <- registerHeader ("", [], []) (runF content defaultParserState)
221 attr <- registerHeader ("", [], []) (runF content defaultParserState)
222 return $ B.headerWith attr level <$> content
222 return $ B.headerWith attr level <$> content
223
223
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+
224exampleTag :: PandocMonad m => MuseParser m (F Blocks)
231exampleTag :: PandocMonad m => MuseParser m (F Blocks)
225exampleTag = do
232exampleTag = do
226 (attr, contents) <- htmlElement "example"
233 (attr, contents) <- htmlElement "example"
test/Tests/Readers/Muse.hs+33
@@ -232,6 +232,39 @@ tests =
232 lineBlock [ "Foo bar" ] <>
232 lineBlock [ "Foo bar" ] <>
233 lineBlock [ "Foo bar" ] <>
233 lineBlock [ "Foo bar" ] <>
234 lineBlock [ "\160\160\160Foo" ]
234 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+ ]
235 , testGroup "Example tag"
268 , testGroup "Example tag"
236 [ "Tags on separate lines" =:
269 [ "Tags on separate lines" =:
237 T.unlines [ "<example>"
270 T.unlines [ "<example>"