pptx: Fix list level numbering

In PowerPoint, the content of a top-level list is at the same level as
the content of a top-level paragraph – the only difference is that a
list style has been applied.

At the moment, the pptx writer increments the paragraph level on each
list, turning what should be top-level lists into second-level lists.

This commit changes that logic, only incrementing the paragraph level on
continuation paragraphs of lists.

- Fixes https://github.com/jgm/pandoc/issues/4828
- Fixes https://github.com/jgm/pandoc/issues/4663
This commit is contained in:
Emily Bourke 2021-09-17 16:05:06 +01:00 committed by John MacFarlane
parent 3f489bcb58
commit 8af15ab345
24 changed files with 43 additions and 14 deletions

View file

@ -429,6 +429,8 @@ extra-source-files:
test/pptx/inline-formatting/*.pptx
test/pptx/lists/input.native
test/pptx/lists/*.pptx
test/pptx/list-level/input.native
test/pptx/list-level/*.pptx
test/pptx/raw-ooxml/input.native
test/pptx/raw-ooxml/*.pptx
test/pptx/remove-empty-slides/input.native

View file

@ -500,27 +500,23 @@ blockToParagraphs (Header _ (ident, _, _) ils) = do
blockToParagraphs (BulletList blksLst) = do
pProps <- asks envParaProps
incremental <- listShouldBeIncremental
let lvl = pPropLevel pProps
local (\env -> env{ envInList = True
, envParaProps = pProps{ pPropLevel = lvl + 1
, pPropBullet = Just Bullet
, envParaProps = pProps{ pPropBullet = Just Bullet
, pPropMarginLeft = Nothing
, pPropIndent = Nothing
, pPropIncremental = incremental
}}) $
concatMapM multiParBullet blksLst
concatMapM multiParList blksLst
blockToParagraphs (OrderedList listAttr blksLst) = do
pProps <- asks envParaProps
incremental <- listShouldBeIncremental
let lvl = pPropLevel pProps
local (\env -> env{ envInList = True
, envParaProps = pProps{ pPropLevel = lvl + 1
, pPropBullet = Just (AutoNumbering listAttr)
, envParaProps = pProps{ pPropBullet = Just (AutoNumbering listAttr)
, pPropMarginLeft = Nothing
, pPropIndent = Nothing
, pPropIncremental = incremental
}}) $
concatMapM multiParBullet blksLst
concatMapM multiParList blksLst
blockToParagraphs (DefinitionList entries) = do
incremental <- listShouldBeIncremental
let go :: ([Inline], [[Block]]) -> Pres [Paragraph]
@ -545,14 +541,21 @@ blockToParagraphs blk = do
addLogMessage $ BlockNotRendered blk
return []
-- Make sure the bullet env gets turned off after the first para.
multiParBullet :: [Block] -> Pres [Paragraph]
multiParBullet [] = return []
multiParBullet (b:bs) = do
-- | Make sure the bullet env gets turned off after the first paragraph, and
-- indent any continuation paragraphs.
multiParList :: [Block] -> Pres [Paragraph]
multiParList [] = return []
multiParList (b:bs) = do
pProps <- asks envParaProps
p <- blockToParagraphs b
ps <- local (\env -> env{envParaProps = pProps{pPropBullet = Nothing}}) $
concatMapM blockToParagraphs bs
let level = pPropLevel pProps
ps <- local (\env -> env
{ envParaProps = pProps
{ pPropBullet = Nothing
, pPropLevel = level + 1
}
})
$ concatMapM blockToParagraphs bs
return $ p ++ ps
cellToParagraphs :: Alignment -> SimpleCell -> Pres [Paragraph]

View file

@ -66,6 +66,10 @@ tests = let
def
"pptx/start-numbering-at/input.native"
"pptx/start-numbering-at/output.pptx"
, pptxTests "List continuation paragraph indentation"
def
"pptx/list-level/input.native"
"pptx/list-level/output.pptx"
, pptxTests "tables"
def
"pptx/tables/input.native"

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -0,0 +1,20 @@
[Header 1 ("slide",[],[]) [Str "Slide"]
,BulletList
[[Para [Str "Top-level"]
,Para [Str "With",Space,Str "continuation",Space,Str "paragraph"]]
,[Para [Str "Then:"]
,BulletList
[[Plain [Str "nested"]]
,[Plain [Str "list"]]
,[Plain [Str "items"]]]]]
,Header 1 ("slide-1",[],[]) [Str "Slide"]
,Para [Str "Paragraph."]
,OrderedList (1,Decimal,Period)
[[Para [Str "Top-level"]
,Para [Str "Continuation"]
,OrderedList (1,Decimal,Period)
[[Para [Str "Sub-list"]
,Para [Str "With",Space,Str "Continuation"]]
,[Para [Str "(still",Space,Str "sub-list)"]]]]
,[Para [Str "(back",Space,Str "to",Space,Str "top-level)"]]]
,Para [Str "Paragraph."]]

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.