From 66efec1670c9beb3ba1189de558dce402f16cf04 Mon Sep 17 00:00:00 2001 From: fiddlosopher Date: Thu, 22 Nov 2007 19:09:38 +0000 Subject: Improved and simplified setextHeader parser in markdown reader. git-svn-id: https://pandoc.googlecode.com/svn/trunk@1092 788f1e2b-df1e-0410-8736-df70ead52e1b --- src/Text/Pandoc/Readers/Markdown.hs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/Text/Pandoc/Readers/Markdown.hs b/src/Text/Pandoc/Readers/Markdown.hs index 05a46c511..7168cee4d 100644 --- a/src/Text/Pandoc/Readers/Markdown.hs +++ b/src/Text/Pandoc/Readers/Markdown.hs @@ -31,9 +31,10 @@ module Text.Pandoc.Readers.Markdown ( readMarkdown ) where -import Data.List ( transpose, isPrefixOf, isSuffixOf, lookup, sortBy ) +import Data.List ( transpose, isPrefixOf, isSuffixOf, lookup, sortBy, findIndex ) import Data.Ord ( comparing ) import Data.Char ( isAlphaNum ) +import Data.Maybe ( fromMaybe ) import Network.URI ( isURI ) import Text.Pandoc.Definition import Text.Pandoc.Shared @@ -276,13 +277,12 @@ atxHeader = try $ do atxClosing = try $ skipMany (char '#') >> blanklines setextHeader = try $ do - -- first, see if this block has any chance of being a setextHeader: - lookAhead (anyLine >> oneOf setextHChars) - text <- many1Till inline newline >>= return . normalizeSpaces - level <- choice $ zipWith - (\ch lev -> try (many1 $ char ch) >> blanklines >> return lev) - setextHChars [1..(length setextHChars)] - return $ Header level text + text <- many1Till inline newline + underlineChar <- oneOf setextHChars + many (char underlineChar) + blanklines + let level = (fromMaybe 0 $ findIndex (== underlineChar) setextHChars) + 1 + return $ Header level (normalizeSpaces text) -- -- hrule block -- cgit v1.2.3