git.iko.soy/typeable/pandoc
on master help sign in
Merge pull request #974 from merijn/master

Added support for LaTeX style literate Haskell code blocks in rST.

commit1bc9cb4105d432e27bc1b18397ac1c1a5630a781 authorJohn MacFarlane <jgm@berkeley.edu> dateThu 16 Jan 2014, 12:32 (13 years ago) parenta1abb3e56f56e5
1 file changed+17−6
src/Text/Pandoc/Readers/RST.hs+17−6
src/Text/Pandoc/Readers/RST.hs+17−6
@@ -347,14 +347,25 @@ lhsCodeBlock = try $ do
347347 getPosition >>= guard . (==1) . sourceColumn
348348 guardEnabled Ext_literate_haskell
349349 optional codeBlockStart
350− lns <- many1 birdTrackLine
351− -- if (as is normal) there is always a space after >, drop it
352− let lns' = if all (\ln -> null ln || take 1 ln == " ") lns
353− then map (drop 1) lns
354− else lns
350+ lns <- latexCodeBlock <|> birdCodeBlock
355351 blanklines
356352 return $ B.codeBlockWith ("", ["sourceCode", "literate", "haskell"], [])
357− $ intercalate "\n" lns'
353+ $ intercalate "\n" lns
354+
355+latexCodeBlock :: Parser [Char] st [[Char]]
356+latexCodeBlock = try $ do
357+ try (latexBlockLine "\\begin{code}")
358+ many1Till anyLine (try $ latexBlockLine "\\end{code}")
359+ where
360+ latexBlockLine s = skipMany spaceChar >> string s >> blankline
361+
362+birdCodeBlock :: Parser [Char] st [[Char]]
363+birdCodeBlock = filterSpace <$> many1 birdTrackLine
364+ where filterSpace lns =
365+ -- if (as is normal) there is always a space after >, drop it
366+ if all (\ln -> null ln || take 1 ln == " ") lns
367+ then map (drop 1) lns
368+ else lns
358369
359370birdTrackLine :: Parser [Char] st [Char]
360371birdTrackLine = char '>' >> anyLine