HTML reader: Revise treatment of li with id attribute.

Previously we always added an empty div before the list
item, but this created problems with spacing in tight
lists.  Now we do this:

If the list item contents begin with a Plain block,
we modify the Plain block by adding a Span around
its contents.

Otherwise, we add a Div around the contents of the
list item (instead of adding an empty Div to the
beginning, as before).

Closes #3596.
This commit is contained in:
John MacFarlane 2017-04-23 10:55:16 +02:00
parent c5f4a0b9c5
commit 51a46b7e31
2 changed files with 67 additions and 2 deletions

View file

@ -260,8 +260,12 @@ pBulletList = try $ do
pListItem :: PandocMonad m => TagParser m a -> TagParser m Blocks
pListItem nonItem = do
TagOpen _ attr <- lookAhead $ pSatisfy (~== TagOpen "li" [])
let liDiv = maybe mempty (\x -> B.divWith (x, [], []) mempty) (lookup "id" attr)
(liDiv <>) <$> pInTags "li" block <* skipMany nonItem
let addId ident bs = case B.toList bs of
(Plain ils:xs) -> B.fromList (Plain
[Span (ident, [], []) ils] : xs)
_ -> B.divWith (ident, [], []) bs
(maybe id addId (lookup "id" attr)) <$>
pInTags "li" block <* skipMany nonItem
parseListStyleType :: String -> ListNumberStyle
parseListStyleType "lower-roman" = LowerRoman

61
test/command/3596.md Normal file
View file

@ -0,0 +1,61 @@
```
% pandoc -f html -t markdown-raw_html-bracketed_spans-native_spans
<ul>
<li>foo</li>
<li id="id">bar</li>
<li>baz</li>
</ul>
^D
- foo
- bar
- baz
```
```
% pandoc -f html -t markdown-raw_html-bracketed_spans-native_spans
<ul>
<li>foo</li>
<li id="id">bar<ul><li>subbar</li></ul></li>
<li>baz</li>
</ul>
^D
- foo
- bar
- subbar
- baz
```
```
% pandoc -f html -t markdown
<ul>
<li>foo</li>
<li id="id">bar</li>
<li>baz</li>
</ul>
^D
- foo
- [bar]{#id}
- baz
```
```
% pandoc -f html -t markdown
<ul>
<li><p>foo</p></li>
<li id="id"><p>bar</p></li>
<li><p>baz</p></li>
</ul>
^D
- foo
- <div id="id">
bar
</div>
- baz
```