git.iko.soy/typeable/pandoc
on master help sign in
Distinguish tight and loose lists in Docbook output

Determined by the first block of the first item being Plain.

commitccbf4fc9c20ccdce0f7144845cd022ee8cfca1af authorNeil Mayhew <neiljhmayhew@gmail.com> dateMon 14 Apr 2014, 19:07 (13 years ago) parent2ba7873
3 files changed+236−49
src/Text/Pandoc/Writers/Docbook.hs+18−8 tests/Tests/Writers/Docbook.hs+188−11 tests/writer.docbook+30−30
src/Text/Pandoc/Writers/Docbook.hs+18−8
@@ -185,10 +185,13 @@ blockToDocbook _ (CodeBlock (_,classes,_) str) =
185185 else languagesByExtension . map toLower $ s
186186 langs = concatMap langsFrom classes
187187blockToDocbook opts (BulletList lst) =
188− inTagsIndented "itemizedlist" $ listItemsToDocbook opts lst
188+ let attribs = case lst of
189+ ((Plain _:_):_) -> [("spacing", "compact")]
190+ _ -> []
191+ in inTags True "itemizedlist" attribs $ listItemsToDocbook opts lst
189192blockToDocbook _ (OrderedList _ []) = empty
190193blockToDocbook opts (OrderedList (start, numstyle, _) (first:rest)) =
191− let attribs = case numstyle of
194+ let numeration = case numstyle of
192195 DefaultStyle -> []
193196 Decimal -> [("numeration", "arabic")]
194197 Example -> [("numeration", "arabic")]
@@ -196,14 +199,21 @@ blockToDocbook opts (OrderedList (start, numstyle, _) (first:rest)) =
196199 LowerAlpha -> [("numeration", "loweralpha")]
197200 UpperRoman -> [("numeration", "upperroman")]
198201 LowerRoman -> [("numeration", "lowerroman")]
199− items = if start == 1
200− then listItemsToDocbook opts (first:rest)
201− else (inTags True "listitem" [("override",show start)]
202− (blocksToDocbook opts $ map plainToPara first)) $$
203− listItemsToDocbook opts rest
202+ spacing = case first of
203+ (Plain _:_) -> [("spacing", "compact")]
204+ _ -> []
205+ attribs = numeration ++ spacing
206+ items = if start == 1
207+ then listItemsToDocbook opts (first:rest)
208+ else (inTags True "listitem" [("override",show start)]
209+ (blocksToDocbook opts $ map plainToPara first)) $$
210+ listItemsToDocbook opts rest
204211 in inTags True "orderedlist" attribs items
205212blockToDocbook opts (DefinitionList lst) =
206− inTagsIndented "variablelist" $ deflistItemsToDocbook opts lst
213+ let attribs = case lst of
214+ ((_, (Plain _:_):_):_) -> [("spacing", "compact")]
215+ _ -> []
216+ in inTags True "variablelist" attribs $ deflistItemsToDocbook opts lst
207217blockToDocbook _ (RawBlock f str)
208218 | f == "docbook" = text str -- raw XML block
209219 | f == "html" = text str -- allow html for backwards compatibility
tests/Tests/Writers/Docbook.hs+188−11
@@ -31,22 +31,199 @@ lineblock :: Blocks
3131lineblock = para ("some text" <> linebreak <>
3232 "and more lines" <> linebreak <>
3333 "and again")
34−lineblock_out :: String
35−lineblock_out = "<literallayout>some text\n" ++
36− "and more lines\n" ++
37− "and again</literallayout>"
34+lineblock_out :: [String]
35+lineblock_out = [ "<literallayout>some text"
36+ , "and more lines"
37+ , "and again</literallayout>"
38+ ]
3839
3940tests :: [Test]
4041tests = [ testGroup "line blocks"
4142 [ "none" =: para "This is a test"
42− =?> "<para>\n This is a test\n</para>"
43+ =?> unlines
44+ [ "<para>"
45+ , " This is a test"
46+ , "</para>"
47+ ]
4348 , "basic" =: lineblock
44− =?> lineblock_out
49+ =?> unlines lineblock_out
4550 , "blockquote" =: blockQuote lineblock
46− =?> ("<blockquote>\n" ++ lineblock_out ++ "\n</blockquote>")
47− , "footnote" =: para ("This is a test" <> note lineblock <> " of footnotes")
48− =?> ("<para>\n This is a test<footnote>\n" ++
49− lineblock_out ++
50− "\n </footnote> of footnotes\n</para>")
51+ =?> unlines
52+ ( [ "<blockquote>" ] ++
53+ lineblock_out ++
54+ [ "</blockquote>" ]
55+ )
56+ , "footnote" =: para ("This is a test" <>
57+ note lineblock <>
58+ " of footnotes")
59+ =?> unlines
60+ ( [ "<para>"
61+ , " This is a test<footnote>" ] ++
62+ lineblock_out ++
63+ [ " </footnote> of footnotes"
64+ , "</para>" ]
65+ )
66+ ]
67+ , testGroup "compact lists"
68+ [ testGroup "bullet"
69+ [ "compact" =: bulletList [plain "a", plain "b", plain "c"]
70+ =?> unlines
71+ [ "<itemizedlist spacing=\"compact\">"
72+ , " <listitem>"
73+ , " <para>"
74+ , " a"
75+ , " </para>"
76+ , " </listitem>"
77+ , " <listitem>"
78+ , " <para>"
79+ , " b"
80+ , " </para>"
81+ , " </listitem>"
82+ , " <listitem>"
83+ , " <para>"
84+ , " c"
85+ , " </para>"
86+ , " </listitem>"
87+ , "</itemizedlist>"
88+ ]
89+ , "loose" =: bulletList [para "a", para "b", para "c"]
90+ =?> unlines
91+ [ "<itemizedlist>"
92+ , " <listitem>"
93+ , " <para>"
94+ , " a"
95+ , " </para>"
96+ , " </listitem>"
97+ , " <listitem>"
98+ , " <para>"
99+ , " b"
100+ , " </para>"
101+ , " </listitem>"
102+ , " <listitem>"
103+ , " <para>"
104+ , " c"
105+ , " </para>"
106+ , " </listitem>"
107+ , "</itemizedlist>"
108+ ]
109+ ]
110+ , testGroup "ordered"
111+ [ "compact" =: orderedList [plain "a", plain "b", plain "c"]
112+ =?> unlines
113+ [ "<orderedlist spacing=\"compact\">"
114+ , " <listitem>"
115+ , " <para>"
116+ , " a"
117+ , " </para>"
118+ , " </listitem>"
119+ , " <listitem>"
120+ , " <para>"
121+ , " b"
122+ , " </para>"
123+ , " </listitem>"
124+ , " <listitem>"
125+ , " <para>"
126+ , " c"
127+ , " </para>"
128+ , " </listitem>"
129+ , "</orderedlist>"
130+ ]
131+ , "loose" =: orderedList [para "a", para "b", para "c"]
132+ =?> unlines
133+ [ "<orderedlist>"
134+ , " <listitem>"
135+ , " <para>"
136+ , " a"
137+ , " </para>"
138+ , " </listitem>"
139+ , " <listitem>"
140+ , " <para>"
141+ , " b"
142+ , " </para>"
143+ , " </listitem>"
144+ , " <listitem>"
145+ , " <para>"
146+ , " c"
147+ , " </para>"
148+ , " </listitem>"
149+ , "</orderedlist>"
150+ ]
151+ ]
152+ , testGroup "definition"
153+ [ "compact" =: definitionList [ ("an", [plain "apple" ])
154+ , ("a", [plain "banana"])
155+ , ("an", [plain "orange"])]
156+ =?> unlines
157+ [ "<variablelist spacing=\"compact\">"
158+ , " <varlistentry>"
159+ , " <term>"
160+ , " an"
161+ , " </term>"
162+ , " <listitem>"
163+ , " <para>"
164+ , " apple"
165+ , " </para>"
166+ , " </listitem>"
167+ , " </varlistentry>"
168+ , " <varlistentry>"
169+ , " <term>"
170+ , " a"
171+ , " </term>"
172+ , " <listitem>"
173+ , " <para>"
174+ , " banana"
175+ , " </para>"
176+ , " </listitem>"
177+ , " </varlistentry>"
178+ , " <varlistentry>"
179+ , " <term>"
180+ , " an"
181+ , " </term>"
182+ , " <listitem>"
183+ , " <para>"
184+ , " orange"
185+ , " </para>"
186+ , " </listitem>"
187+ , " </varlistentry>"
188+ , "</variablelist>"
189+ ]
190+ , "loose" =: definitionList [ ("an", [para "apple" ])
191+ , ("a", [para "banana"])
192+ , ("an", [para "orange"])]
193+ =?> unlines
194+ [ "<variablelist>"
195+ , " <varlistentry>"
196+ , " <term>"
197+ , " an"
198+ , " </term>"
199+ , " <listitem>"
200+ , " <para>"
201+ , " apple"
202+ , " </para>"
203+ , " </listitem>"
204+ , " </varlistentry>"
205+ , " <varlistentry>"
206+ , " <term>"
207+ , " a"
208+ , " </term>"
209+ , " <listitem>"
210+ , " <para>"
211+ , " banana"
212+ , " </para>"
213+ , " </listitem>"
214+ , " </varlistentry>"
215+ , " <varlistentry>"
216+ , " <term>"
217+ , " an"
218+ , " </term>"
219+ , " <listitem>"
220+ , " <para>"
221+ , " orange"
222+ , " </para>"
223+ , " </listitem>"
224+ , " </varlistentry>"
225+ , "</variablelist>"
226+ ]
227+ ]
51228 ]
52229 ]
tests/writer.docbook+30−30
@@ -93,7 +93,7 @@ sub status {
9393 <para>
9494 A list:
9595 </para>
96− <orderedlist numeration="arabic">
96+ <orderedlist numeration="arabic" spacing="compact">
9797 <listitem>
9898 <para>
9999 item one
@@ -156,7 +156,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
156156 <para>
157157 Asterisks tight:
158158 </para>
159− <itemizedlist>
159+ <itemizedlist spacing="compact">
160160 <listitem>
161161 <para>
162162 asterisk 1
@@ -196,7 +196,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
196196 <para>
197197 Pluses tight:
198198 </para>
199− <itemizedlist>
199+ <itemizedlist spacing="compact">
200200 <listitem>
201201 <para>
202202 Plus 1
@@ -236,7 +236,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
236236 <para>
237237 Minuses tight:
238238 </para>
239− <itemizedlist>
239+ <itemizedlist spacing="compact">
240240 <listitem>
241241 <para>
242242 Minus 1
@@ -279,7 +279,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
279279 <para>
280280 Tight:
281281 </para>
282− <orderedlist numeration="arabic">
282+ <orderedlist numeration="arabic" spacing="compact">
283283 <listitem>
284284 <para>
285285 First
@@ -299,7 +299,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
299299 <para>
300300 and:
301301 </para>
302− <orderedlist numeration="arabic">
302+ <orderedlist numeration="arabic" spacing="compact">
303303 <listitem>
304304 <para>
305305 One
@@ -383,17 +383,17 @@ These should not be escaped: \$ \\ \&gt; \[ \{
383383 </sect2>
384384 <sect2 id="nested">
385385 <title>Nested</title>
386− <itemizedlist>
386+ <itemizedlist spacing="compact">
387387 <listitem>
388388 <para>
389389 Tab
390390 </para>
391− <itemizedlist>
391+ <itemizedlist spacing="compact">
392392 <listitem>
393393 <para>
394394 Tab
395395 </para>
396− <itemizedlist>
396+ <itemizedlist spacing="compact">
397397 <listitem>
398398 <para>
399399 Tab
@@ -407,7 +407,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
407407 <para>
408408 Here’s another:
409409 </para>
410− <orderedlist numeration="arabic">
410+ <orderedlist numeration="arabic" spacing="compact">
411411 <listitem>
412412 <para>
413413 First
@@ -417,7 +417,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
417417 <para>
418418 Second:
419419 </para>
420− <itemizedlist>
420+ <itemizedlist spacing="compact">
421421 <listitem>
422422 <para>
423423 Fee
@@ -454,7 +454,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
454454 <para>
455455 Second:
456456 </para>
457− <itemizedlist>
457+ <itemizedlist spacing="compact">
458458 <listitem>
459459 <para>
460460 Fee
@@ -508,7 +508,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
508508 </sect2>
509509 <sect2 id="fancy-list-markers">
510510 <title>Fancy list markers</title>
511− <orderedlist numeration="arabic">
511+ <orderedlist numeration="arabic" spacing="compact">
512512 <listitem override="2">
513513 <para>
514514 begins with 2
@@ -521,7 +521,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
521521 <para>
522522 with a continuation
523523 </para>
524− <orderedlist numeration="lowerroman">
524+ <orderedlist numeration="lowerroman" spacing="compact">
525525 <listitem override="4">
526526 <para>
527527 sublist with roman numerals, starting with 4
@@ -531,7 +531,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
531531 <para>
532532 more items
533533 </para>
534− <orderedlist numeration="upperalpha">
534+ <orderedlist numeration="upperalpha" spacing="compact">
535535 <listitem>
536536 <para>
537537 a subsublist
@@ -550,22 +550,22 @@ These should not be escaped: \$ \\ \&gt; \[ \{
550550 <para>
551551 Nesting:
552552 </para>
553− <orderedlist numeration="upperalpha">
553+ <orderedlist numeration="upperalpha" spacing="compact">
554554 <listitem>
555555 <para>
556556 Upper Alpha
557557 </para>
558− <orderedlist numeration="upperroman">
558+ <orderedlist numeration="upperroman" spacing="compact">
559559 <listitem>
560560 <para>
561561 Upper Roman.
562562 </para>
563− <orderedlist numeration="arabic">
563+ <orderedlist numeration="arabic" spacing="compact">
564564 <listitem override="6">
565565 <para>
566566 Decimal start with 6
567567 </para>
568− <orderedlist numeration="loweralpha">
568+ <orderedlist numeration="loweralpha" spacing="compact">
569569 <listitem override="3">
570570 <para>
571571 Lower alpha with paren
@@ -581,7 +581,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
581581 <para>
582582 Autonumbering:
583583 </para>
584− <orderedlist>
584+ <orderedlist spacing="compact">
585585 <listitem>
586586 <para>
587587 Autonumber.
@@ -591,7 +591,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
591591 <para>
592592 More.
593593 </para>
594− <orderedlist>
594+ <orderedlist spacing="compact">
595595 <listitem>
596596 <para>
597597 Nested.
@@ -616,7 +616,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
616616 <para>
617617 Tight using spaces:
618618 </para>
619− <variablelist>
619+ <variablelist spacing="compact">
620620 <varlistentry>
621621 <term>
622622 apple
@@ -651,7 +651,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
651651 <para>
652652 Tight using tabs:
653653 </para>
654− <variablelist>
654+ <variablelist spacing="compact">
655655 <varlistentry>
656656 <term>
657657 apple
@@ -757,7 +757,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
757757 <para>
758758 Multiple definitions, tight:
759759 </para>
760− <variablelist>
760+ <variablelist spacing="compact">
761761 <varlistentry>
762762 <term>
763763 apple
@@ -841,7 +841,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
841841 <para>
842842 orange fruit
843843 </para>
844− <orderedlist numeration="arabic">
844+ <orderedlist numeration="arabic" spacing="compact">
845845 <listitem>
846846 <para>
847847 sublist
@@ -1051,7 +1051,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
10511051</sect1>
10521052<sect1 id="latex">
10531053 <title>LaTeX</title>
1054− <itemizedlist>
1054+ <itemizedlist spacing="compact">
10551055 <listitem>
10561056 <para>
10571057 </para>
@@ -1097,7 +1097,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
10971097 <para>
10981098 These shouldn’t be math:
10991099 </para>
1100− <itemizedlist>
1100+ <itemizedlist spacing="compact">
11011101 <listitem>
11021102 <para>
11031103 To get the famous equation, write <literal>$e = mc^2$</literal>.
@@ -1130,7 +1130,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
11301130 <para>
11311131 Here is some unicode:
11321132 </para>
1133− <itemizedlist>
1133+ <itemizedlist spacing="compact">
11341134 <listitem>
11351135 <para>
11361136 I hat: Î
@@ -1316,7 +1316,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
13161316 With an ampersand:
13171317 <ulink url="http://example.com/?foo=1&amp;bar=2">http://example.com/?foo=1&amp;bar=2</ulink>
13181318 </para>
1319− <itemizedlist>
1319+ <itemizedlist spacing="compact">
13201320 <listitem>
13211321 <para>
13221322 In a list?
@@ -1414,7 +1414,7 @@ or here: &lt;http://example.com/&gt;
14141414 </footnote>
14151415 </para>
14161416 </blockquote>
1417− <orderedlist numeration="arabic">
1417+ <orderedlist numeration="arabic" spacing="compact">
14181418 <listitem>
14191419 <para>
14201420 And in list items.<footnote>