git.iko.soy/typeable/pandoc
on master help sign in
Shared.compactify: Avoid mixed lists.

This improves on the original fix to #5285 by preventing other mixed lists (lists with a mix of Plain and Para elements) that were allowed given the original fix.

commitba05e1ea02d5227796f12dea2404285300021de6 authorJohn MacFarlane <jgm@berkeley.edu> dateSat 23 Feb 2019, 15:40 (8 years ago) parent38c028b
23 files changed+48−26
src/Text/Pandoc/Shared.hs+6−7 test/command/5285.md+17 test/rst-reader.native+5−5 test/rst-reader.rst+1−1 test/testsuite.native+1−1 test/writer.custom+1−1 test/writer.dokuwiki+1−1 test/writer.fb2+1 test/writer.haddock+1 test/writer.html4+1−1 test/writer.html5+1−1 test/writer.icml+2−2 test/writer.markdown+1 test/writer.mediawiki+1−1 test/writer.native+1−1 test/writer.opendocument−1 test/writer.opml+1−1 test/writer.org+1 test/writer.plain+1 test/writer.rst+1 test/writer.rtf+1−1 test/writer.texinfo+1 test/writer.textile+1−1
src/Text/Pandoc/Shared.hs+6−7
@@ -424,13 +424,12 @@ compactify [] = []
424424compactify items =
425425 let (others, final) = (init items, last items)
426426 in case reverse (B.toList final) of
427− (Para a:xs) -> case [Para x | Para x <- concatMap B.toList items] of
428− -- if this is only Para, change to Plain
429− [_] -> others ++ [B.fromList (reverse $ Plain a : xs)]
430− -- if other Paras, it's a loose list, change
431− -- all Plain to Para
432− _ -> map (fmap plainToPara) items
433− _ -> items
427+ (Para a:xs)
428+ | null [Para x | Para x <- (xs ++ concatMap B.toList others)]
429+ -> others ++ [B.fromList (reverse (Plain a : xs))]
430+ _ | null [Para x | Para x <- concatMap B.toList items]
431+ -> items
432+ _ -> map (fmap plainToPara) items
434433
435434plainToPara :: Block -> Block
436435plainToPara (Plain ils) = Para ils
test/command/5285.md+17
@@ -13,3 +13,20 @@
1313 ,[Para [Str "a"]]
1414 ,[Para [Str "b"]]]]
1515```
16+
17+```
18+% pandoc -t native
19+- foo
20+
21+ foo
22+- foo
23+
24+ > foo
25+^D
26+[BulletList
27+ [[Para [Str "foo"]
28+ ,Para [Str "foo"]]
29+ ,[Para [Str "foo"]
30+ ,BlockQuote
31+ [Para [Str "foo"]]]]]
32+```
test/rst-reader.native+5−5
@@ -96,8 +96,8 @@ Pandoc (Meta {unMeta = fromList [("author",MetaList [MetaInlines [Str "John",Spa
9696,OrderedList (1,Decimal,Period)
9797 [[Para [Str "Item",Space,Str "1,",Space,Str "graf",Space,Str "one."]
9898 ,Para [Str "Item",Space,Str "1.",Space,Str "graf",Space,Str "two.",Space,Str "The",Space,Str "quick",Space,Str "brown",Space,Str "fox",Space,Str "jumped",Space,Str "over",Space,Str "the",Space,Str "lazy",Space,Str "dog\8217s",SoftBreak,Str "back."]]
99− ,[Plain [Str "Item",Space,Str "2."]]
100− ,[Plain [Str "Item",Space,Str "3."]]]
99+ ,[Para [Str "Item",Space,Str "2."]]
100+ ,[Para [Str "Item",Space,Str "3."]]]
101101,Para [Str "Nested:"]
102102,BulletList
103103 [[Plain [Str "Tab"]
@@ -107,17 +107,17 @@ Pandoc (Meta {unMeta = fromList [("author",MetaList [MetaInlines [Str "John",Spa
107107 [[Plain [Str "Tab"]]]]]]]
108108,Para [Str "Here\8217s",Space,Str "another:"]
109109,OrderedList (1,Decimal,Period)
110− [[Plain [Str "First"]]
110+ [[Para [Str "First"]]
111111 ,[Para [Str "Second:"]
112112 ,BlockQuote
113113 [BulletList
114114 [[Plain [Str "Fee"]]
115115 ,[Plain [Str "Fie"]]
116116 ,[Plain [Str "Foe"]]]]]
117− ,[Plain [Str "Third"]]]
117+ ,[Para [Str "Third"]]]
118118,Header 2 ("fancy-list-markers",[],[]) [Str "Fancy",Space,Str "list",Space,Str "markers"]
119119,OrderedList (2,Decimal,TwoParens)
120− [[Plain [Str "begins",Space,Str "with",Space,Str "2"]]
120+ [[Para [Str "begins",Space,Str "with",Space,Str "2"]]
121121 ,[Para [Str "and",Space,Str "now",Space,Str "3"]
122122 ,Para [Str "with",Space,Str "a",Space,Str "continuation"]
123123 ,OrderedList (4,LowerRoman,Period)
test/rst-reader.rst+1−1
@@ -192,7 +192,7 @@ Multiple paragraphs:
192192
193193 Item 1. graf two. The quick brown fox jumped over the lazy dog's
194194 back.
195−
195+
1961962. Item 2.
197197
1981983. Item 3.
test/testsuite.native+1−1
@@ -137,7 +137,7 @@ Pandoc (Meta {unMeta = fromList [("author",MetaList [MetaInlines [Str "John",Spa
137137 ,[Para [Str "this",Space,Str "is",Space,Str "an",Space,Str "example",Space,Str "list",Space,Str "item",SoftBreak,Str "indented",Space,Str "with",Space,Str "spaces"]]]]]
138138,Header 2 ("fancy-list-markers",[],[]) [Str "Fancy",Space,Str "list",Space,Str "markers"]
139139,OrderedList (2,Decimal,TwoParens)
140− [[Plain [Str "begins",Space,Str "with",Space,Str "2"]]
140+ [[Para [Str "begins",Space,Str "with",Space,Str "2"]]
141141 ,[Para [Str "and",Space,Str "now",Space,Str "3"]
142142 ,Para [Str "with",Space,Str "a",Space,Str "continuation"]
143143 ,OrderedList (4,LowerRoman,Period)
test/writer.custom+1−1
@@ -263,7 +263,7 @@ indented with spaces</p></li>
263263<h2 id="fancy-list-markers">Fancy list markers</h2>
264264
265265<ol>
266−<li>begins with 2</li>
266+<li><p>begins with 2</p></li>
267267<li><p>and now 3</p>
268268
269269<p>with a continuation</p>
test/writer.dokuwiki+1−1
@@ -205,7 +205,7 @@ Same thing but with paragraphs:
205205===== Fancy list markers =====
206206
207207<HTML><ol start="2" style="list-style-type: decimal;"></HTML>
208−<HTML><li></HTML>begins with 2<HTML></li></HTML>
208+<HTML><li></HTML><HTML><p></HTML>begins with 2<HTML></p></HTML><HTML></li></HTML>
209209<HTML><li></HTML><HTML><p></HTML>and now 3<HTML></p></HTML>
210210<HTML><p></HTML>with a continuation<HTML></p></HTML>
211211<HTML><ol start="4" style="list-style-type: lower-roman;"></HTML>
test/writer.fb2+1
@@ -302,6 +302,7 @@ indented with spaces</p>
302302<p>Fancy list markers</p>
303303</title>
304304<p>(2) begins with 2</p>
305+<empty-line />
305306<p>(3) and now 3</p>
306307<empty-line />
307308<p>    with a continuation</p>
test/writer.haddock+1
@@ -236,6 +236,7 @@ Same thing but with paragraphs:
236236#fancy-list-markers#
237237
238238(2) begins with 2
239+
239240(3) and now 3
240241
241242 with a continuation
test/writer.html4+1−1
@@ -196,7 +196,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{</code></pre>
196196</ul>
197197<h2 id="fancy-list-markers">Fancy list markers</h2>
198198<ol start="2" style="list-style-type: decimal">
199−<li>begins with 2</li>
199+<li><p>begins with 2</p></li>
200200<li><p>and now 3</p>
201201<p>with a continuation</p>
202202<ol start="4" style="list-style-type: lower-roman">
test/writer.html5+1−1
@@ -199,7 +199,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{</code></pre>
199199</ul>
200200<h2 id="fancy-list-markers">Fancy list markers</h2>
201201<ol start="2" type="1">
202−<li>begins with 2</li>
202+<li><p>begins with 2</p></li>
203203<li><p>and now 3</p>
204204<p>with a continuation</p>
205205<ol start="4" type="i">
test/writer.icml+2−2
@@ -400,7 +400,7 @@
400400 <BasedOn type="object">$ID/NormalParagraphStyle</BasedOn>
401401 </Properties>
402402 </ParagraphStyle>
403− <ParagraphStyle Self="ParagraphStyle/NumList &gt; first &gt; beginsWith-2" Name="NumList &gt; first &gt; beginsWith-2" NumberingExpression="^#.^t" NumberingLevel="1" BulletsAndNumberingListType="NumberedList" LeftIndent="0">
403+ <ParagraphStyle Self="ParagraphStyle/NumList &gt; first &gt; beginsWith-2 &gt; Paragraph" Name="NumList &gt; first &gt; beginsWith-2 &gt; Paragraph" NumberingExpression="^#.^t" NumberingLevel="1" BulletsAndNumberingListType="NumberedList" LeftIndent="0">
404404 <Properties>
405405 <BasedOn type="object">$ID/NormalParagraphStyle</BasedOn>
406406 </Properties>
@@ -1105,7 +1105,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{</Content>
11051105 </CharacterStyleRange>
11061106</ParagraphStyleRange>
11071107<Br />
1108−<ParagraphStyleRange NumberingStartAt="2" AppliedParagraphStyle="ParagraphStyle/NumList &gt; first &gt; beginsWith-2" NumberingContinue="false">
1108+<ParagraphStyleRange NumberingStartAt="2" AppliedParagraphStyle="ParagraphStyle/NumList &gt; first &gt; beginsWith-2 &gt; Paragraph" NumberingContinue="false">
11091109 <CharacterStyleRange AppliedCharacterStyle="$ID/NormalCharacterStyle">
11101110 <Content>begins with 2</Content>
11111111 </CharacterStyleRange>
test/writer.markdown+1
@@ -239,6 +239,7 @@ Fancy list markers
239239------------------
240240
241241(2) begins with 2
242+
242243(3) and now 3
243244
244245 with a continuation
test/writer.mediawiki+1−1
@@ -198,7 +198,7 @@ Same thing but with paragraphs:
198198== Fancy list markers ==
199199
200200<ol start="2" style="list-style-type: decimal;">
201−<li>begins with 2</li>
201+<li><p>begins with 2</p></li>
202202<li><p>and now 3</p>
203203<p>with a continuation</p>
204204<ol start="4" style="list-style-type: lower-roman;">
test/writer.native+1−1
@@ -137,7 +137,7 @@ Pandoc (Meta {unMeta = fromList [("author",MetaList [MetaInlines [Str "John",Spa
137137 ,[Para [Str "this",Space,Str "is",Space,Str "an",Space,Str "example",Space,Str "list",Space,Str "item",SoftBreak,Str "indented",Space,Str "with",Space,Str "spaces"]]]]]
138138,Header 2 ("fancy-list-markers",[],[]) [Str "Fancy",Space,Str "list",Space,Str "markers"]
139139,OrderedList (2,Decimal,TwoParens)
140− [[Plain [Str "begins",Space,Str "with",Space,Str "2"]]
140+ [[Para [Str "begins",Space,Str "with",Space,Str "2"]]
141141 ,[Para [Str "and",Space,Str "now",Space,Str "3"]
142142 ,Para [Str "with",Space,Str "a",Space,Str "continuation"]
143143 ,OrderedList (4,LowerRoman,Period)
test/writer.opendocument−1
@@ -1115,7 +1115,6 @@
11151115 <style:style style:name="P38" style:family="paragraph" style:parent-style-name="Text_20_body" style:list-style-name="L21">
11161116 </style:style>
11171117 <style:style style:name="P39" style:family="paragraph" style:parent-style-name="Text_20_body" style:list-style-name="L22">
1118− <style:paragraph-properties fo:margin-top="0in" fo:margin-bottom="0in" />
11191118 </style:style>
11201119 <style:style style:name="P40" style:family="paragraph" style:parent-style-name="Text_20_body" style:list-style-name="L23">
11211120 <style:paragraph-properties fo:margin-top="0in" fo:margin-bottom="0in" />
test/writer.opml+1−1
@@ -39,7 +39,7 @@
3939 </outline>
4040 <outline text="Tabs and spaces" _note="- this is a list item indented with tabs&#10;&#10;- this is a list item indented with spaces&#10;&#10; - this is an example list item indented with tabs&#10;&#10; - this is an example list item indented with spaces">
4141 </outline>
42− <outline text="Fancy list markers" _note="1. begins with 2&#10;2. and now 3&#10;&#10; with a continuation&#10;&#10; 1. sublist with roman numerals, starting with 4&#10; 2. more items&#10; 1. a subsublist&#10; 2. a subsublist&#10;&#10;Nesting:&#10;&#10;1. Upper Alpha&#10; 1. Upper Roman.&#10; 1. Decimal start with 6&#10; 1. Lower alpha with paren&#10;&#10;Autonumbering:&#10;&#10;1. Autonumber.&#10;2. More.&#10; 1. Nested.&#10;&#10;Should not be a list item:&#10;&#10;M.A. 2007&#10;&#10;B. Williams&#10;&#10;------------------------------------------------------------------------">
42+ <outline text="Fancy list markers" _note="1. begins with 2&#10;&#10;2. and now 3&#10;&#10; with a continuation&#10;&#10; 1. sublist with roman numerals, starting with 4&#10; 2. more items&#10; 1. a subsublist&#10; 2. a subsublist&#10;&#10;Nesting:&#10;&#10;1. Upper Alpha&#10; 1. Upper Roman.&#10; 1. Decimal start with 6&#10; 1. Lower alpha with paren&#10;&#10;Autonumbering:&#10;&#10;1. Autonumber.&#10;2. More.&#10; 1. Nested.&#10;&#10;Should not be a list item:&#10;&#10;M.A. 2007&#10;&#10;B. Williams&#10;&#10;------------------------------------------------------------------------">
4343 </outline>
4444</outline>
4545<outline text="Definition Lists" _note="Tight using spaces:&#10;&#10;apple &#10;red fruit&#10;&#10;orange &#10;orange fruit&#10;&#10;banana &#10;yellow fruit&#10;&#10;Tight using tabs:&#10;&#10;apple &#10;red fruit&#10;&#10;orange &#10;orange fruit&#10;&#10;banana &#10;yellow fruit&#10;&#10;Loose:&#10;&#10;apple &#10;red fruit&#10;&#10;orange &#10;orange fruit&#10;&#10;banana &#10;yellow fruit&#10;&#10;Multiple blocks with italics:&#10;&#10;*apple* &#10;red fruit&#10;&#10;contains seeds, crisp, pleasant to taste&#10;&#10;*orange* &#10;orange fruit&#10;&#10; { orange code block }&#10;&#10;&gt; orange block quote&#10;&#10;Multiple definitions, tight:&#10;&#10;apple &#10;red fruit&#10;&#10;computer&#10;&#10;orange &#10;orange fruit&#10;&#10;bank&#10;&#10;Multiple definitions, loose:&#10;&#10;apple &#10;red fruit&#10;&#10;computer&#10;&#10;orange &#10;orange fruit&#10;&#10;bank&#10;&#10;Blank line after term, indented marker, alternate markers:&#10;&#10;apple &#10;red fruit&#10;&#10;computer&#10;&#10;orange &#10;orange fruit&#10;&#10;1. sublist&#10;2. sublist">
test/writer.org+1
@@ -294,6 +294,7 @@ Same thing but with paragraphs:
294294 :END:
295295
2962962) begins with 2
297+
2972983) and now 3
298299
299300 with a continuation
test/writer.plain+1
@@ -244,6 +244,7 @@ Tabs and spaces
244244Fancy list markers
245245
246246(2) begins with 2
247+
247248(3) and now 3
248249
249250 with a continuation
test/writer.rst+1
@@ -261,6 +261,7 @@ Fancy list markers
261261------------------
262262
263263(2) begins with 2
264+
264265(3) and now 3
265266
266267 with a continuation
test/writer.rtf+1−1
@@ -132,7 +132,7 @@ These should not be escaped: \\$ \\\\ \\> \\[ \\\{\par}
132132{\pard \ql \f0 \sa180 \li720 \fi-360 \endash \tx360\tab this is an example list item indented with tabs\par}
133133{\pard \ql \f0 \sa180 \li720 \fi-360 \endash \tx360\tab this is an example list item indented with spaces\sa180\sa180\par}
134134{\pard \ql \f0 \sa180 \li0 \fi0 \b \fs32 Fancy list markers\par}
135−{\pard \ql \f0 \sa0 \li360 \fi-360 (2)\tx360\tab begins with 2\par}
135+{\pard \ql \f0 \sa180 \li360 \fi-360 (2)\tx360\tab begins with 2\par}
136136{\pard \ql \f0 \sa180 \li360 \fi-360 (3)\tx360\tab and now 3\par}
137137{\pard \ql \f0 \sa180 \li360 \fi0 with a continuation\par}
138138{\pard \ql \f0 \sa0 \li720 \fi-360 iv.\tx360\tab sublist with roman numerals, starting with 4\par}
test/writer.texinfo+1
@@ -453,6 +453,7 @@ this is an example list item indented with spaces
453453@enumerate 2
454454@item
455455begins with 2
456+
456457@item
457458and now 3
458459
test/writer.textile+1−1
@@ -212,7 +212,7 @@ h2(#tabs-and-spaces). Tabs and spaces
212212h2(#fancy-list-markers). Fancy list markers
213213
214214<ol start="2" style="list-style-type: decimal;">
215−<li>begins with 2</li>
215+<li><p>begins with 2</p></li>
216216<li><p>and now 3</p>
217217<p>with a continuation</p>
218218<ol start="4" style="list-style-type: lower-roman;">