From d1b0ce6b106ca0ae386aede7f26f0c6f4f06ecc4 Mon Sep 17 00:00:00 2001 From: Rockingcool Date: Tue, 6 May 2025 17:06:22 -0500 Subject: [PATCH] Move parseHeader up in the chain - parseDocument can either parse headers or a paragraph --- src/MdToHTML.hs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/MdToHTML.hs b/src/MdToHTML.hs index c1bbe2b..23d8c21 100644 --- a/src/MdToHTML.hs +++ b/src/MdToHTML.hs @@ -166,7 +166,7 @@ parsePara = do -- string "\n\n" <|> (eof >> return "") -- Consume the next double-newline or EOF. text <- (manyTill get ((string "\n\n") <|> (eof >> return ""))) when (null text) pfail - let parsedText = fst $ leftmostLongestParse (parseHeader <|> parseLine) text -- Parse either a line or a header. + let parsedText = fst $ leftmostLongestParse parseLine text -- Parse either a line or a header. -- If the paragraph is a header, return a Header token. Otheriwse return a Para token. case parsedText of Header level token -> return (Header level token) @@ -174,4 +174,6 @@ parsePara = do -- Parse a document, which is multiple paragraphs. parseDocument :: ReadP MdToken -parseDocument = (many1 parsePara) >>= (\res -> return (Document (res))) +parseDocument = do + res <- manyTill (parseHeader <++ parsePara) (eof) + return (Document res)