diff options
author | fiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> | 2010-03-14 23:23:20 +0000 |
---|---|---|
committer | fiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> | 2010-03-14 23:23:20 +0000 |
commit | 075f958c6a96449f071dea2a9bbfaaad98905f33 (patch) | |
tree | d9fedc2b2fca97402ac7ed0cbfdefdbce4c23b0d /src/Text/Pandoc/Readers/Markdown.hs | |
parent | 800b03ba505c1c40dbe1432e3686f41d8f4a31f1 (diff) | |
download | pandoc-075f958c6a96449f071dea2a9bbfaaad98905f33.tar.gz |
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
Diffstat (limited to 'src/Text/Pandoc/Readers/Markdown.hs')
-rw-r--r-- | src/Text/Pandoc/Readers/Markdown.hs | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/src/Text/Pandoc/Readers/Markdown.hs b/src/Text/Pandoc/Readers/Markdown.hs index fccde1140..82c761685 100644 --- a/src/Text/Pandoc/Readers/Markdown.hs +++ b/src/Text/Pandoc/Readers/Markdown.hs @@ -409,8 +409,10 @@ codeBlockIndented = do lhsCodeBlock :: GenParser Char ParserState Block lhsCodeBlock = do failUnlessLHS - contents <- lhsCodeBlockBird <|> lhsCodeBlockLaTeX - return $ CodeBlock ("",["sourceCode","literate","haskell"],[]) contents + liftM (CodeBlock ("",["sourceCode","literate","haskell"],[])) + (lhsCodeBlockBird <|> lhsCodeBlockLaTeX) + <|> liftM (CodeBlock ("",["sourceCode","haskell"],[])) + lhsCodeBlockInverseBird lhsCodeBlockLaTeX :: GenParser Char ParserState String lhsCodeBlockLaTeX = try $ do @@ -421,10 +423,16 @@ lhsCodeBlockLaTeX = try $ do return $ stripTrailingNewlines contents 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 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 let lns' = if all (\ln -> null ln || take 1 ln == " ") lns then map (drop 1) lns @@ -432,9 +440,9 @@ lhsCodeBlockBird = try $ do blanklines return $ intercalate "\n" lns' -birdTrackLine :: GenParser Char st [Char] -birdTrackLine = do - char '>' +birdTrackLine :: Char -> GenParser Char st [Char] +birdTrackLine c = do + char c manyTill anyChar newline |