git.iko.soy/typeable/pandoc
on master help sign in
Added lhs support to RST reader.
ebe9ac5fiddlosopher
Text/Pandoc/Readers/RST.hs+20
@@ -33,6 +33,7 @@ module Text.Pandoc.Readers.RST (
33import Text.Pandoc.Definition
33import Text.Pandoc.Definition
34import Text.Pandoc.Shared
34import Text.Pandoc.Shared
35import Text.ParserCombinators.Parsec
35import Text.ParserCombinators.Parsec
36+import Control.Monad ( when )
36import Data.List ( findIndex, delete, intercalate )
37import Data.List ( findIndex, delete, intercalate )
37
38
38-- | Parse reStructuredText string and return Pandoc document.
39-- | Parse reStructuredText string and return Pandoc document.
@@ -126,6 +127,7 @@ block = choice [ codeBlock
126 , hrule
127 , hrule
127 , list
128 , list
128 , lineBlock
129 , lineBlock
130+ , lhsCodeBlock
129 , para
131 , para
130 , plain
132 , plain
131 , nullBlock ] <?> "block"
133 , nullBlock ] <?> "block"
@@ -328,6 +330,24 @@ codeBlock = try $ do
328 result <- indentedBlock
330 result <- indentedBlock
329 return $ CodeBlock ("",[],[]) $ stripTrailingNewlines result
331 return $ CodeBlock ("",[],[]) $ stripTrailingNewlines result
330
332
333+lhsCodeBlock :: GenParser Char ParserState Block
334+lhsCodeBlock = try $ do
335+ failUnlessLHS
336+ pos <- getPosition
337+ when (sourceColumn pos /= 1) $ fail "Not in first column"
338+ lns <- many1 birdTrackLine
339+ -- if (as is normal) there is always a space after >, drop it
340+ let lns' = if all (\ln -> null ln || take 1 ln == " ") lns
341+ then map (drop 1) lns
342+ else lns
343+ blanklines
344+ return $ CodeBlock ("", ["sourceCode", "haskell"], []) $ intercalate "\n" lns'
345+
346+birdTrackLine :: GenParser Char st [Char]
347+birdTrackLine = do
348+ char '>'
349+ manyTill anyChar newline
350+
331--
351--
332-- raw html
352-- raw html
333--
353--