From a496979c6d0eb3e6efd57264cb89d4aad1f7afdb Mon Sep 17 00:00:00 2001 From: Alexander Krotov Date: Tue, 31 Oct 2017 20:16:22 +0300 Subject: FB2 writer: write blocks outside of

in definitions --- src/Text/Pandoc/Writers/FB2.hs | 20 ++---------- test/writer.fb2 | 70 ++++++++++++++++++++++-------------------- 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 @@

apple

-

    red fruit -

+

    red fruit

orange

-

    orange fruit -

+

    orange fruit

banana

-

    yellow fruit -

+

    yellow fruit

Tight using tabs:

apple

-

    red fruit -

+

    red fruit

orange

-

    orange fruit -

+

    orange fruit

banana

-

    yellow fruit -

+

    yellow fruit

Loose:

apple

-

    red fruit -

+

    red fruit

+

orange

-

    orange fruit -

+

    orange fruit

+

banana

-

    yellow fruit -

+

    yellow fruit

+

Multiple blocks with italics:

apple

-

    red fruit    contains seeds, crisp, pleasant to taste -

+

    red fruit

+ +

    contains seeds, crisp, pleasant to taste

+

orange

-

    orange fruit +

    orange fruit

+

    { orange code block } @@ -398,42 +395,47 @@

    orange block quote

-

Multiple definitions, tight:

apple

-

    red fruit    computer -

+

    red fruit

+

    computer

orange

-

    orange fruit    bank -

+

    orange fruit

+

    bank

Multiple definitions, loose:

apple

-

    red fruit    computer -

+

    red fruit

+ +

    computer

+

orange

-

    orange fruit    bank -

+

    orange fruit

+ +

    bank

+

Blank line after term, indented marker, alternate markers:

apple

-

    red fruit    computer -

+

    red fruit

+ +

    computer

+

orange

-

    orange fruit +

    orange fruit

+

1. sublist

2. sublist

-

-- cgit v1.2.3