Skip to content

Commit

Permalink
Fix HTML comment parser to conform to 0.31.2 spec.
Browse files Browse the repository at this point in the history
  • Loading branch information
jgm committed Jan 29, 2024
1 parent 7527b0f commit 647b880
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions commonmark/src/Commonmark/Tag.hs
Original file line number Diff line number Diff line change
Expand Up @@ -138,24 +138,25 @@ htmlClosingTag = try $ do
cl <- symbol '>'
return $ op : n ++ sps ++ [cl]

-- An HTML comment consists of <!-- + text + -->, where text does not
-- start with > or ->, does not end with -, and does not contain --.
-- An HTML comment consists of `<!-->`, `<!--->`, or `<!--`, a string of
-- characters not including the string `-->`, and `-->`.
-- (See the HTML5 spec.)
htmlComment :: Monad m => ParsecT [Tok] s m [Tok]
htmlComment = try $ do
-- assume < has already been parsed
op <- sequence [ symbol '!'
, symbol '-'
, symbol '-' ]
notFollowedBy $ do
optional $ symbol '-'
symbol '>'
contents <- many $ satisfyTok (not . hasType (Symbol '-'))
<|> try (symbol '-' <* notFollowedBy (symbol '-'))
cl <- sequence [ symbol '-'
, symbol '-'
, symbol '>' ]
return $ op ++ contents ++ cl
let getContent =
try (sequence [ symbol '-', symbol '-', symbol '>' ])
<|> try ((++) <$> many1 (satisfyTok (not . hasType (Symbol '-')))
<*> getContent)
<|> try ((:) <$> symbol '-' <*> getContent)
(op ++) <$>
( ((:[]) <$> symbol '>')
<|> try (sequence [ symbol '-', symbol '>' ])
<|> getContent
)

-- A processing instruction consists of the string <?, a string of
-- characters not including the string ?>, and the string ?>.
Expand Down

0 comments on commit 647b880

Please sign in to comment.