Distinguish tight and loose lists in Docbook output

Determined by the first block of the first item being Plain.
This commit is contained in:
Neil Mayhew 2014-04-14 19:07:14 -06:00 committed by John MacFarlane
parent 2ba7873086
commit ccbf4fc9c2
3 changed files with 236 additions and 49 deletions

View file

@ -185,10 +185,13 @@ blockToDocbook _ (CodeBlock (_,classes,_) str) =
else languagesByExtension . map toLower $ s
langs = concatMap langsFrom classes
blockToDocbook opts (BulletList lst) =
inTagsIndented "itemizedlist" $ listItemsToDocbook opts lst
let attribs = case lst of
((Plain _:_):_) -> [("spacing", "compact")]
_ -> []
in inTags True "itemizedlist" attribs $ listItemsToDocbook opts lst
blockToDocbook _ (OrderedList _ []) = empty
blockToDocbook opts (OrderedList (start, numstyle, _) (first:rest)) =
let attribs = case numstyle of
let numeration = case numstyle of
DefaultStyle -> []
Decimal -> [("numeration", "arabic")]
Example -> [("numeration", "arabic")]
@ -196,14 +199,21 @@ blockToDocbook opts (OrderedList (start, numstyle, _) (first:rest)) =
LowerAlpha -> [("numeration", "loweralpha")]
UpperRoman -> [("numeration", "upperroman")]
LowerRoman -> [("numeration", "lowerroman")]
items = if start == 1
then listItemsToDocbook opts (first:rest)
else (inTags True "listitem" [("override",show start)]
(blocksToDocbook opts $ map plainToPara first)) $$
listItemsToDocbook opts rest
spacing = case first of
(Plain _:_) -> [("spacing", "compact")]
_ -> []
attribs = numeration ++ spacing
items = if start == 1
then listItemsToDocbook opts (first:rest)
else (inTags True "listitem" [("override",show start)]
(blocksToDocbook opts $ map plainToPara first)) $$
listItemsToDocbook opts rest
in inTags True "orderedlist" attribs items
blockToDocbook opts (DefinitionList lst) =
inTagsIndented "variablelist" $ deflistItemsToDocbook opts lst
let attribs = case lst of
((_, (Plain _:_):_):_) -> [("spacing", "compact")]
_ -> []
in inTags True "variablelist" attribs $ deflistItemsToDocbook opts lst
blockToDocbook _ (RawBlock f str)
| f == "docbook" = text str -- raw XML block
| f == "html" = text str -- allow html for backwards compatibility

View file

