FB2 writer: write blocks outside of <p> in definitions

This commit is contained in:
Alexander Krotov 2017-10-31 20:16:22 +03:00
parent 3eaa6ff329
commit a496979c6d
2 changed files with 38 additions and 52 deletions

View file

@ -362,17 +362,9 @@ blockToXml (DefinitionList defs) =
cMapM mkdef defs
where
mkdef (term, bss) = do
def' <- cMapM (cMapM blockToXml . sep . paraToPlain . map indent) bss
items <- cMapM (cMapM blockToXml . plainToPara . indentBlocks (replicate 4 ' ')) bss
t <- wrap "strong" term
return [ el "p" t, el "p" def' ]
sep blocks =
if all needsBreak blocks then
blocks ++ [Plain [LineBreak]]
else
blocks
needsBreak (Para _) = False
needsBreak (Plain ins) = LineBreak `notElem` ins
needsBreak _ = True
return (el "p" t : items)
blockToXml h@Header{} = do
-- should not occur after hierarchicalize, except inside lists/blockquotes
report $ BlockNotRendered h
@ -403,14 +395,6 @@ blockToXml (Table caption aligns _ headers rows) = do
align_str AlignDefault = "left"
blockToXml Null = return []
-- Replace paragraphs with plain text and line break.
-- Necessary to simulate multi-paragraph lists in FB2.
paraToPlain :: [Block] -> [Block]
paraToPlain [] = []
paraToPlain (Para inlines : rest) =
Plain inlines : Plain [LineBreak] : paraToPlain rest
paraToPlain (p:rest) = p : paraToPlain rest
-- Replace plain text with paragraphs and add line break after paragraphs.
-- It is used to convert plain text from tight list items to paragraphs.
plainToPara :: [Block] -> [Block]

View file

@ -332,64 +332,61 @@
<p>
<strong>apple</strong>
</p>
<p>    red fruit<empty-line />
</p>
<p>    red fruit</p>
<p>
<strong>orange</strong>
</p>
<p>    orange fruit<empty-line />
</p>
<p>    orange fruit</p>
<p>
<strong>banana</strong>
</p>
<p>    yellow fruit<empty-line />
</p>
<p>    yellow fruit</p>
<p>Tight using tabs:</p>
<p>
<strong>apple</strong>
</p>
<p>    red fruit<empty-line />
</p>
<p>    red fruit</p>
<p>
<strong>orange</strong>
</p>
<p>    orange fruit<empty-line />
</p>
<p>    orange fruit</p>
<p>
<strong>banana</strong>
</p>
<p>    yellow fruit<empty-line />
</p>
<p>    yellow fruit</p>
<p>Loose:</p>
<p>
<strong>apple</strong>
</p>
<p>    red fruit<empty-line />
</p>
<p>    red fruit</p>
<empty-line />
<p>
<strong>orange</strong>
</p>
<p>    orange fruit<empty-line />
</p>
<p>    orange fruit</p>
<empty-line />
<p>
<strong>banana</strong>
</p>
<p>    yellow fruit<empty-line />
</p>
<p>    yellow fruit</p>
<empty-line />
<p>Multiple blocks with italics:</p>
<p>
<strong>
<emphasis>apple</emphasis>
</strong>
</p>
<p>    red fruit<empty-line />    contains seeds, crisp, pleasant to taste<empty-line />
</p>
<p>    red fruit</p>
<empty-line />
<p>    contains seeds, crisp, pleasant to taste</p>
<empty-line />
<p>
<strong>
<emphasis>orange</emphasis>
</strong>
</p>
<p>    orange fruit<empty-line />
<p>    orange fruit</p>
<empty-line />
<empty-line />
<p>
<code>    { orange code block }</code>
@ -398,42 +395,47 @@
<cite>
<p>    orange block quote</p>
</cite>
</p>
<p>Multiple definitions, tight:</p>
<p>
<strong>apple</strong>
</p>
<p>    red fruit<empty-line />    computer<empty-line />
</p>
<p>    red fruit</p>
<p>    computer</p>
<p>
<strong>orange</strong>
</p>
<p>    orange fruit<empty-line />    bank<empty-line />
</p>
<p>    orange fruit</p>
<p>    bank</p>
<p>Multiple definitions, loose:</p>
<p>
<strong>apple</strong>
</p>
<p>    red fruit<empty-line />    computer<empty-line />
</p>
<p>    red fruit</p>
<empty-line />
<p>    computer</p>
<empty-line />
<p>
<strong>orange</strong>
</p>
<p>    orange fruit<empty-line />    bank<empty-line />
</p>
<p>    orange fruit</p>
<empty-line />
<p>    bank</p>
<empty-line />
<p>Blank line after term, indented marker, alternate markers:</p>
<p>
<strong>apple</strong>
</p>
<p>    red fruit<empty-line />    computer<empty-line />
</p>
<p>    red fruit</p>
<empty-line />
<p>    computer</p>
<empty-line />
<p>
<strong>orange</strong>
</p>
<p>    orange fruit<empty-line />
<p>    orange fruit</p>
<empty-line />
<p>1. sublist</p>
<p>2. sublist</p>
</p>
</section>
<section>
<title>