diff options
author | Merijn Verstraaten <merijn@inconsistent.nl> | 2013-09-07 18:58:16 +0100 |
---|---|---|
committer | Merijn Verstraaten <merijn@inconsistent.nl> | 2013-09-07 18:58:16 +0100 |
commit | 56f56e5e1594ef5d18326d1eb6de3176db307c6a (patch) | |
tree | 3122bbe619f1cc815724f8e4a49a91cf5f07d219 /src/Text/Pandoc | |
parent | 91550dd6dbca6655b5f08d7f17fbe99fe58801a2 (diff) | |
download | pandoc-56f56e5e1594ef5d18326d1eb6de3176db307c6a.tar.gz |
Added support for LaTeX style literate Haskell code blocks in rST.
Diffstat (limited to 'src/Text/Pandoc')
-rw-r--r-- | src/Text/Pandoc/Readers/RST.hs | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/src/Text/Pandoc/Readers/RST.hs b/src/Text/Pandoc/Readers/RST.hs index 32893128a..c12a1493a 100644 --- a/src/Text/Pandoc/Readers/RST.hs +++ b/src/Text/Pandoc/Readers/RST.hs @@ -347,14 +347,25 @@ lhsCodeBlock = try $ do getPosition >>= guard . (==1) . sourceColumn guardEnabled Ext_literate_haskell optional codeBlockStart - lns <- many1 birdTrackLine - -- if (as is normal) there is always a space after >, drop it - let lns' = if all (\ln -> null ln || take 1 ln == " ") lns - then map (drop 1) lns - else lns + lns <- latexCodeBlock <|> birdCodeBlock blanklines return $ B.codeBlockWith ("", ["sourceCode", "literate", "haskell"], []) - $ intercalate "\n" lns' + $ intercalate "\n" lns + +latexCodeBlock :: Parser [Char] st [[Char]] +latexCodeBlock = try $ do + try (latexBlockLine "\\begin{code}") + many1Till anyLine (try $ latexBlockLine "\\end{code}") + where + latexBlockLine s = skipMany spaceChar >> string s >> blankline + +birdCodeBlock :: Parser [Char] st [[Char]] +birdCodeBlock = filterSpace <$> many1 birdTrackLine + where filterSpace lns = + -- if (as is normal) there is always a space after >, drop it + if all (\ln -> null ln || take 1 ln == " ") lns + then map (drop 1) lns + else lns birdTrackLine :: Parser [Char] st [Char] birdTrackLine = char '>' >> anyLine |