git.iko.soy/typeable/pandoc
on master help sign in
HTML reader: fix htmlTag and isInlineTag to accept processing instructions.

Fixes regression #3123 (since 2.0). Added regression test.

commitf5c64c3060ba40181a86d6c82a67b5b975f74446 authorJohn MacFarlane <jgm@berkeley.edu> dateThu 11 Oct 2018, 09:58 (8 years ago) parent3e04c2f
2 files changed+23−8
src/Text/Pandoc/Readers/HTML.hs+10−8 test/command/3123.md+13
src/Text/Pandoc/Readers/HTML.hs+10−8
@@ -1069,11 +1069,11 @@ instance NamedTag (Tag String) where
10691069 getTagName _ = Nothing
10701070
10711071isInlineTag :: NamedTag (Tag a) => Tag a -> Bool
1072−isInlineTag t = isInlineTagName || isCommentTag t
1073− where isInlineTagName = case getTagName t of
1074− Just x -> x
1075− `Set.notMember` blockTags
1076− Nothing -> False
1072+isInlineTag t =
1073+ isCommentTag t || case getTagName t of
1074+ Nothing -> False
1075+ Just x -> x `Set.notMember` blockTags ||
1076+ T.take 1 x == "?" -- processing instr.
10771077
10781078isBlockTag :: NamedTag (Tag a) => Tag a -> Bool
10791079isBlockTag t = isBlockTagName || isTagComment t
@@ -1208,8 +1208,10 @@ htmlTag f = try $ do
12081208 let isNameChar c = isAlphaNum c || c == ':' || c == '-' || c == '_'
12091209 let isName s = case s of
12101210 [] -> False
1211− ('?':_) -> True -- processing instruction
12121211 (c:cs) -> isLetter c && all isNameChar cs
1212+ let isPI s = case s of
1213+ ('?':_) -> True -- processing instruction
1214+ _ -> False
12131215
12141216 let endpos = if ln == 1
12151217 then setSourceColumn startpos
@@ -1225,7 +1227,7 @@ htmlTag f = try $ do
12251227 let handleTag tagname = do
12261228 -- basic sanity check, since the parser is very forgiving
12271229 -- and finds tags in stuff like x<y)
1228− guard $ isName tagname
1230+ guard $ isName tagname || isPI tagname
12291231 guard $ not $ null tagname
12301232 -- <https://example.org> should NOT be a tag either.
12311233 -- tagsoup will parse it as TagOpen "https:" [("example.org","")]
@@ -1245,7 +1247,7 @@ htmlTag f = try $ do
12451247 else return (next, "<!--" <> s <> "-->")
12461248 | otherwise -> fail "bogus comment mode, HTML5 parse error"
12471249 TagOpen tagname attr -> do
1248− guard $ all (isName . fst) attr
1250+ guard $ isPI tagname || all (isName . fst) attr
12491251 handleTag tagname
12501252 TagClose tagname ->
12511253 handleTag tagname
test/command/3123.mdnew file+13
@@ -0,0 +1,13 @@
1+```
2+% pandoc -f markdown -t native
3+<?php echo "1" ; ?>
4+^D
5+[RawBlock (Format "html") "<?php echo \"1\" ; ?>"]
6+```
7+
8+```
9+% pandoc -f markdown -t native
10+a<?php echo "1" ; ?>
11+^D
12+[Para [Str "a",RawInline (Format "html") "<?php echo \"1\" ; ?>"]]
13+```