HTML writer: Allow "spanlike" classes to be combined.
Previously classes like "underline" and "marked" had to be the first class in a span in order for the span to be interpreted as a "ul" or "mark" element. This commit allows these special classes to be "stacked," e.g. `[test]{.mark .underline}`; in addition, the special classes are no longer required to come first in the list of classes. See #8194 for context.
This commit is contained in:
parent
b7bc980089
commit
ac7fa3da4d
2 changed files with 27 additions and 8 deletions
|
@ -1389,15 +1389,28 @@ inlineToHtml opts inline = do
|
|||
-> inlineListToHtml opts ils >>= inDiv cls
|
||||
|
||||
(Span (id',classes,kvs) ils) ->
|
||||
let spanLikeTag = case classes of
|
||||
(c:_) -> do
|
||||
guard (c `Set.member` htmlSpanLikeElements)
|
||||
pure $ customParent (textTag c)
|
||||
_ -> Nothing
|
||||
in case spanLikeTag of
|
||||
Just tag -> do
|
||||
let go Nothing c
|
||||
| c `Set.member` htmlSpanLikeElements
|
||||
= Just (customParent (textTag c), [])
|
||||
| c == "smallcaps"
|
||||
= Just (H.span ! A.class_ "smallcaps", [])
|
||||
| c == "underline"
|
||||
= Just (H.u, [])
|
||||
| otherwise = Nothing
|
||||
go (Just (t,cs)) c
|
||||
| c `Set.member` htmlSpanLikeElements
|
||||
= Just (t . customParent (textTag c), cs)
|
||||
| c == "smallcaps"
|
||||
= Just (t . (H.span ! A.class_ "smallcaps"), cs)
|
||||
| c == "underline"
|
||||
= Just (t . H.u, cs)
|
||||
| otherwise
|
||||
= Just (t, c:cs)
|
||||
spanLikeTags = foldl' go Nothing
|
||||
in case spanLikeTags classes of
|
||||
Just (tag, cs) -> do
|
||||
h <- inlineListToHtml opts ils
|
||||
addAttrs opts (id',tail classes',kvs') $ tag h
|
||||
addAttrs opts (id',cs,kvs') $ tag h
|
||||
Nothing -> do
|
||||
h <- inlineListToHtml opts ils
|
||||
addAttrs opts (id',classes',kvs') (H.span h)
|
||||
|
|
6
test/command/nested-spanlike.md
Normal file
6
test/command/nested-spanlike.md
Normal file
|
@ -0,0 +1,6 @@
|
|||
```
|
||||
% pandoc -f markdown -t html
|
||||
[test]{.foo .underline #bar .smallcaps .kbd}
|
||||
^D
|
||||
<p><u id="bar"><span class="smallcaps"><kbd>test</kbd></span></u></p>
|
||||
```
|
Loading…
Add table
Reference in a new issue