git.iko.soy/typeable/pandoc
on master help sign in
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

commit075f958c6a96449f071dea2a9bbfaaad98905f33 authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> dateSun 14 Mar 2010, 23:23 (17 years ago) parent800b03b
1 file changed+15−7
src/Text/Pandoc/Readers/Markdown.hs+15−7
src/Text/Pandoc/Readers/Markdown.hs+15−7
@@ -409,8 +409,10 @@ codeBlockIndented = do
409409lhsCodeBlock :: GenParser Char ParserState Block
410410lhsCodeBlock = do
411411 failUnlessLHS
412− contents <- lhsCodeBlockBird <|> lhsCodeBlockLaTeX
413− return $ CodeBlock ("",["sourceCode","literate","haskell"],[]) contents
412+ liftM (CodeBlock ("",["sourceCode","literate","haskell"],[]))
413+ (lhsCodeBlockBird <|> lhsCodeBlockLaTeX)
414+ <|> liftM (CodeBlock ("",["sourceCode","haskell"],[]))
415+ lhsCodeBlockInverseBird
414416
415417lhsCodeBlockLaTeX :: GenParser Char ParserState String
416418lhsCodeBlockLaTeX = try $ do
@@ -421,10 +423,16 @@ lhsCodeBlockLaTeX = try $ do
421423 return $ stripTrailingNewlines contents
422424
423425lhsCodeBlockBird :: GenParser Char ParserState String
424−lhsCodeBlockBird = try $ do
426+lhsCodeBlockBird = lhsCodeBlockBirdWith '>'
427+
428+lhsCodeBlockInverseBird :: GenParser Char ParserState String
429+lhsCodeBlockInverseBird = lhsCodeBlockBirdWith '<'
430+
431+lhsCodeBlockBirdWith :: Char -> GenParser Char ParserState String
432+lhsCodeBlockBirdWith c = try $ do
425433 pos <- getPosition
426434 when (sourceColumn pos /= 1) $ fail "Not in first column"
427− lns <- many1 birdTrackLine
435+ lns <- many1 $ birdTrackLine c
428436 -- if (as is normal) there is always a space after >, drop it
429437 let lns' = if all (\ln -> null ln || take 1 ln == " ") lns
430438 then map (drop 1) lns
@@ -432,9 +440,9 @@ lhsCodeBlockBird = try $ do
432440 blanklines
433441 return $ intercalate "\n" lns'
434442
435−birdTrackLine :: GenParser Char st [Char]
436−birdTrackLine = do
437− char '>'
443+birdTrackLine :: Char -> GenParser Char st [Char]
444+birdTrackLine c = do
445+ char c
438446 manyTill anyChar newline
439447
440448