DocBook reader: be sensitive to spacing="compact" in lists.

When spacing="compact" is set, Para elements are turned
into Plain, so we get a "tight" list.

Closes .
This commit is contained in:
John MacFarlane 2022-01-03 14:18:25 -08:00
parent ca7a3ed5ed
commit 53699f2ab3
3 changed files with 27 additions and 41 deletions

View file

@ -843,7 +843,7 @@ parseBlock (Elem e) =
"answer" -> addToStart (strong (str "A:") <> str " ") <$> getBlocks e "answer" -> addToStart (strong (str "A:") <> str " ") <$> getBlocks e
"abstract" -> blockQuote <$> getBlocks e "abstract" -> blockQuote <$> getBlocks e
"calloutlist" -> bulletList <$> callouts "calloutlist" -> bulletList <$> callouts
"itemizedlist" -> bulletList <$> listitems "itemizedlist" -> bulletList . handleCompact <$> listitems
"orderedlist" -> do "orderedlist" -> do
let listStyle = case attrValue "numeration" e of let listStyle = case attrValue "numeration" e of
"arabic" -> Decimal "arabic" -> Decimal
@ -855,7 +855,7 @@ parseBlock (Elem e) =
let start = fromMaybe 1 $ let start = fromMaybe 1 $
filterElement (named "listitem") e filterElement (named "listitem") e
>>= safeRead . attrValue "override" >>= safeRead . attrValue "override"
orderedListWith (start,listStyle,DefaultDelim) orderedListWith (start,listStyle,DefaultDelim) . handleCompact
<$> listitems <$> listitems
"variablelist" -> definitionList <$> deflistitems "variablelist" -> definitionList <$> deflistitems
"procedure" -> bulletList <$> steps "procedure" -> bulletList <$> steps
@ -903,6 +903,14 @@ parseBlock (Elem e) =
lift $ report $ IgnoredElement name lift $ report $ IgnoredElement name
return mempty return mempty
compactSpacing = case attrValue "spacing" e of
"compact" -> True
_ -> False
handleCompact = if compactSpacing
then map (fmap paraToPlain)
else id
codeBlockWithLang = do codeBlockWithLang = do
let classes' = case attrValue "language" e of let classes' = case attrValue "language" e of
"" -> [] "" -> []
@ -1320,3 +1328,8 @@ showVerbatimCData c = showContent c
-- | Set the prefix of a name to 'Nothing' -- | Set the prefix of a name to 'Nothing'
removePrefix :: QName -> QName removePrefix :: QName -> QName
removePrefix elname = elname { qPrefix = Nothing } removePrefix elname = elname { qPrefix = Nothing }
paraToPlain :: Block -> Block
paraToPlain (Para ils) = Plain ils
paraToPlain x = x

View file

@ -194,9 +194,9 @@ These should not be escaped: \$ \\ \&gt; \[ \{
</listitem> </listitem>
</itemizedlist> </itemizedlist>
<para> <para>
Pluses loose: Asterisks tight:
</para> </para>
<itemizedlist> <itemizedlist spacing="compact">
<listitem> <listitem>
<para> <para>
Plus 1 Plus 1
@ -213,26 +213,6 @@ These should not be escaped: \$ \\ \&gt; \[ \{
</para> </para>
</listitem> </listitem>
</itemizedlist> </itemizedlist>
<para>
Minuses loose:
</para>
<itemizedlist>
<listitem>
<para>
Minus 1
</para>
</listitem>
<listitem>
<para>
Minus 2
</para>
</listitem>
<listitem>
<para>
Minus 3
</para>
</listitem>
</itemizedlist>
</sect2> </sect2>
<sect2 id="ordered"> <sect2 id="ordered">
<title>Ordered</title> <title>Ordered</title>
@ -254,9 +234,9 @@ These should not be escaped: \$ \\ \&gt; \[ \{
</listitem> </listitem>
</orderedlist> </orderedlist>
<para> <para>
and using spaces: and tight:
</para> </para>
<orderedlist numeration="arabic"> <orderedlist spacing="compact" numeration="arabic">
<listitem> <listitem>
<para> <para>
One One

View file

@ -336,17 +336,11 @@ Pandoc
, [ Para [ Str "asterisk" , Space , Str "2" ] ] , [ Para [ Str "asterisk" , Space , Str "2" ] ]
, [ Para [ Str "asterisk" , Space , Str "3" ] ] , [ Para [ Str "asterisk" , Space , Str "3" ] ]
] ]
, Para [ Str "Pluses" , Space , Str "loose:" ] , Para [ Str "Asterisks" , Space , Str "tight:" ]
, BulletList , BulletList
[ [ Para [ Str "Plus" , Space , Str "1" ] ] [ [ Plain [ Str "Plus" , Space , Str "1" ] ]
, [ Para [ Str "Plus" , Space , Str "2" ] ] , [ Plain [ Str "Plus" , Space , Str "2" ] ]
, [ Para [ Str "Plus" , Space , Str "3" ] ] , [ Plain [ Str "Plus" , Space , Str "3" ] ]
]
, Para [ Str "Minuses" , Space , Str "loose:" ]
, BulletList
[ [ Para [ Str "Minus" , Space , Str "1" ] ]
, [ Para [ Str "Minus" , Space , Str "2" ] ]
, [ Para [ Str "Minus" , Space , Str "3" ] ]
] ]
, Header 2 ( "ordered" , [] , [] ) [ Str "Ordered" ] , Header 2 ( "ordered" , [] , [] ) [ Str "Ordered" ]
, OrderedList , OrderedList
@ -355,13 +349,12 @@ Pandoc
, [ Para [ Str "Second" ] ] , [ Para [ Str "Second" ] ]
, [ Para [ Str "Third" ] ] , [ Para [ Str "Third" ] ]
] ]
, Para , Para [ Str "and" , Space , Str "tight:" ]
[ Str "and" , Space , Str "using" , Space , Str "spaces:" ]
, OrderedList , OrderedList
( 1 , Decimal , DefaultDelim ) ( 1 , Decimal , DefaultDelim )
[ [ Para [ Str "One" ] ] [ [ Plain [ Str "One" ] ]
, [ Para [ Str "Two" ] ] , [ Plain [ Str "Two" ] ]
, [ Para [ Str "Three" ] ] , [ Plain [ Str "Three" ] ]
] ]
, Para [ Str "Multiple" , Space , Str "paragraphs:" ] , Para [ Str "Multiple" , Space , Str "paragraphs:" ]
, OrderedList , OrderedList