summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b>2007-11-22 19:09:38 +0000
committerfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b>2007-11-22 19:09:38 +0000
commit66efec1670c9beb3ba1189de558dce402f16cf04 (patch)
tree1325846bc49c134fa264f00b2bbbfe23e85fdfc4
parent7e540720aa72569fd77f1870c3208b2c013ccb8a (diff)
Improved and simplified setextHeader parser in markdown reader.
git-svn-id: https://pandoc.googlecode.com/svn/trunk@1092 788f1e2b-df1e-0410-8736-df70ead52e1b
-rw-r--r--src/Text/Pandoc/Readers/Markdown.hs16
1 files changed, 8 insertions, 8 deletions
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