git.iko.soy/typeable/pandoc
on master help sign in
FB2 writer: write blocks outside of <p> in definitions
commita496979c6d0eb3e6efd57264cb89d4aad1f7afdb authorAlexander Krotov <ilabdsf@gmail.com> dateTue 31 Oct 2017, 20:16 (9 years ago) parent3eaa6ff
2 files changed+38−52
src/Text/Pandoc/Writers/FB2.hs+2−18 test/writer.fb2+36−34
src/Text/Pandoc/Writers/FB2.hs+2−18
@@ -362,17 +362,9 @@ blockToXml (DefinitionList defs) =
362362 cMapM mkdef defs
363363 where
364364 mkdef (term, bss) = do
365− def' <- cMapM (cMapM blockToXml . sep . paraToPlain . map indent) bss
365+ items <- cMapM (cMapM blockToXml . plainToPara . indentBlocks (replicate 4 ' ')) bss
366366 t <- wrap "strong" term
367− return [ el "p" t, el "p" def' ]
368− sep blocks =
369− if all needsBreak blocks then
370− blocks ++ [Plain [LineBreak]]
371− else
372− blocks
373− needsBreak (Para _) = False
374− needsBreak (Plain ins) = LineBreak `notElem` ins
375− needsBreak _ = True
367+ return (el "p" t : items)
376368blockToXml h@Header{} = do
377369 -- should not occur after hierarchicalize, except inside lists/blockquotes
378370 report $ BlockNotRendered h
@@ -403,14 +395,6 @@ blockToXml (Table caption aligns _ headers rows) = do
403395 align_str AlignDefault = "left"
404396blockToXml Null = return []
405397
406−-- Replace paragraphs with plain text and line break.
407−-- Necessary to simulate multi-paragraph lists in FB2.
408−paraToPlain :: [Block] -> [Block]
409−paraToPlain [] = []
410−paraToPlain (Para inlines : rest) =
411− Plain inlines : Plain [LineBreak] : paraToPlain rest
412−paraToPlain (p:rest) = p : paraToPlain rest
413−
414398-- Replace plain text with paragraphs and add line break after paragraphs.
415399-- It is used to convert plain text from tight list items to paragraphs.
416400plainToPara :: [Block] -> [Block]
test/writer.fb2+36−34
@@ -332,64 +332,61 @@
332332<p>
333333<strong>apple</strong>
334334</p>
335−<p>    red fruit<empty-line />
336−</p>
335+<p>    red fruit</p>
337336<p>
338337<strong>orange</strong>
339338</p>
340−<p>    orange fruit<empty-line />
341−</p>
339+<p>    orange fruit</p>
342340<p>
343341<strong>banana</strong>
344342</p>
345−<p>    yellow fruit<empty-line />
346−</p>
343+<p>    yellow fruit</p>
347344<p>Tight using tabs:</p>
348345<p>
349346<strong>apple</strong>
350347</p>
351−<p>    red fruit<empty-line />
352−</p>
348+<p>    red fruit</p>
353349<p>
354350<strong>orange</strong>
355351</p>
356−<p>    orange fruit<empty-line />
357−</p>
352+<p>    orange fruit</p>
358353<p>
359354<strong>banana</strong>
360355</p>
361−<p>    yellow fruit<empty-line />
362−</p>
356+<p>    yellow fruit</p>
363357<p>Loose:</p>
364358<p>
365359<strong>apple</strong>
366360</p>
367−<p>    red fruit<empty-line />
368−</p>
361+<p>    red fruit</p>
362+<empty-line />
369363<p>
370364<strong>orange</strong>
371365</p>
372−<p>    orange fruit<empty-line />
373−</p>
366+<p>    orange fruit</p>
367+<empty-line />
374368<p>
375369<strong>banana</strong>
376370</p>
377−<p>    yellow fruit<empty-line />
378−</p>
371+<p>    yellow fruit</p>
372+<empty-line />
379373<p>Multiple blocks with italics:</p>
380374<p>
381375<strong>
382376<emphasis>apple</emphasis>
383377</strong>
384378</p>
385−<p>    red fruit<empty-line />    contains seeds, crisp, pleasant to taste<empty-line />
386−</p>
379+<p>    red fruit</p>
380+<empty-line />
381+<p>    contains seeds, crisp, pleasant to taste</p>
382+<empty-line />
387383<p>
388384<strong>
389385<emphasis>orange</emphasis>
390386</strong>
391387</p>
392−<p>    orange fruit<empty-line />
388+<p>    orange fruit</p>
389+<empty-line />
393390<empty-line />
394391<p>
395392<code>    { orange code block }</code>
@@ -398,42 +395,47 @@
398395<cite>
399396<p>    orange block quote</p>
400397</cite>
401−</p>
402398<p>Multiple definitions, tight:</p>
403399<p>
404400<strong>apple</strong>
405401</p>
406−<p>    red fruit<empty-line />    computer<empty-line />
407−</p>
402+<p>    red fruit</p>
403+<p>    computer</p>
408404<p>
409405<strong>orange</strong>
410406</p>
411−<p>    orange fruit<empty-line />    bank<empty-line />
412−</p>
407+<p>    orange fruit</p>
408+<p>    bank</p>
413409<p>Multiple definitions, loose:</p>
414410<p>
415411<strong>apple</strong>
416412</p>
417−<p>    red fruit<empty-line />    computer<empty-line />
418−</p>
413+<p>    red fruit</p>
414+<empty-line />
415+<p>    computer</p>
416+<empty-line />
419417<p>
420418<strong>orange</strong>
421419</p>
422−<p>    orange fruit<empty-line />    bank<empty-line />
423−</p>
420+<p>    orange fruit</p>
421+<empty-line />
422+<p>    bank</p>
423+<empty-line />
424424<p>Blank line after term, indented marker, alternate markers:</p>
425425<p>
426426<strong>apple</strong>
427427</p>
428−<p>    red fruit<empty-line />    computer<empty-line />
429−</p>
428+<p>    red fruit</p>
429+<empty-line />
430+<p>    computer</p>
431+<empty-line />
430432<p>
431433<strong>orange</strong>
432434</p>
433−<p>    orange fruit<empty-line />
435+<p>    orange fruit</p>
436+<empty-line />
434437<p>1. sublist</p>
435438<p>2. sublist</p>
436−</p>
437439</section>
438440<section>
439441<title>