git.iko.soy/typeable/pandoc
on master help sign in
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.

commit51a46b7e31c92c717ca4778df96535b0e492babe authorJohn MacFarlane <jgm@berkeley.edu> dateSun 23 Apr 2017, 10:55 (10 years ago) parentc5f4a0b
2 files changed+67−2
src/Text/Pandoc/Readers/HTML.hs+6−2 test/command/3596.md+61
src/Text/Pandoc/Readers/HTML.hs+6−2
@@ -260,8 +260,12 @@ pBulletList = try $ do
260260pListItem :: PandocMonad m => TagParser m a -> TagParser m Blocks
261261pListItem nonItem = do
262262 TagOpen _ attr <- lookAhead $ pSatisfy (~== TagOpen "li" [])
263− let liDiv = maybe mempty (\x -> B.divWith (x, [], []) mempty) (lookup "id" attr)
264− (liDiv <>) <$> pInTags "li" block <* skipMany nonItem
263+ let addId ident bs = case B.toList bs of
264+ (Plain ils:xs) -> B.fromList (Plain
265+ [Span (ident, [], []) ils] : xs)
266+ _ -> B.divWith (ident, [], []) bs
267+ (maybe id addId (lookup "id" attr)) <$>
268+ pInTags "li" block <* skipMany nonItem
265269
266270parseListStyleType :: String -> ListNumberStyle
267271parseListStyleType "lower-roman" = LowerRoman
test/command/3596.mdnew file+61
@@ -0,0 +1,61 @@
1+```
2+% pandoc -f html -t markdown-raw_html-bracketed_spans-native_spans
3+<ul>
4+<li>foo</li>
5+<li id="id">bar</li>
6+<li>baz</li>
7+</ul>
8+^D
9+- foo
10+- bar
11+- baz
12+```
13+
14+```
15+% pandoc -f html -t markdown-raw_html-bracketed_spans-native_spans
16+<ul>
17+<li>foo</li>
18+<li id="id">bar<ul><li>subbar</li></ul></li>
19+<li>baz</li>
20+</ul>
21+^D
22+- foo
23+- bar
24+ - subbar
25+- baz
26+```
27+
28+
29+```
30+% pandoc -f html -t markdown
31+<ul>
32+<li>foo</li>
33+<li id="id">bar</li>
34+<li>baz</li>
35+</ul>
36+^D
37+- foo
38+- [bar]{#id}
39+- baz
40+```
41+
42+
43+```
44+% pandoc -f html -t markdown
45+<ul>
46+<li><p>foo</p></li>
47+<li id="id"><p>bar</p></li>
48+<li><p>baz</p></li>
49+</ul>
50+^D
51+- foo
52+
53+- <div id="id">
54+
55+ bar
56+
57+ </div>
58+
59+- baz
60+
61+```