git.iko.soy/typeable/pandoc
on master help sign in
HTML reader: allow thead containing a row with td rather than th.

See #5014. Note that this doesn't address the original issue in #5014, only an unrelated side-issue.

commit1cfdd3662f667f8119e441b60ba8d718b75f90ca authorJohn MacFarlane <jgm@berkeley.edu> dateTue 13 Nov 2018, 14:49 (8 years ago) parent8074a76
2 files changed+28−11
src/Text/Pandoc/Readers/HTML.hs+11−11 test/command/5014.md+17
src/Text/Pandoc/Readers/HTML.hs+11−11
@@ -496,13 +496,13 @@ pTable = try $ do
496496 let pTh = option [] $ pInTags "tr" (pCell "th")
497497 pTr = try $ skipMany pBlank >>
498498 pInTags "tr" (pCell "td" <|> pCell "th")
499− pTBody = pOptInTag "tbody" $ many1 pTr
500− head'' <- pOptInTag "thead" pTh
499+ pTBody = pInTag True "tbody" $ many1 pTr
500+ head'' <- pInTag False "thead" (option [] pTr) <|> pInTag True "thead" pTh
501501 head' <- map snd <$>
502− pOptInTag "tbody"
502+ pInTag True "tbody"
503503 (if null head'' then pTh else return head'')
504504 rowsLs <- many pTBody
505− rows' <- pOptInTag "tfoot" $ many pTr
505+ rows' <- pInTag True "tfoot" $ many pTr
506506 TagClose _ <- pSatisfy (matchTagClose "table")
507507 let rows'' = concat rowsLs <> rows'
508508 let rows''' = map (map snd) rows''
@@ -609,7 +609,7 @@ pFigure = try $ do
609609 TagOpen _ _ <- pSatisfy (matchTagOpen "figure" [])
610610 skipMany pBlank
611611 let pImg = (\x -> (Just x, Nothing)) <$>
612− (pOptInTag "p" pImage <* skipMany pBlank)
612+ (pInTag True "p" pImage <* skipMany pBlank)
613613 pCapt = (\x -> (Nothing, Just x)) <$> do
614614 bs <- pInTags "figcaption" block
615615 return $ blocksToInlines' $ B.toList bs
@@ -868,16 +868,16 @@ pInTags' tagtype tagtest parser = try $ do
868868 pSatisfy (\t -> t ~== TagOpen tagtype [] && tagtest t)
869869 mconcat <$> manyTill parser (pCloses tagtype <|> eof)
870870
871−-- parses p, preceded by an optional opening tag
872−-- and followed by an optional closing tags
873−pOptInTag :: PandocMonad m => Text -> TagParser m a -> TagParser m a
874−pOptInTag tagtype p = try $ do
871+-- parses p, preceded by an opening tag (optional if tagsOptional)
872+-- and followed by a closing tag (optional if tagsOptional)
873+pInTag :: PandocMonad m => Bool -> Text -> TagParser m a -> TagParser m a
874+pInTag tagsOptional tagtype p = try $ do
875875 skipMany pBlank
876− optional $ pSatisfy (matchTagOpen tagtype [])
876+ (if tagsOptional then optional else void) $ pSatisfy (matchTagOpen tagtype [])
877877 skipMany pBlank
878878 x <- p
879879 skipMany pBlank
880− optional $ pSatisfy (matchTagClose tagtype)
880+ (if tagsOptional then optional else void) $ pSatisfy (matchTagClose tagtype)
881881 skipMany pBlank
882882 return x
883883
test/command/5014.mdnew file+17
@@ -0,0 +1,17 @@
1+```
2+% pandoc -f html -t native
3+<table>
4+ <thead>
5+ <tr>
6+ <td>Name</td>
7+ </tr>
8+ </thead>
9+ <tbody>
10+ <tr>
11+ <td>Accounts</td>
12+ </tr>
13+ </tbody>
14+</table>
15+^D
16+
17+```