HTML reader: fix behavior with -native_spans-raw_html.

Previously with this configuration, `<span>`s were not treated
as inline elements at all.

Closes #8711.
This commit is contained in:
John MacFarlane
2023-03-20 19:42:43 -07:00
parent a14c44cc37
commit b5d54f7f38
2 changed files with 138 additions and 12 deletions
+20 -12
View File
@@ -813,18 +813,26 @@ pBdo = try $ do
Nothing -> contents
pSpan :: PandocMonad m => TagParser m Inlines
pSpan = try $ do
guardEnabled Ext_native_spans
TagOpen _ attr' <- lookAhead $ pSatisfy $ tagOpen (=="span") (const True)
let attr = toAttr attr'
contents <- pInTags "span" inline
let isSmallCaps = fontVariant == "small-caps" || "smallcaps" `elem` classes
where styleAttr = fromMaybe "" $ lookup "style" attr'
fontVariant = fromMaybe "" $ pickStyleAttrProps ["font-variant"] styleAttr
classes = maybe []
T.words $ lookup "class" attr'
let tag = if isSmallCaps then B.smallcaps else B.spanWith attr
return $ tag contents
pSpan = do
(TagOpen _ attr') <- lookAhead (pSatisfy $ tagOpen (=="span") (const True))
exts <- getOption readerExtensions
if extensionEnabled Ext_native_spans exts
then do
contents <- pInTags "span" inline
let attr = toAttr attr'
let classes = maybe [] T.words $ lookup "class" attr'
let styleAttr = fromMaybe "" $ lookup "style" attr'
let fontVariant = fromMaybe "" $
pickStyleAttrProps ["font-variant"] styleAttr
let isSmallCaps = fontVariant == "small-caps" ||
"smallcaps" `elem` classes
let tag = if isSmallCaps then B.smallcaps else B.spanWith attr
return $ tag contents
else if extensionEnabled Ext_raw_html exts
then do
tag <- pSatisfy $ tagOpen (=="span") (const True)
return $ B.rawInline "html" $ renderTags' [tag]
else pInTags "span" inline -- just contents
pRawHtmlInline :: PandocMonad m => TagParser m Inlines
pRawHtmlInline = do
+118
View File
@@ -0,0 +1,118 @@
```
% pandoc -f html-native_spans -t native
<table>
<tr>
<td>
<p><span class="foo">a</span> <span class="bar">b</span></p>
</td>
</tr>
</table>
^D
[ Table
( "" , [] , [] )
(Caption Nothing [])
[ ( AlignDefault , ColWidthDefault ) ]
(TableHead ( "" , [] , [] ) [])
[ TableBody
( "" , [] , [] )
(RowHeadColumns 0)
[]
[ Row
( "" , [] , [] )
[ Cell
( "" , [] , [] )
AlignDefault
(RowSpan 1)
(ColSpan 1)
[ Para [ Str "a" , Space , Str "b" ] ]
]
]
]
(TableFoot ( "" , [] , [] ) [])
]
```
```
% pandoc -f html-native_spans+raw_html -t native
<table>
<tr>
<td>
<p><span class="foo">a</span> <span class="bar">b</span></p>
</td>
</tr>
</table>
^D
[ Table
( "" , [] , [] )
(Caption Nothing [])
[ ( AlignDefault , ColWidthDefault ) ]
(TableHead ( "" , [] , [] ) [])
[ TableBody
( "" , [] , [] )
(RowHeadColumns 0)
[]
[ Row
( "" , [] , [] )
[ Cell
( "" , [] , [] )
AlignDefault
(RowSpan 1)
(ColSpan 1)
[ Para
[ RawInline (Format "html") "<span class=\"foo\">"
, Str "a"
, RawInline (Format "html") "</span>"
, Space
, RawInline (Format "html") "<span class=\"bar\">"
, Str "b"
, RawInline (Format "html") "</span>"
]
]
]
]
]
(TableFoot ( "" , [] , [] ) [])
]
```
```
% pandoc -f html -t native
<table>
<tr>
<td>
<p><span class="foo">a</span> <span class="bar">b</span></p>
</td>
</tr>
</table>
^D
[ Table
( "" , [] , [] )
(Caption Nothing [])
[ ( AlignDefault , ColWidthDefault ) ]
(TableHead ( "" , [] , [] ) [])
[ TableBody
( "" , [] , [] )
(RowHeadColumns 0)
[]
[ Row
( "" , [] , [] )
[ Cell
( "" , [] , [] )
AlignDefault
(RowSpan 1)
(ColSpan 1)
[ Para
[ Span ( "" , [ "foo" ] , [] ) [ Str "a" ]
, Space
, Span ( "" , [ "bar" ] , [] ) [ Str "b" ]
]
]
]
]
]
(TableFoot ( "" , [] , [] ) [])
]
```