@ -31,22 +31,199 @@ lineblock :: Blocks
lineblock = para ("some text" <> linebreak <>
"and more lines" <> linebreak <>
"and again")
lineblock_out :: String
lineblock_out = "<literallayout>some text\n" ++
"and more lines\n" ++
"and again</literallayout>"
lineblock_out :: [String]
lineblock_out = [ "<literallayout>some text"
, "and more lines"
, "and again</literallayout>"
]
tests :: [Test]
tests = [ testGroup "line blocks"
[ "none" =: para "This is a test"
=?> "<para>\n This is a test\n</para>"
=?> unlines
[ "<para>"
, " This is a test"
, "</para>"
]
, "basic" =: lineblock
=?> lineblock_out
=?> unlines lineblock_out
, "blockquote" =: blockQuote lineblock
=?> ("<blockquote>\n" ++ lineblock_out ++ "\n</blockquote>")
, "footnote" =: para ("This is a test" <> note lineblock <> " of footnotes")
=?> ("<para>\n This is a test<footnote>\n" ++
lineblock_out ++
"\n </footnote> of footnotes\n</para>")
=?> unlines
( [ "<blockquote>" ] ++
lineblock_out ++
[ "</blockquote>" ]
)
, "footnote" =: para ("This is a test" <>
note lineblock <>
" of footnotes")
=?> unlines
( [ "<para>"
, " This is a test<footnote>" ] ++
lineblock_out ++
[ " </footnote> of footnotes"
, "</para>" ]
)
]
, testGroup "compact lists"
[ testGroup "bullet"
[ "compact" =: bulletList [plain "a", plain "b", plain "c"]
=?> unlines
[ "<itemizedlist spacing=\"compact\">"
, " <listitem>"
, " <para>"
, " a"
, " </para>"
, " </listitem>"
, " <listitem>"
, " <para>"
, " b"
, " </para>"
, " </listitem>"
, " <listitem>"
, " <para>"
, " c"
, " </para>"
, " </listitem>"
, "</itemizedlist>"
]
, "loose" =: bulletList [para "a", para "b", para "c"]
=?> unlines
[ "<itemizedlist>"
, " <listitem>"
, " <para>"
, " a"
, " </para>"
, " </listitem>"
, " <listitem>"
, " <para>"
, " b"
, " </para>"
, " </listitem>"
, " <listitem>"
, " <para>"
, " c"
, " </para>"
, " </listitem>"
, "</itemizedlist>"
]
]
, testGroup "ordered"
[ "compact" =: orderedList [plain "a", plain "b", plain "c"]
=?> unlines
[ "<orderedlist spacing=\"compact\">"
, " <listitem>"
, " <para>"
, " a"
, " </para>"
, " </listitem>"
, " <listitem>"
, " <para>"
, " b"
, " </para>"
, " </listitem>"
, " <listitem>"
, " <para>"
, " c"
, " </para>"
, " </listitem>"
, "</orderedlist>"
]
, "loose" =: orderedList [para "a", para "b", para "c"]
=?> unlines
[ "<orderedlist>"
, " <listitem>"
, " <para>"
, " a"
, " </para>"
, " </listitem>"
, " <listitem>"
, " <para>"
, " b"
, " </para>"
, " </listitem>"
, " <listitem>"
, " <para>"
, " c"
, " </para>"
, " </listitem>"
, "</orderedlist>"
]
]
, testGroup "definition"
[ "compact" =: definitionList [ ("an", [plain "apple" ])
, ("a", [plain "banana"])
, ("an", [plain "orange"])]
=?> unlines
[ "<variablelist spacing=\"compact\">"
, " <varlistentry>"
, " <term>"
, " an"
, " </term>"
, " <listitem>"
, " <para>"
, " apple"
, " </para>"
, " </listitem>"
, " </varlistentry>"
, " <varlistentry>"
, " <term>"
, " a"
, " </term>"
, " <listitem>"
, " <para>"
, " banana"
, " </para>"
, " </listitem>"
, " </varlistentry>"
, " <varlistentry>"
, " <term>"
, " an"
, " </term>"
, " <listitem>"
, " <para>"
, " orange"
, " </para>"
, " </listitem>"
, " </varlistentry>"
, "</variablelist>"
]
, "loose" =: definitionList [ ("an", [para "apple" ])
, ("a", [para "banana"])
, ("an", [para "orange"])]
=?> unlines
[ "<variablelist>"
, " <varlistentry>"
, " <term>"
, " an"
, " </term>"
, " <listitem>"
, " <para>"
, " apple"
, " </para>"
, " </listitem>"
, " </varlistentry>"
, " <varlistentry>"
, " <term>"
, " a"
, " </term>"
, " <listitem>"
, " <para>"
, " banana"
, " </para>"
, " </listitem>"
, " </varlistentry>"
, " <varlistentry>"
, " <term>"
, " an"
, " </term>"
, " <listitem>"
, " <para>"
, " orange"
, " </para>"
, " </listitem>"
, " </varlistentry>"
, "</variablelist>"
]
]
]
]

View file

