diff options
author | fiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> | 2007-08-20 19:21:18 +0000 |
---|---|---|
committer | fiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> | 2007-08-20 19:21:18 +0000 |
commit | cc0460f952535441b4bb0d77a652bca1bc708ea4 (patch) | |
tree | dd62c135a5543b53d8f6dadfec2c06e963942e42 /src/Text/Pandoc/Readers | |
parent | 84aa875bdba3215cf79f195a3f2ba6db06498257 (diff) | |
download | pandoc-cc0460f952535441b4bb0d77a652bca1bc708ea4.tar.gz |
Code cleanup in Markdown reader.
git-svn-id: https://pandoc.googlecode.com/svn/trunk@877 788f1e2b-df1e-0410-8736-df70ead52e1b
Diffstat (limited to 'src/Text/Pandoc/Readers')
-rw-r--r-- | src/Text/Pandoc/Readers/Markdown.hs | 45 |
1 files changed, 18 insertions, 27 deletions
diff --git a/src/Text/Pandoc/Readers/Markdown.hs b/src/Text/Pandoc/Readers/Markdown.hs index 5f0c0b7a5..2260a6d85 100644 --- a/src/Text/Pandoc/Readers/Markdown.hs +++ b/src/Text/Pandoc/Readers/Markdown.hs @@ -223,25 +223,21 @@ block = choice [ header header = setextHeader <|> atxHeader <?> "header" atxHeader = try $ do - lead <- many1 (char '#') + level <- many1 (char '#') >>= return . length notFollowedBy (char '.' <|> char ')') -- this would be a list skipSpaces - txt <- manyTill inline atxClosing - return $ Header (length lead) (normalizeSpaces txt) + text <- manyTill inline atxClosing >>= return . normalizeSpaces + return $ Header level text -atxClosing = try $ skipMany (char '#') >> skipSpaces >> newline >> - option "" blanklines +atxClosing = try $ skipMany (char '#') >> blanklines -setextHeader = choice $ - map (\x -> setextH x) $ enumFromTo 1 (length setextHChars) +setextHeader = choice $ map setextH $ enumFromTo 1 (length setextHChars) -setextH n = try $ do - txt <- many1Till inline newline - many1 (char (setextHChars !! (n-1))) - skipSpaces - newline - optional blanklines - return $ Header n (normalizeSpaces txt) +setextH level = try $ do + text <- many1Till inline newline >>= return . normalizeSpaces + many1 $ char (setextHChars !! (level - 1)) + blanklines + return $ Header level text -- -- hrule block @@ -260,20 +256,15 @@ hrule = choice (map hruleWith hruleChars) <?> "hrule" -- code blocks -- -indentedLine = try $ do - indentSpaces - result <- manyTill anyChar newline - return $ result ++ "\n" +indentedLine = indentSpaces >> manyTill anyChar newline >>= return . (++ "\n") --- two or more indented lines, possibly separated by blank lines -indentedBlock = try $ do - res1 <- indentedLine - blanks <- many blankline - res2 <- indentedBlock <|> indentedLine - return $ res1 ++ blanks ++ res2 - -codeBlock = (indentedBlock <|> indentedLine) >>~ optional blanklines >>= - return . CodeBlock . stripTrailingNewlines +codeBlock = try $ do + contents <- many1 (indentedLine <|> + try (do b <- blanklines + l <- indentedLine + return $ b ++ l)) + blanklines + return $ CodeBlock $ stripTrailingNewlines $ concat contents -- -- block quotes |