summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Krotov <ilabdsf@gmail.com>2017-10-31 20:16:22 +0300
committerAlexander Krotov <ilabdsf@gmail.com>2017-10-31 20:19:00 +0300
commita496979c6d0eb3e6efd57264cb89d4aad1f7afdb (patch)
tree04d3423c1a2ebd1b44664e7c3254294e77b7abb0
parent3eaa6ff329b079387d70449a8236d1b83b95e3bf (diff)
FB2 writer: write blocks outside of <p> in definitions
-rw-r--r--src/Text/Pandoc/Writers/FB2.hs20
-rw-r--r--test/writer.fb270
2 files changed, 38 insertions, 52 deletions
diff --git a/src/Text/Pandoc/Writers/FB2.hs b/src/Text/Pandoc/Writers/FB2.hs
index cf96393ca..0a8ae17bb 100644
--- a/src/Text/Pandoc/Writers/FB2.hs
+++ b/src/Text/Pandoc/Writers/FB2.hs
@@ -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]
diff --git a/test/writer.fb2 b/test/writer.fb2
index 8a4986508..d25ce1f62 100644
--- a/test/writer.fb2
+++ b/test/writer.fb2
@@ -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>