@@ -33,6 +33,7 @@ module Text.Pandoc.Readers.RST (
3333import Text.Pandoc.Definition
3434import Text.Pandoc.Shared
3535import Text.ParserCombinators.Parsec
36+import Control.Monad ( when )
3637import Data.List ( findIndex, delete, intercalate )
3738
3839-- | Parse reStructuredText string and return Pandoc document.
@@ -126,6 +127,7 @@ block = choice [ codeBlock
126127 , hrule
127128 , list
128129 , lineBlock
130+ , lhsCodeBlock
129131 , para
130132 , plain
131133 , nullBlock ] <?> "block"
@@ -328,6 +330,24 @@ codeBlock = try $ do
328330 result <- indentedBlock
329331 return $ CodeBlock ("",[],[]) $ stripTrailingNewlines result
330332
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+
331351--
332352-- raw html
333353--