aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2014-01-16 12:32:44 -0800
committerJohn MacFarlane <jgm@berkeley.edu>2014-01-16 12:32:44 -0800
commit1bc9cb4105d432e27bc1b18397ac1c1a5630a781 (patch)
tree7d1016269aeed7e792152f4af722bb1952730c63
parenta1abb3eeea2321654a8450725ff6c0d1a18ee0c7 (diff)
parent56f56e5e1594ef5d18326d1eb6de3176db307c6a (diff)
downloadpandoc-1bc9cb4105d432e27bc1b18397ac1c1a5630a781.tar.gz
Merge pull request #974 from merijn/master
Added support for LaTeX style literate Haskell code blocks in rST.
-rw-r--r--src/Text/Pandoc/Readers/RST.hs23
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