git.iko.soy/typeable/pandoc
on master help sign in
Distinguish tight and loose lists in Docbook output
ccbf4fcNeil Mayhew
src/Text/Pandoc/Writers/Docbook.hs+18−8
@@ -185,10 +185,13 @@ blockToDocbook _ (CodeBlock (_,classes,_) str) =
185 else languagesByExtension . map toLower $ s
185 else languagesByExtension . map toLower $ s
186 langs = concatMap langsFrom classes
186 langs = concatMap langsFrom classes
187blockToDocbook opts (BulletList lst) =
187blockToDocbook opts (BulletList lst) =
188+ let attribs = case lst of
189+ ((Plain _:_):_) -> [("spacing", "compact")]
190+ _ -> []
188− inTagsIndented "itemizedlist" $ listItemsToDocbook opts lst
191+ in inTags True "itemizedlist" attribs $ listItemsToDocbook opts lst
189blockToDocbook _ (OrderedList _ []) = empty
192blockToDocbook _ (OrderedList _ []) = empty
190blockToDocbook opts (OrderedList (start, numstyle, _) (first:rest)) =
193blockToDocbook opts (OrderedList (start, numstyle, _) (first:rest)) =
191− let attribs = case numstyle of
194+ let numeration = case numstyle of
192 DefaultStyle -> []
195 DefaultStyle -> []
193 Decimal -> [("numeration", "arabic")]
196 Decimal -> [("numeration", "arabic")]
194 Example -> [("numeration", "arabic")]
197 Example -> [("numeration", "arabic")]
@@ -196,14 +199,21 @@ blockToDocbook opts (OrderedList (start, numstyle, _) (first:rest)) =
196 LowerAlpha -> [("numeration", "loweralpha")]
199 LowerAlpha -> [("numeration", "loweralpha")]
197 UpperRoman -> [("numeration", "upperroman")]
200 UpperRoman -> [("numeration", "upperroman")]
198 LowerRoman -> [("numeration", "lowerroman")]
201 LowerRoman -> [("numeration", "lowerroman")]
202+ spacing = case first of
203+ (Plain _:_) -> [("spacing", "compact")]
204+ _ -> []
205+ attribs = numeration ++ spacing
199− items = if start == 1
206+ items = if start == 1
200− then listItemsToDocbook opts (first:rest)
207+ then listItemsToDocbook opts (first:rest)
201− else (inTags True "listitem" [("override",show start)]
208+ else (inTags True "listitem" [("override",show start)]
202− (blocksToDocbook opts $ map plainToPara first)) $$
209+ (blocksToDocbook opts $ map plainToPara first)) $$
203− listItemsToDocbook opts rest
210+ listItemsToDocbook opts rest
204 in inTags True "orderedlist" attribs items
211 in inTags True "orderedlist" attribs items
205blockToDocbook opts (DefinitionList lst) =
212blockToDocbook opts (DefinitionList lst) =
213+ let attribs = case lst of
214+ ((_, (Plain _:_):_):_) -> [("spacing", "compact")]
215+ _ -> []
206− inTagsIndented "variablelist" $ deflistItemsToDocbook opts lst
216+ in inTags True "variablelist" attribs $ deflistItemsToDocbook opts lst
207blockToDocbook _ (RawBlock f str)
217blockToDocbook _ (RawBlock f str)
208 | f == "docbook" = text str -- raw XML block
218 | f == "docbook" = text str -- raw XML block
209 | f == "html" = text str -- allow html for backwards compatibility
219 | f == "html" = text str -- allow html for backwards compatibility
tests/Tests/Writers/Docbook.hs+188−11
@@ -31,22 +31,199 @@ lineblock :: Blocks
31lineblock = para ("some text" <> linebreak <>
31lineblock = para ("some text" <> linebreak <>
32 "and more lines" <> linebreak <>
32 "and more lines" <> linebreak <>
33 "and again")
33 "and again")
34−lineblock_out :: String
34+lineblock_out :: [String]
35−lineblock_out = "<literallayout>some text\n" ++
35+lineblock_out = [ "<literallayout>some text"
36− "and more lines\n" ++
36+ , "and more lines"
37− "and again</literallayout>"
37+ , "and again</literallayout>"
38+ ]
38
39
39tests :: [Test]
40tests :: [Test]
40tests = [ testGroup "line blocks"
41tests = [ testGroup "line blocks"
41 [ "none" =: para "This is a test"
42 [ "none" =: para "This is a test"
43+ =?> unlines
44+ [ "<para>"
42− =?> "<para>\n This is a test\n</para>"
45+ , " This is a test"
46+ , "</para>"
47+ ]
43 , "basic" =: lineblock
48 , "basic" =: lineblock
44− =?> lineblock_out
49+ =?> unlines lineblock_out
45 , "blockquote" =: blockQuote lineblock
50 , "blockquote" =: blockQuote lineblock
51+ =?> unlines
52+ ( [ "<blockquote>" ] ++
46− =?> ("<blockquote>\n" ++ lineblock_out ++ "\n</blockquote>")
53+ lineblock_out ++
54+ [ "</blockquote>" ]
55+ )
47− , "footnote" =: para ("This is a test" <> note lineblock <> " of footnotes")
56+ , "footnote" =: para ("This is a test" <>
57+ note lineblock <>
58+ " of footnotes")
59+ =?> unlines
60+ ( [ "<para>"
48− =?> ("<para>\n This is a test<footnote>\n" ++
61+ , " This is a test<footnote>" ] ++
49− lineblock_out ++
62+ lineblock_out ++
50− "\n </footnote> of footnotes\n</para>")
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+ ]
51 ]
228 ]
52 ]
229 ]
tests/writer.docbook+30−30
@@ -93,7 +93,7 @@ sub status {
93 <para>
93 <para>
94 A list:
94 A list:
95 </para>
95 </para>
96− <orderedlist numeration="arabic">
96+ <orderedlist numeration="arabic" spacing="compact">
97 <listitem>
97 <listitem>
98 <para>
98 <para>
99 item one
99 item one
@@ -156,7 +156,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
156 <para>
156 <para>
157 Asterisks tight:
157 Asterisks tight:
158 </para>
158 </para>
159− <itemizedlist>
159+ <itemizedlist spacing="compact">
160 <listitem>
160 <listitem>
161 <para>
161 <para>
162 asterisk 1
162 asterisk 1
@@ -196,7 +196,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
196 <para>
196 <para>
197 Pluses tight:
197 Pluses tight:
198 </para>
198 </para>
199− <itemizedlist>
199+ <itemizedlist spacing="compact">
200 <listitem>
200 <listitem>
201 <para>
201 <para>
202 Plus 1
202 Plus 1
@@ -236,7 +236,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
236 <para>
236 <para>
237 Minuses tight:
237 Minuses tight:
238 </para>
238 </para>
239− <itemizedlist>
239+ <itemizedlist spacing="compact">
240 <listitem>
240 <listitem>
241 <para>
241 <para>
242 Minus 1
242 Minus 1
@@ -279,7 +279,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
279 <para>
279 <para>
280 Tight:
280 Tight:
281 </para>
281 </para>
282− <orderedlist numeration="arabic">
282+ <orderedlist numeration="arabic" spacing="compact">
283 <listitem>
283 <listitem>
284 <para>
284 <para>
285 First
285 First
@@ -299,7 +299,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
299 <para>
299 <para>
300 and:
300 and:
301 </para>
301 </para>
302− <orderedlist numeration="arabic">
302+ <orderedlist numeration="arabic" spacing="compact">
303 <listitem>
303 <listitem>
304 <para>
304 <para>
305 One
305 One
@@ -383,17 +383,17 @@ These should not be escaped: \$ \\ \&gt; \[ \{
383 </sect2>
383 </sect2>
384 <sect2 id="nested">
384 <sect2 id="nested">
385 <title>Nested</title>
385 <title>Nested</title>
386− <itemizedlist>
386+ <itemizedlist spacing="compact">
387 <listitem>
387 <listitem>
388 <para>
388 <para>
389 Tab
389 Tab
390 </para>
390 </para>
391− <itemizedlist>
391+ <itemizedlist spacing="compact">
392 <listitem>
392 <listitem>
393 <para>
393 <para>
394 Tab
394 Tab
395 </para>
395 </para>
396− <itemizedlist>
396+ <itemizedlist spacing="compact">
397 <listitem>
397 <listitem>
398 <para>
398 <para>
399 Tab
399 Tab
@@ -407,7 +407,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
407 <para>
407 <para>
408 Here’s another:
408 Here’s another:
409 </para>
409 </para>
410− <orderedlist numeration="arabic">
410+ <orderedlist numeration="arabic" spacing="compact">
411 <listitem>
411 <listitem>
412 <para>
412 <para>
413 First
413 First
@@ -417,7 +417,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
417 <para>
417 <para>
418 Second:
418 Second:
419 </para>
419 </para>
420− <itemizedlist>
420+ <itemizedlist spacing="compact">
421 <listitem>
421 <listitem>
422 <para>
422 <para>
423 Fee
423 Fee
@@ -454,7 +454,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
454 <para>
454 <para>
455 Second:
455 Second:
456 </para>
456 </para>
457− <itemizedlist>
457+ <itemizedlist spacing="compact">
458 <listitem>
458 <listitem>
459 <para>
459 <para>
460 Fee
460 Fee
@@ -508,7 +508,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
508 </sect2>
508 </sect2>
509 <sect2 id="fancy-list-markers">
509 <sect2 id="fancy-list-markers">
510 <title>Fancy list markers</title>
510 <title>Fancy list markers</title>
511− <orderedlist numeration="arabic">
511+ <orderedlist numeration="arabic" spacing="compact">
512 <listitem override="2">
512 <listitem override="2">
513 <para>
513 <para>
514 begins with 2
514 begins with 2
@@ -521,7 +521,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
521 <para>
521 <para>
522 with a continuation
522 with a continuation
523 </para>
523 </para>
524− <orderedlist numeration="lowerroman">
524+ <orderedlist numeration="lowerroman" spacing="compact">
525 <listitem override="4">
525 <listitem override="4">
526 <para>
526 <para>
527 sublist with roman numerals, starting with 4
527 sublist with roman numerals, starting with 4
@@ -531,7 +531,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
531 <para>
531 <para>
532 more items
532 more items
533 </para>
533 </para>
534− <orderedlist numeration="upperalpha">
534+ <orderedlist numeration="upperalpha" spacing="compact">
535 <listitem>
535 <listitem>
536 <para>
536 <para>
537 a subsublist
537 a subsublist
@@ -550,22 +550,22 @@ These should not be escaped: \$ \\ \&gt; \[ \{
550 <para>
550 <para>
551 Nesting:
551 Nesting:
552 </para>
552 </para>
553− <orderedlist numeration="upperalpha">
553+ <orderedlist numeration="upperalpha" spacing="compact">
554 <listitem>
554 <listitem>
555 <para>
555 <para>
556 Upper Alpha
556 Upper Alpha
557 </para>
557 </para>
558− <orderedlist numeration="upperroman">
558+ <orderedlist numeration="upperroman" spacing="compact">
559 <listitem>
559 <listitem>
560 <para>
560 <para>
561 Upper Roman.
561 Upper Roman.
562 </para>
562 </para>
563− <orderedlist numeration="arabic">
563+ <orderedlist numeration="arabic" spacing="compact">
564 <listitem override="6">
564 <listitem override="6">
565 <para>
565 <para>
566 Decimal start with 6
566 Decimal start with 6
567 </para>
567 </para>
568− <orderedlist numeration="loweralpha">
568+ <orderedlist numeration="loweralpha" spacing="compact">
569 <listitem override="3">
569 <listitem override="3">
570 <para>
570 <para>
571 Lower alpha with paren
571 Lower alpha with paren
@@ -581,7 +581,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
581 <para>
581 <para>
582 Autonumbering:
582 Autonumbering:
583 </para>
583 </para>
584− <orderedlist>
584+ <orderedlist spacing="compact">
585 <listitem>
585 <listitem>
586 <para>
586 <para>
587 Autonumber.
587 Autonumber.
@@ -591,7 +591,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
591 <para>
591 <para>
592 More.
592 More.
593 </para>
593 </para>
594− <orderedlist>
594+ <orderedlist spacing="compact">
595 <listitem>
595 <listitem>
596 <para>
596 <para>
597 Nested.
597 Nested.
@@ -616,7 +616,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
616 <para>
616 <para>
617 Tight using spaces:
617 Tight using spaces:
618 </para>
618 </para>
619− <variablelist>
619+ <variablelist spacing="compact">
620 <varlistentry>
620 <varlistentry>
621 <term>
621 <term>
622 apple
622 apple
@@ -651,7 +651,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
651 <para>
651 <para>
652 Tight using tabs:
652 Tight using tabs:
653 </para>
653 </para>
654− <variablelist>
654+ <variablelist spacing="compact">
655 <varlistentry>
655 <varlistentry>
656 <term>
656 <term>
657 apple
657 apple
@@ -757,7 +757,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
757 <para>
757 <para>
758 Multiple definitions, tight:
758 Multiple definitions, tight:
759 </para>
759 </para>
760− <variablelist>
760+ <variablelist spacing="compact">
761 <varlistentry>
761 <varlistentry>
762 <term>
762 <term>
763 apple
763 apple
@@ -841,7 +841,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
841 <para>
841 <para>
842 orange fruit
842 orange fruit
843 </para>
843 </para>
844− <orderedlist numeration="arabic">
844+ <orderedlist numeration="arabic" spacing="compact">
845 <listitem>
845 <listitem>
846 <para>
846 <para>
847 sublist
847 sublist
@@ -1051,7 +1051,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
1051</sect1>
1051</sect1>
1052<sect1 id="latex">
1052<sect1 id="latex">
1053 <title>LaTeX</title>
1053 <title>LaTeX</title>
1054− <itemizedlist>
1054+ <itemizedlist spacing="compact">
1055 <listitem>
1055 <listitem>
1056 <para>
1056 <para>
1057 </para>
1057 </para>
@@ -1097,7 +1097,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
1097 <para>
1097 <para>
1098 These shouldn’t be math:
1098 These shouldn’t be math:
1099 </para>
1099 </para>
1100− <itemizedlist>
1100+ <itemizedlist spacing="compact">
1101 <listitem>
1101 <listitem>
1102 <para>
1102 <para>
1103 To get the famous equation, write <literal>$e = mc^2$</literal>.
1103 To get the famous equation, write <literal>$e = mc^2$</literal>.
@@ -1130,7 +1130,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
1130 <para>
1130 <para>
1131 Here is some unicode:
1131 Here is some unicode:
1132 </para>
1132 </para>
1133− <itemizedlist>
1133+ <itemizedlist spacing="compact">
1134 <listitem>
1134 <listitem>
1135 <para>
1135 <para>
1136 I hat: Î
1136 I hat: Î
@@ -1316,7 +1316,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
1316 With an ampersand:
1316 With an ampersand:
1317 <ulink url="http://example.com/?foo=1&amp;bar=2">http://example.com/?foo=1&amp;bar=2</ulink>
1317 <ulink url="http://example.com/?foo=1&amp;bar=2">http://example.com/?foo=1&amp;bar=2</ulink>
1318 </para>
1318 </para>
1319− <itemizedlist>
1319+ <itemizedlist spacing="compact">
1320 <listitem>
1320 <listitem>
1321 <para>
1321 <para>
1322 In a list?
1322 In a list?
@@ -1414,7 +1414,7 @@ or here: &lt;http://example.com/&gt;
1414 </footnote>
1414 </footnote>
1415 </para>
1415 </para>
1416 </blockquote>
1416 </blockquote>
1417− <orderedlist numeration="arabic">
1417+ <orderedlist numeration="arabic" spacing="compact">
1418 <listitem>
1418 <listitem>
1419 <para>
1419 <para>
1420 And in list items.<footnote>
1420 And in list items.<footnote>