git.iko.soy/typeable/pandoc
on master help sign in
HTML reader: Updated `closes` with rules from HTML5 spec.
commit971e4c43647cf28d1de0dbc109a6ec6f269fa563 authorJohn MacFarlane <fiddlosopher@gmail.com> dateSat 5 Apr 2014, 23:05 (13 years ago) parent24f438a
1 file changed+12−5
src/Text/Pandoc/Readers/HTML.hs+12−5
src/Text/Pandoc/Readers/HTML.hs+12−5
@@ -469,7 +469,7 @@ pCloses :: String -> TagParser ()
469469pCloses tagtype = try $ do
470470 t <- lookAhead $ pSatisfy $ \tag -> isTagClose tag || isTagOpen tag
471471 case t of
472− (TagClose t') | t' == tagtype -> pAnyTag >> return ()
472+ (TagClose t') | t' == tagtype -> pAnyTag >> return ()
473473 (TagOpen t' _) | t' `closes` tagtype -> return ()
474474 (TagClose "ul") | tagtype == "li" -> return ()
475475 (TagClose "ol") | tagtype == "li" -> return ()
@@ -627,7 +627,7 @@ isCommentTag :: Tag String -> Bool
627627isCommentTag = tagComment (const True)
628628
629629-- taken from HXT and extended
630−
630+-- See http://www.w3.org/TR/html5/syntax.html sec 8.1.2.4 optional tags
631631closes :: String -> String -> Bool
632632_ `closes` "body" = False
633633_ `closes` "html" = False
@@ -635,11 +635,18 @@ _ `closes` "html" = False
635635"li" `closes` "li" = True
636636"th" `closes` t | t `elem` ["th","td"] = True
637637"tr" `closes` t | t `elem` ["th","td","tr"] = True
638+"dd" `closes` t | t `elem` ["dt", "dd"] = True
638639"dt" `closes` t | t `elem` ["dt","dd"] = True
639−"hr" `closes` "p" = True
640−"p" `closes` "p" = True
640+"rt" `closes` t | t `elem` ["rb", "rt", "rtc"] = True
641+"optgroup" `closes` "optgroup" = True
642+"optgroup" `closes` "option" = True
643+"option" `closes` "option" = True
644+-- http://www.w3.org/TR/html-markup/p.html
645+x `closes` "p" | x `elem` ["address", "article", "aside", "blockquote",
646+ "dir", "div", "dl", "fieldset", "footer", "form", "h1", "h2", "h3", "h4",
647+ "h5", "h6", "header", "hr", "menu", "nav", "ol", "p", "pre", "section",
648+ "table", "ul"] = True
641649"meta" `closes` "meta" = True
642−"colgroup" `closes` "colgroup" = True
643650"form" `closes` "form" = True
644651"label" `closes` "label" = True
645652"map" `closes` "map" = True