From 94d02a6efa29ce24ddf8ebbccac29d5acabbd84f Mon Sep 17 00:00:00 2001 From: Alexander Krotov Date: Tue, 31 Oct 2017 11:33:55 +0300 Subject: FB2 writer: make bullet lists consistent with ordered lists Previously bullet lists interacted in odd way with ordered lists. For example, bullet lists nested in ordered list had incorrect indentation. Besides that, indentation with spaces is not rendered by FBReader and fbless. To avoid this problem, bullet lists are indented by appending bullets to marker just the same way it is done for ordered lists. --- src/Text/Pandoc/Writers/FB2.hs | 12 ++++-------- test/writer.fb2 | 20 ++++++++++---------- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/src/Text/Pandoc/Writers/FB2.hs b/src/Text/Pandoc/Writers/FB2.hs index cf96393ca..46913e605 100644 --- a/src/Text/Pandoc/Writers/FB2.hs +++ b/src/Text/Pandoc/Writers/FB2.hs @@ -64,7 +64,6 @@ data FbRenderState = FbRenderState { footnotes :: [ (Int, String, [Content]) ] -- ^ #, ID, text , imagesToFetch :: [ (String, String) ] -- ^ filename, URL or path , parentListMarker :: String -- ^ list marker of the parent ordered list - , parentBulletLevel :: Int -- ^ nesting level of the unordered list , writerOptions :: WriterOptions } deriving (Show) @@ -73,7 +72,7 @@ type FBM m = StateT FbRenderState m newFB :: FbRenderState newFB = FbRenderState { footnotes = [], imagesToFetch = [] - , parentListMarker = "", parentBulletLevel = 0 + , parentListMarker = "" , writerOptions = def } data ImageMode = NormalImage | InlineImage deriving (Eq) @@ -347,15 +346,12 @@ blockToXml (OrderedList a bss) = do concat <$> zipWithM mkitem markers bss blockToXml (BulletList bss) = do state <- get - let level = parentBulletLevel state let pmrk = parentListMarker state - let prefix = replicate (length pmrk) ' ' - let bullets = ["\x2022", "\x25e6", "*", "\x2043", "\x2023"] - let mrk = prefix ++ bullets !! (level `mod` length bullets) + let mrk = pmrk ++ "•" let mkitem bs = do - modify (\s -> s { parentBulletLevel = level+1 }) + modify (\s -> s { parentListMarker = mrk ++ " "}) item <- cMapM blockToXml $ plainToPara $ indentBlocks (mrk ++ " ") bs - modify (\s -> s { parentBulletLevel = level }) -- restore bullet level + modify (\s -> s { parentListMarker = pmrk }) -- old parent marker return item cMapM mkitem bss blockToXml (DefinitionList defs) = diff --git a/test/writer.fb2 b/test/writer.fb2 index 8a4986508..3b8ceef8a 100644 --- a/test/writer.fb2 +++ b/test/writer.fb2 @@ -261,23 +261,23 @@

Nested

• Tab

-

◦ Tab

-

* Tab

+

• • Tab

+

• • • Tab

Here’s another:

1. First

2. Second:

-

   • Fee

-

   • Fie

-

   • Foe

+

2. • Fee

+

2. • Fie

+

2. • Foe

3. Third

Same thing but with paragraphs:

1. First

2. Second:

-

   • Fee

-

   • Fie

-

   • Foe

+

2. • Fee

+

2. • Fie

+

2. • Foe

3. Third

@@ -289,9 +289,9 @@

• this is a list item indented with spaces

-

◦ this is an example list item indented with tabs

+

• • this is an example list item indented with tabs

-

◦ this is an example list item indented with spaces

+

• • this is an example list item indented with spaces

-- cgit v1.2.3