From cc0460f952535441b4bb0d77a652bca1bc708ea4 Mon Sep 17 00:00:00 2001 From: fiddlosopher Date: Mon, 20 Aug 2007 19:21:18 +0000 Subject: Code cleanup in Markdown reader. git-svn-id: https://pandoc.googlecode.com/svn/trunk@877 788f1e2b-df1e-0410-8736-df70ead52e1b --- src/Text/Pandoc/Readers/Markdown.hs | 45 +++++++++++++++---------------------- 1 file changed, 18 insertions(+), 27 deletions(-) (limited to 'src/Text') 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 -- cgit v1.2.3