From 0ebe65e651766a2b3d006d3dee4afdfd43a386d5 Mon Sep 17 00:00:00 2001 From: Emily Bourke Date: Wed, 8 Sep 2021 14:05:22 +0100 Subject: pptx: Fix logic for choosing Comparison layout There was a mistake in the logic used to choose between the Comparison and Two Content layouts: if one column contained only non-text (an image or a table) and the other contained only text, the Comparison layout was chosen instead of the desired Two Content layout. This commit fixes that logic: > If either column contains text followed by non-text, use Comparison. Otherwise, use Two Content. It also adds a test asserting this behaviour. --- pandoc.cabal | 6 ++++-- src/Text/Pandoc/Writers/Powerpoint/Presentation.hs | 9 +++++---- test/Tests/Writers/Powerpoint.hs | 8 ++++++-- test/pptx/two-column/all-text/deleted-layouts.pptx | Bin 0 -> 30568 bytes test/pptx/two-column/all-text/input.native | 9 +++++++++ test/pptx/two-column/all-text/moved-layouts.pptx | Bin 0 -> 41256 bytes test/pptx/two-column/all-text/output.pptx | Bin 0 -> 27689 bytes test/pptx/two-column/all-text/templated.pptx | Bin 0 -> 40756 bytes test/pptx/two-column/deleted-layouts.pptx | Bin 30568 -> 0 bytes test/pptx/two-column/input.native | 9 --------- test/pptx/two-column/moved-layouts.pptx | Bin 41256 -> 0 bytes test/pptx/two-column/output.pptx | Bin 27689 -> 0 bytes test/pptx/two-column/templated.pptx | Bin 40756 -> 0 bytes .../pptx/two-column/text-and-image/deleted-layouts.pptx | Bin 0 -> 48392 bytes test/pptx/two-column/text-and-image/input.native | 12 ++++++++++++ test/pptx/two-column/text-and-image/moved-layouts.pptx | Bin 0 -> 59086 bytes test/pptx/two-column/text-and-image/output.pptx | Bin 0 -> 45520 bytes test/pptx/two-column/text-and-image/templated.pptx | Bin 0 -> 58586 bytes 18 files changed, 36 insertions(+), 17 deletions(-) create mode 100644 test/pptx/two-column/all-text/deleted-layouts.pptx create mode 100644 test/pptx/two-column/all-text/input.native create mode 100644 test/pptx/two-column/all-text/moved-layouts.pptx create mode 100644 test/pptx/two-column/all-text/output.pptx create mode 100644 test/pptx/two-column/all-text/templated.pptx delete mode 100644 test/pptx/two-column/deleted-layouts.pptx delete mode 100644 test/pptx/two-column/input.native delete mode 100644 test/pptx/two-column/moved-layouts.pptx delete mode 100644 test/pptx/two-column/output.pptx delete mode 100644 test/pptx/two-column/templated.pptx create mode 100644 test/pptx/two-column/text-and-image/deleted-layouts.pptx create mode 100644 test/pptx/two-column/text-and-image/input.native create mode 100644 test/pptx/two-column/text-and-image/moved-layouts.pptx create mode 100644 test/pptx/two-column/text-and-image/output.pptx create mode 100644 test/pptx/two-column/text-and-image/templated.pptx diff --git a/pandoc.cabal b/pandoc.cabal index 3de7da39c..347c33d51 100644 --- a/pandoc.cabal +++ b/pandoc.cabal @@ -446,8 +446,10 @@ extra-source-files: test/pptx/start-numbering-at/*.pptx test/pptx/tables/input.native test/pptx/tables/*.pptx - test/pptx/two-column/input.native - test/pptx/two-column/*.pptx + test/pptx/two-column/all-text/input.native + test/pptx/two-column/all-text/*.pptx + test/pptx/two-column/text-and-image/input.native + test/pptx/two-column/text-and-image/*.pptx test/ipynb/*.in.native test/ipynb/*.out.native test/ipynb/*.ipynb diff --git a/src/Text/Pandoc/Writers/Powerpoint/Presentation.hs b/src/Text/Pandoc/Writers/Powerpoint/Presentation.hs index 10060d975..015e2cbdd 100644 --- a/src/Text/Pandoc/Writers/Powerpoint/Presentation.hs +++ b/src/Text/Pandoc/Writers/Powerpoint/Presentation.hs @@ -696,10 +696,11 @@ bodyBlocksToSlide _ (blk : blks) spkNotes sldId (ComparisonSlide [] (shapesL1, shapesL2) (shapesR1, shapesR2)) spkNotes - case (break notText blksL, break notText blksR) of - ((_, []), (_, [])) -> mkTwoColumn blksL blksR - (([], _), ([], _)) -> mkTwoColumn blksL blksR - ((blksL1, blksL2), (blksR1, blksR2)) -> mkComparison blksL1 blksL2 blksR1 blksR2 + let (blksL1, blksL2) = break notText blksL + (blksR1, blksR2) = break notText blksR + if (any null [blksL1, blksL2]) && (any null [blksR1, blksR2]) + then mkTwoColumn blksL blksR + else mkComparison blksL1 blksL2 blksR1 blksR2 bodyBlocksToSlide _ (blk : blks) spkNotes = do sldId <- asks envCurSlideId inNoteSlide <- asks envInNoteSlide diff --git a/test/Tests/Writers/Powerpoint.hs b/test/Tests/Writers/Powerpoint.hs index 256ee1f7f..dd3846fef 100644 --- a/test/Tests/Writers/Powerpoint.hs +++ b/test/Tests/Writers/Powerpoint.hs @@ -103,8 +103,12 @@ tests = groupPptxTests [ pptxTests "Inline formatting" "pptx/images/output.pptx" , pptxTests "two-column layout" def - "pptx/two-column/input.native" - "pptx/two-column/output.pptx" + "pptx/two-column/all-text/input.native" + "pptx/two-column/all-text/output.pptx" + , pptxTests "two-column (not comparison)" + def + "pptx/two-column/text-and-image/input.native" + "pptx/two-column/text-and-image/output.pptx" , pptxTests "speaker notes" def "pptx/speaker-notes/input.native" diff --git a/test/pptx/two-column/all-text/deleted-layouts.pptx b/test/pptx/two-column/all-text/deleted-layouts.pptx new file mode 100644 index 000000000..1d7bd87d3 Binary files /dev/null and b/test/pptx/two-column/all-text/deleted-layouts.pptx differ diff --git a/test/pptx/two-column/all-text/input.native b/test/pptx/two-column/all-text/input.native new file mode 100644 index 000000000..086f74889 --- /dev/null +++ b/test/pptx/two-column/all-text/input.native @@ -0,0 +1,9 @@ +Pandoc (Meta {unMeta = fromList []}) +[Header 1 ("two-column-layout",[],[]) [Str "Two-Column",Space,Str "Layout"] +,Div ("",["columns"],[]) + [Div ("",["column"],[]) + [Para [Str "One",Space,Str "paragraph."] + ,Para [Str "Another",Space,Str "paragraph."]] + ,Div ("",["column"],[]) + [Para [Str "Second",Space,Str "column",Space,Str "paragraph."] + ,Para [Str "Another",Space,Str "second",Space,Str "paragraph."]]]] diff --git a/test/pptx/two-column/all-text/moved-layouts.pptx b/test/pptx/two-column/all-text/moved-layouts.pptx new file mode 100644 index 000000000..71760268c Binary files /dev/null and b/test/pptx/two-column/all-text/moved-layouts.pptx differ diff --git a/test/pptx/two-column/all-text/output.pptx b/test/pptx/two-column/all-text/output.pptx new file mode 100644 index 000000000..396dc2a74 Binary files /dev/null and b/test/pptx/two-column/all-text/output.pptx differ diff --git a/test/pptx/two-column/all-text/templated.pptx b/test/pptx/two-column/all-text/templated.pptx new file mode 100644 index 000000000..8901695b1 Binary files /dev/null and b/test/pptx/two-column/all-text/templated.pptx differ diff --git a/test/pptx/two-column/deleted-layouts.pptx b/test/pptx/two-column/deleted-layouts.pptx deleted file mode 100644 index 1d7bd87d3..000000000 Binary files a/test/pptx/two-column/deleted-layouts.pptx and /dev/null differ diff --git a/test/pptx/two-column/input.native b/test/pptx/two-column/input.native deleted file mode 100644 index 086f74889..000000000 --- a/test/pptx/two-column/input.native +++ /dev/null @@ -1,9 +0,0 @@ -Pandoc (Meta {unMeta = fromList []}) -[Header 1 ("two-column-layout",[],[]) [Str "Two-Column",Space,Str "Layout"] -,Div ("",["columns"],[]) - [Div ("",["column"],[]) - [Para [Str "One",Space,Str "paragraph."] - ,Para [Str "Another",Space,Str "paragraph."]] - ,Div ("",["column"],[]) - [Para [Str "Second",Space,Str "column",Space,Str "paragraph."] - ,Para [Str "Another",Space,Str "second",Space,Str "paragraph."]]]] diff --git a/test/pptx/two-column/moved-layouts.pptx b/test/pptx/two-column/moved-layouts.pptx deleted file mode 100644 index 71760268c..000000000 Binary files a/test/pptx/two-column/moved-layouts.pptx and /dev/null differ diff --git a/test/pptx/two-column/output.pptx b/test/pptx/two-column/output.pptx deleted file mode 100644 index 396dc2a74..000000000 Binary files a/test/pptx/two-column/output.pptx and /dev/null differ diff --git a/test/pptx/two-column/templated.pptx b/test/pptx/two-column/templated.pptx deleted file mode 100644 index 8901695b1..000000000 Binary files a/test/pptx/two-column/templated.pptx and /dev/null differ diff --git a/test/pptx/two-column/text-and-image/deleted-layouts.pptx b/test/pptx/two-column/text-and-image/deleted-layouts.pptx new file mode 100644 index 000000000..297fd6bad Binary files /dev/null and b/test/pptx/two-column/text-and-image/deleted-layouts.pptx differ diff --git a/test/pptx/two-column/text-and-image/input.native b/test/pptx/two-column/text-and-image/input.native new file mode 100644 index 000000000..796c2c7f4 --- /dev/null +++ b/test/pptx/two-column/text-and-image/input.native @@ -0,0 +1,12 @@ +[Header 1 ("slide-1",[],[]) [Str "Slide",Space,Str "1"] +,Div ("",["columns"],[]) + [Div ("",["column"],[]) + [Para [Image ("",[],[]) [Str "an",Space,Str "image"] ("lalune.jpg","fig:")]] + ,Div ("",["column"],[]) + [Para [Str "This",Space,Str "should",Space,Str "use",Space,Str "Two",Space,Str "Content,",Space,Emph [Str "not"],Space,Str "Comparison!"]]] +,Header 1 ("slide-2",[],[]) [Str "Slide",Space,Str "2"] +,Div ("",["columns"],[]) + [Div ("",["column"],[]) + [Para [Str "This",Space,Str "should",Space,Str "also",Space,Str "use",Space,Str "Two",Space,Str "Content"]] + ,Div ("",["column"],[]) + [Para [Image ("",[],[]) [Str "an",Space,Str "image"] ("lalune.jpg","fig:")]]]] diff --git a/test/pptx/two-column/text-and-image/moved-layouts.pptx b/test/pptx/two-column/text-and-image/moved-layouts.pptx new file mode 100644 index 000000000..c9a6e577e Binary files /dev/null and b/test/pptx/two-column/text-and-image/moved-layouts.pptx differ diff --git a/test/pptx/two-column/text-and-image/output.pptx b/test/pptx/two-column/text-and-image/output.pptx new file mode 100644 index 000000000..bfd532ed9 Binary files /dev/null and b/test/pptx/two-column/text-and-image/output.pptx differ diff --git a/test/pptx/two-column/text-and-image/templated.pptx b/test/pptx/two-column/text-and-image/templated.pptx new file mode 100644 index 000000000..23e6b283f Binary files /dev/null and b/test/pptx/two-column/text-and-image/templated.pptx differ -- cgit v1.2.3