@ -93,7 +93,7 @@ sub status {
<para>
A list:
</para>
<orderedlist numeration="arabic">
<orderedlist numeration="arabic" spacing="compact">
<listitem>
<para>
item one
@ -156,7 +156,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
<para>
Asterisks tight:
</para>
<itemizedlist>
<itemizedlist spacing="compact">
<listitem>
<para>
asterisk 1
@ -196,7 +196,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
<para>
Pluses tight:
</para>
<itemizedlist>
<itemizedlist spacing="compact">
<listitem>
<para>
Plus 1
@ -236,7 +236,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
<para>
Minuses tight:
</para>
<itemizedlist>
<itemizedlist spacing="compact">
<listitem>
<para>
Minus 1
@ -279,7 +279,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
<para>
Tight:
</para>
<orderedlist numeration="arabic">
<orderedlist numeration="arabic" spacing="compact">
<listitem>
<para>
First
@ -299,7 +299,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
<para>
and:
</para>
<orderedlist numeration="arabic">
<orderedlist numeration="arabic" spacing="compact">
<listitem>
<para>
One
@ -383,17 +383,17 @@ These should not be escaped: \$ \\ \&gt; \[ \{
</sect2>
<sect2 id="nested">
<title>Nested</title>
<itemizedlist>
<itemizedlist spacing="compact">
<listitem>
<para>
Tab
</para>
<itemizedlist>
<itemizedlist spacing="compact">
<listitem>
<para>
Tab
</para>
<itemizedlist>
<itemizedlist spacing="compact">
<listitem>
<para>
Tab
@ -407,7 +407,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
<para>
Heres another:
</para>
<orderedlist numeration="arabic">
<orderedlist numeration="arabic" spacing="compact">
<listitem>
<para>
First
@ -417,7 +417,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
<para>
Second:
</para>
<itemizedlist>
<itemizedlist spacing="compact">
<listitem>
<para>
Fee
@ -454,7 +454,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
<para>
Second:
</para>
<itemizedlist>
<itemizedlist spacing="compact">
<listitem>
<para>
Fee
@ -508,7 +508,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
</sect2>
<sect2 id="fancy-list-markers">
<title>Fancy list markers</title>
<orderedlist numeration="arabic">
<orderedlist numeration="arabic" spacing="compact">
<listitem override="2">
<para>
begins with 2
@ -521,7 +521,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
<para>
with a continuation
</para>
<orderedlist numeration="lowerroman">
<orderedlist numeration="lowerroman" spacing="compact">
<listitem override="4">
<para>
sublist with roman numerals, starting with 4
@ -531,7 +531,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
<para>
more items
</para>
<orderedlist numeration="upperalpha">
<orderedlist numeration="upperalpha" spacing="compact">
<listitem>
<para>
a subsublist
@ -550,22 +550,22 @@ These should not be escaped: \$ \\ \&gt; \[ \{
<para>
Nesting:
</para>
<orderedlist numeration="upperalpha">
<orderedlist numeration="upperalpha" spacing="compact">
<listitem>
<para>
Upper Alpha
</para>
<orderedlist numeration="upperroman">
<orderedlist numeration="upperroman" spacing="compact">
<listitem>
<para>
Upper Roman.
</para>
<orderedlist numeration="arabic">
<orderedlist numeration="arabic" spacing="compact">
<listitem override="6">
<para>
Decimal start with 6
</para>
<orderedlist numeration="loweralpha">
<orderedlist numeration="loweralpha" spacing="compact">
<listitem override="3">
<para>
Lower alpha with paren
@ -581,7 +581,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
<para>
Autonumbering:
</para>
<orderedlist>
<orderedlist spacing="compact">
<listitem>
<para>
Autonumber.
@ -591,7 +591,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
<para>
More.
</para>
<orderedlist>
<orderedlist spacing="compact">
<listitem>
<para>
Nested.
@ -616,7 +616,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
<para>
Tight using spaces:
</para>
<variablelist>
<variablelist spacing="compact">
<varlistentry>
<term>
apple
@ -651,7 +651,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
<para>
Tight using tabs:
</para>
<variablelist>
<variablelist spacing="compact">
<varlistentry>
<term>
apple
@ -757,7 +757,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
<para>
Multiple definitions, tight:
</para>
<variablelist>
<variablelist spacing="compact">
<varlistentry>
<term>
apple
@ -841,7 +841,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
<para>
orange fruit
</para>
<orderedlist numeration="arabic">
<orderedlist numeration="arabic" spacing="compact">
<listitem>
<para>
sublist
@ -1051,7 +1051,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
</sect1>
<sect1 id="latex">
<title>LaTeX</title>
<itemizedlist>
<itemizedlist spacing="compact">
<listitem>
<para>
</para>
@ -1097,7 +1097,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
<para>
These shouldnt be math:
</para>
<itemizedlist>
<itemizedlist spacing="compact">
<listitem>
<para>
To get the famous equation, write <literal>$e = mc^2$</literal>.
@ -1130,7 +1130,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
<para>
Here is some unicode:
</para>
<itemizedlist>
<itemizedlist spacing="compact">
<listitem>
<para>
I hat: Î
@ -1316,7 +1316,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
With an ampersand:
<ulink url="http://example.com/?foo=1&amp;bar=2">http://example.com/?foo=1&amp;bar=2</ulink>
</para>
<itemizedlist>
<itemizedlist spacing="compact">
<listitem>
<para>
In a list?
@ -1414,7 +1414,7 @@ or here: &lt;http://example.com/&gt;
</footnote>
</para>
</blockquote>
<orderedlist numeration="arabic">
<orderedlist numeration="arabic" spacing="compact">
<listitem>
<para>
And in list items.<footnote>