Markdown(+lhs) reader: handle "inverse bird tracks"

Inverse bird tracks (<) are used for haskell example code that is not
part of the literate Haskell program.

Resolves Issue #211.

git-svn-id: https://pandoc.googlecode.com/svn/trunk@1888 788f1e2b-df1e-0410-8736-df70ead52e1b
This commit is contained in:
fiddlosopher 2010-03-14 23:23:20 +00:00
parent 800b03ba50
commit 075f958c6a

View file

@ -409,8 +409,10 @@ codeBlockIndented = do
lhsCodeBlock :: GenParser Char ParserState Block lhsCodeBlock :: GenParser Char ParserState Block
lhsCodeBlock = do lhsCodeBlock = do
failUnlessLHS failUnlessLHS
contents <- lhsCodeBlockBird <|> lhsCodeBlockLaTeX liftM (CodeBlock ("",["sourceCode","literate","haskell"],[]))
return $ CodeBlock ("",["sourceCode","literate","haskell"],[]) contents (lhsCodeBlockBird <|> lhsCodeBlockLaTeX)
<|> liftM (CodeBlock ("",["sourceCode","haskell"],[]))
lhsCodeBlockInverseBird
lhsCodeBlockLaTeX :: GenParser Char ParserState String lhsCodeBlockLaTeX :: GenParser Char ParserState String
lhsCodeBlockLaTeX = try $ do lhsCodeBlockLaTeX = try $ do
@ -421,10 +423,16 @@ lhsCodeBlockLaTeX = try $ do
return $ stripTrailingNewlines contents return $ stripTrailingNewlines contents
lhsCodeBlockBird :: GenParser Char ParserState String lhsCodeBlockBird :: GenParser Char ParserState String
lhsCodeBlockBird = try $ do lhsCodeBlockBird = lhsCodeBlockBirdWith '>'
lhsCodeBlockInverseBird :: GenParser Char ParserState String
lhsCodeBlockInverseBird = lhsCodeBlockBirdWith '<'
lhsCodeBlockBirdWith :: Char -> GenParser Char ParserState String
lhsCodeBlockBirdWith c = try $ do
pos <- getPosition pos <- getPosition
when (sourceColumn pos /= 1) $ fail "Not in first column" when (sourceColumn pos /= 1) $ fail "Not in first column"
lns <- many1 birdTrackLine lns <- many1 $ birdTrackLine c
-- if (as is normal) there is always a space after >, drop it -- if (as is normal) there is always a space after >, drop it
let lns' = if all (\ln -> null ln || take 1 ln == " ") lns let lns' = if all (\ln -> null ln || take 1 ln == " ") lns
then map (drop 1) lns then map (drop 1) lns
@ -432,9 +440,9 @@ lhsCodeBlockBird = try $ do
blanklines blanklines
return $ intercalate "\n" lns' return $ intercalate "\n" lns'
birdTrackLine :: GenParser Char st [Char] birdTrackLine :: Char -> GenParser Char st [Char]
birdTrackLine = do birdTrackLine c = do
char '>' char c
manyTill anyChar newline manyTill anyChar newline