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

View file

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