From c31d3cc306d476e340dd156a9b9520a4f935230e Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Fri, 14 Jan 2011 20:47:32 -0800 Subject: HTML reader: parse location tags in pSatisfy. This avoids the need for manual parsing all over the place. --- src/Text/Pandoc/Readers/HTML.hs | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) (limited to 'src/Text') diff --git a/src/Text/Pandoc/Readers/HTML.hs b/src/Text/Pandoc/Readers/HTML.hs index ae8f0438e..b1a03a4bd 100644 --- a/src/Text/Pandoc/Readers/HTML.hs +++ b/src/Text/Pandoc/Readers/HTML.hs @@ -78,9 +78,8 @@ parseBody :: TagParser [Block] parseBody = liftM concat $ manyTill block eof block :: TagParser [Block] -block = optional pLocation >> - choice [ - pPara +block = choice + [ pPara , pHeader , pBlockQuote , pCodeBlock @@ -235,9 +234,8 @@ pCodeBlock = try $ do return [CodeBlock attribs result] inline :: TagParser [Inline] -inline = choice [ - pLocation - , pTagText +inline = choice + [ pTagText , pEmph , pStrong , pSuperscript @@ -250,17 +248,19 @@ inline = choice [ , pRawHtmlInline ] -pLocation :: TagParser [a] +pLocation :: TagParser () pLocation = do - (TagPosition r c) <- pSatisfy isTagPosition + (TagPosition r c) <- pSat isTagPosition setPosition $ newPos "input" r c - return [] -pSatisfy :: (Tag String -> Bool) -> TagParser (Tag String) -pSatisfy f = do +pSat :: (Tag String -> Bool) -> TagParser (Tag String) +pSat f = do pos <- getPosition token show (const pos) (\x -> if f x then Just x else Nothing) +pSatisfy :: (Tag String -> Bool) -> TagParser (Tag String) +pSatisfy f = try $ optional pLocation >> pSat f + pAnyTag :: TagParser (Tag String) pAnyTag = pSatisfy (const True) @@ -268,7 +268,7 @@ pSelfClosing :: (String -> Bool) -> ([Attribute String] -> Bool) -> TagParser (Tag String) pSelfClosing f g = do open <- pSatisfy (tagOpen f g) - optional $ try $ pLocation >> pSatisfy (tagClose f) + optional $ pSatisfy (tagClose f) return open pEmph :: TagParser [Inline] @@ -342,7 +342,6 @@ pInTags tagtype parser = try $ do pCloses :: String -> TagParser () pCloses tagtype = try $ do - optional pLocation t <- lookAhead $ pSatisfy $ \tag -> isTagClose tag || isTagOpen tag case t of (TagClose t') | t' == tagtype -> pAnyTag >> return () @@ -360,6 +359,11 @@ pTagText = try $ do Left _ -> fail $ "Could not parse `" ++ str ++ "'" Right result -> return result +pBlank :: TagParser () +pBlank = try $ do + (TagText str) <- pSatisfy isTagText + guard $ all isSpace str + pTagContents :: GenParser Char ParserState Inline pTagContents = pStr <|> pSpace <|> smartPunctuation pTagContents <|> pSymbol -- cgit v1.2.3