git.iko.soy/typeable/pandoc
on master help sign in
HTML reader: Simplified parsing of <script> sections.

I had previously assumed that we needed to ignore </script> occuring in a string literal or javascript comment. It turns out, though, that browsers aren't that smart.

commitc08ca6fa6d58c6a52c93b126d1a704b8202f9a36 authorJohn MacFarlane <jgm@berkeley.edu> dateWed 22 Dec 2010, 19:20 (16 years ago) parent4bfe140
1 file changed+1−24
src/Text/Pandoc/Readers/HTML.hs+1−24
src/Text/Pandoc/Readers/HTML.hs+1−24
@@ -288,32 +288,9 @@ htmlScript :: GenParser Char ParserState [Char]
288288htmlScript = try $ do
289289 lookAhead $ htmlOpenTag "script"
290290 open <- anyHtmlTag
291− rest <- liftM concat $ manyTill scriptChunk (htmlEndTag "script")
291+ rest <- manyTill anyChar (htmlEndTag "script")
292292 return $ open ++ rest ++ "</script>"
293293
294−scriptChunk :: GenParser Char ParserState [Char]
295−scriptChunk = jsComment <|> jsString <|> jsChars
296− where jsComment = jsEndlineComment <|> jsMultilineComment
297− jsString = jsSingleQuoteString <|> jsDoubleQuoteString
298− jsChars = many1 (noneOf "<\"'*/") <|> count 1 anyChar
299− jsEndlineComment = try $ do
300− string "//"
301− res <- manyTill anyChar newline
302− return ("//" ++ res)
303− jsMultilineComment = try $ do
304− string "/*"
305− res <- manyTill anyChar (try $ string "*/")
306− return ("/*" ++ res ++ "*/")
307− jsSingleQuoteString = stringwith '\''
308− jsDoubleQuoteString = stringwith '"'
309− charWithEsc escapable = try $
310− (try $ char '\\' >> oneOf ('\\':escapable) >>= \x -> return ['\\',x])
311− <|> count 1 anyChar
312− stringwith c = try $ do
313− char c
314− res <- liftM concat $ manyTill (charWithEsc [c]) (char c)
315− return (c : (res ++ [c]))
316−
317294-- | Parses material between style tags.
318295-- Style tags must be treated differently, because they can contain CSS
319296htmlStyle :: GenParser Char ParserState [Char]