Commit graph

48 commits

Author SHA1 Message Date
John MacFarlane
808bcb5d3b Change reference.pptx to use 16:9 aspect ratio.
This is now Powerpoint's default.
2022-01-02 14:58:55 -08:00
Emily Bourke
8de261ba4e pptx: Line up continuation paragraphs
This commit changes the `marL` and `indent` values used for plain
paragraphs and numbered lists, and changes the spacing defined in the
reference doc master for bulleted lists.

For paragraphs, there is now a left-indent taken from the `otherStyle`
in the master. For numbered lists, the number is positioned where the
text would be if this were a plain paragraph, and the text is indented
to the next level. This means that continuation paragraphs line up
nicely with numbered lists.

It also /mostly/ matches the observed PowerPoint behaviour when
inserting paragraphs and numbered lists: the only difference is that
PowerPoint was using a different margin value for the first level
numbered lists – I’ve changed this to match the other levels, as I don’t
think it makes the spacing unappealing and it allows continuation
paragraphs at any level to line up.

With bulleted lists, I’m keeping the observed PowerPoint behaviour of
specifying only a level, letting `marL` and `indent` be automatically
taken from `bodyStyle`. To that end, this commit changes the `bodyStyle`
spacing in the master of the default reference doc, to:

- line up the text of the first paragraph in each bullet with any
  continuation paragraphs
- line up nested bullet markers in any continuation paragraphs with the
  first paragraph, matching lists and plain paragraphs

This does mean the continuation paragraphs still won’t line up for
anyone using their own reference doc where they haven’t matched the
`otherStyle` and `bodyStyle` indent levels, but I think people in that
situation will be able to troubleshoot.
2021-10-17 17:24:30 -07:00
Emily Bourke
8af15ab345 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
2021-10-17 17:24:30 -07:00
Emily Bourke
aa78765bf9 pptx: Remove excessive layout tests
When I added the tests for moved layouts and deleted layouts, I added
them to all tests. However, this doesn’t really give a lot more info
than having single tests, and the extra tests take up time and disk
space.

This commit removes the moved-layouts and deleted-layouts tests, in
favour of a single test for each of those scenarios.
2021-10-07 08:45:43 -07:00
John MacFarlane
b8d460eeab Powerpoint writer: consolidate text runs when possible.
This slims down the output files by avoiding unnecessary
text run elements.

Updated golden tests.
2021-10-04 12:24:12 -07:00
John MacFarlane
82d587493d Revert "Powerpoint writer: consolidate text run nodes."
This reverts commit 62f83aa486.

This was already being done, it seems.
I misidentified the problem; it is really with `Str ""` nodes.
2021-10-04 11:50:32 -07:00
John MacFarlane
62f83aa486 Powerpoint writer: consolidate text run nodes.
This should reduce the size of the generated files.
2021-10-04 11:45:01 -07:00
Emily Bourke
50adea220d pptx: Support footers in the reference doc
In PowerPoint, it’s possible to specify footers across all slides,
containing a date (optionally automatically updated to today’s date),
the slide number (optionally starting from a higher number than 1), and
static text. There’s also an option to hide the footer on the title
slide.

Before this commit, none of that footer content was pulled through from
the reference doc: this commit supports all the functionality listed
above.

There is one behaviour which may not be immediately obvious: if the
reference doc specifies a fixed date (i.e. not automatically updating),
and there’s a date specified in the metadata for the document, the
footer date is replaced by the metadata date.

- Include date, slide number, and static footer content from reference
  doc
- Respect “slide number starts from” option
- Respect “Don’t show on title slide” option
- Add tests
2021-09-18 09:55:45 -07:00
Emily Bourke
7c22c0202e pptx: Support specifying slide background images
In the reveal-js output, it’s possible to use reveal’s
`data-background-image` class on a slide’s title to specify a background
image for the slide.

With this commit, it’s possible to use `background-image` in the same
way for pptx output. Only the “stretch” mode is supported, and the
background image is centred around the slide in the image’s larger axis,
matching the observed default behaviour of PowerPoint.

- Support `background-image` per slide.
- Add tests.
- Update manual.
2021-09-16 19:45:53 -07:00
Emily Bourke
0fb6474a55 pptx: Add support for incremental lists
- Support -i option
- Support incremental/noincremental divs
- Support older block quote syntax
- Add tests

One thing not clear from the manual is what should happen when the input
uses a combination of these things. For example, what should the
following produce?

```md
::: {.incremental .nonincremental}
- are
- these
- incremental?
:::

::: incremental
::::: nonincremental
- or
- these?
:::::
:::

::: nonincremental
> - how
> - about
> - these?
:::
```

In this commit I’ve taken the following approach, matching the observed
behaviour for beamer and reveal.js output:

- if a div with both classes, incremental wins
- the innermost incremental/nonincremental div is the one which takes
  effect
- a block quote containing a list as its first element inverts whether
  the list is incremental, whether or not the quote is inside an
  incremental/non-incremental div

I’ve added some tests to verify this behaviour.

This commit closes issue #5689
(https://github.com/jgm/pandoc/issues/5689).
2021-09-15 09:13:05 -07:00
Emily Bourke
0ebe65e651 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.
2021-09-13 08:30:36 -07:00
Emily Bourke
2b98991551 pptx: Include all themes in output archive
- Accept test changes: they’re adding the second theme (for all tests
  not containing speaker notes), or changing its position in the
  XML (for the ones containing speaker notes).
2021-09-10 17:06:45 -07:00
Emily Bourke
8ec9b884f1 pptx: Fix capitalisation of notesMasterId
I don’t think this has caused any problems, but before now it’s been
"NotesMasterId", which is incorrect according to [ECMA-376].

[ECMA-376]: https://www.ecma-international.org/publications-and-standards/standards/ecma-376/
2021-09-10 17:06:45 -07:00
Emily Bourke
b82a01b688 pptx: Add support for more layouts
Until now, the pptx writer only supported four slide layouts: “Title
Slide” (used for the automatically generated metadata slide), “Section
Header” (used for headings above the slide level), “Two Column” (used
when there’s a columns div containing at least two column divs), and
“Title and Content” (used for all other slides).

This commit adds support for three more layouts: Comparison, Content
with Caption, and Blank.

- Support “Comparison” slide layout

  This layout is used when a slide contains at least two columns, at
  least one of which contains some text followed by some non-text (e.g.
  an image or table). The text in each column is inserted into the
  “body” placeholder for that column, and the non-text is inserted into
  the ObjType placeholder. Any extra content after the non-text is
  overlaid on top of the preceding content, rather than dropping it
  completely (as currently happens for the two-column layout).

  + Accept straightforward test changes

    Adding the new layout means the “-deleted-layouts” tests have an
    additional layout added to the master and master rels.

  + Add new tests for the comparison layout
  + Add new tests to pandoc.cabal

- Support “Content with Caption” slide layout

  This layout is used when a slide’s body contains some text, followed by
  non-text (e.g. and image or a table). Before now, in this case the image
  or table would break onto a new slide: to get that output again, users
  can add a horizontal rule before the image or table.

  + Accept straightforward tests

    The “-deleted-layouts” tests all have an extra layout and relationship
    in the master for the Content with Caption layout.

  + Accept remove-empty-slides test

    Empty slides are still removed, but the Content with Caption layout is
    now used.

  + Change slide-level-0/h1-h2-with-text description

    This test now triggers the content with caption layout, giving a
    different (but still correct) result.

  + Add new tests for the new layout
  + Add new tests to the cabal file

- Support “Blank” slide layout

  This layout is used when a slide contains only blank content (e.g.
  non-breaking spaces). No content is inserted into any placeholders in
  the layout.

  Fixes #5097.

  + Accept straightforward test changes

    Blank layout now copied over from reference doc as well, when
    layouts have been deleted.

  + Add some new tests

    A slide should use the blank layout if:

    - It contains only speaker notes
    - It contains only an empty heading with a body of nbsps
    - It contains only a heading containing only nbsps

- Change ContentType -> Placeholder

  This type was starting to have a constructor for each placeholder on
  each slide (e.g. `ComparisonUpperLeftContent`). I’ve changed it
  instead to identify a placeholder by type and index, as I think that’s
  clearer and less redundant.

- Describe layout-choosing logic in manual
2021-09-01 07:16:17 -07:00
Emily Bourke
8dbea49092 pptx: Restructure tests
- Use dashes consistently rather than underscores
- Make a folder for each set of tests
- List test files explicitly (Cabal doesn’t support ** until version
  2.4)
2021-09-01 07:16:17 -07:00
Emily Bourke
8e5a79f264 pptx: Make first heading title if slide level is 0
Before this commit, the pptx writer adds a slide break before any table,
“columns” div, or paragraph starting with an image, unless the only
thing before it on the same slide is a heading at the slide level. In
that case, the item and heading are kept on the same slide, and the
heading is used as the slide title (inserted into the layout’s “title”
placeholder).

However, if the slide level is set to 0 (as was recently enabled) this
makes it impossible to have a slide with a title which contains any of
those items in its body.

This commit changes this behaviour: now if the slide level is 0, then
items will be kept with a heading of any level, if the heading’s the
only thing before the item on the same slide.
2021-08-27 09:47:03 -07:00
Emily Bourke
5616d00d09 pptx: Include image title in description
The image title (i.e. `![alt text](link "title")`) was previously
ignored when writing to pptx. This commit includes it in PowerPoint's
description of the image, along with the link (which was already
included).

Fixes 7352.
2021-08-18 10:10:55 -07:00
Emily Bourke
72823ad947 pptx: Select layouts from reference doc by name
Until now, users had to make sure that their reference doc contains
layouts in a specific order: the first four layouts in the file had to
have a specific structure, or else pandoc would error (or sometimes
successfully produce a pptx file, which PowerPoint would then fail to
open).

This commit changes the layout selection to use the layout names rather
than order: users must make sure their reference doc contains four
layouts with specific names, and if a layout with the right name isn’t
found pandoc will output a warning and use the corresponding layout from
the default reference doc as a fallback.

I believe the use of names rather than order will be clearer to users,
and the clearer errors will help them troubleshoot when things go wrong.

- Add tests for moved layouts
- Add tests for deleted layouts
- Add newly included layouts to slideMaster1.xml to fix tests
2021-08-17 09:35:25 -07:00
John MacFarlane
8660f42f09 Modify pptx tests to take a whole lot less space.
- Replace a 300K image in the reference pptx with a 2K one.
- Updated all the *_templated.pptx files based on the new
  reference pptx.
- These changes should reduce the size of the tarball by
  roughly 7 MB!

See haskell/hackage-server#935
2021-05-29 10:59:14 -07:00
John MacFarlane
967e7f5fb9 Rename Text.Pandoc.XMLParser -> Text.Pandoc.XML.Light...
..and add new definitions isomorphic to xml-light's, but with
Text instead of String.  This allows us to keep most of the code in
existing readers that use xml-light, but avoid lots of unnecessary
allocation.

We also add versions of the functions from xml-light's
Text.XML.Light.Output and Text.XML.Light.Proc that operate
on our modified XML types, and functions that convert
xml-light types to our types (since some of our dependencies,
like texmath, use xml-light).

Update golden tests for docx and pptx.

OOXML test: Use `showContent` instead of `ppContent` in `displayDiff`.

Docx: Do a manual traversal to unwrap sdt and smartTag.
This is faster, and needed to pass the tests.

Benchmarks:

A = prior to 8ca191604d (Feb 8)
B = as of 8ca191604d (Feb 8)
C = this commit

| Reader  |  A    | B      | C     |
| ------- | ----- | ------ | ----- |
| docbook | 18 ms | 12 ms  | 10 ms |
| opml    | 65 ms | 62 ms  | 35 ms |
| jats    | 15 ms | 11 ms  |  9 ms |
| docx    | 72 ms | 69 ms  | 44 ms |
| odt     | 78 ms | 41 ms  | 28 ms |
| epub    | 64 ms | 61 ms  | 56 ms |
| fb2     | 14 ms | 5  ms  | 4 ms  |
2021-02-16 16:55:20 -08:00
John MacFarlane
8ca191604d Add new unexported module T.P.XMLParser.
This exports functions that uses xml-conduit's parser to
produce an xml-light Element or [Content].  This allows
existing pandoc code to use a better parser without
much modification.

The new parser is used in all places where xml-light's
parser was previously used.  Benchmarks show a significant
performance improvement in parsing XML-based formats
(especially ODT and FB2).

Note that the xml-light types use String, so the
conversion from xml-conduit types involves a lot
of extra allocation.  It would be desirable to
avoid that in the future by gradually switching
to using xml-conduit directly. This can be done
module by module.

The new parser also reports errors, which we report
when possible.

A new constructor PandocXMLError has been added to
PandocError in T.P.Error [API change].

Closes #7091, which was the main stimulus.

These changes revealed the need for some changes
in the tests.  The docbook-reader.docbook test
lacked definitions for the entities it used; these
have been added. And the docx golden tests have been
updated, because the new parser does not preserve
the order of attributes.

Add entity defs to docbook-reader.docbook.

Update golden tests for docx.
2021-02-10 22:04:11 -08:00
Albert Krewinkel
dcd89413f3 Powerpoint writer: allow arbitrary OOXML in raw inline elements
The raw text is now included verbatim in the output. Previously is was parsed
into XML elements, which prevented the inclusion of partial XML snippets.
2020-12-27 23:18:54 +01:00
John MacFarlane
7f8105159c Handle native Underline in Powerpoint writer.
(Instead of old Span with underline class.
Spans with `underline` will no longer be rendered
as underlined text.)
2020-06-22 17:56:28 -07:00
despresc
d368536a4e Adapt to the removal of the RowSpan, ColSpan, RowHeadColumns accessors 2020-04-15 23:03:22 -04:00
despresc
4e34d366df Adapt to the newest Table type, fix some previous adaptation issues
- Writers.Native is now adapted to the new Table type.

- Inline captions should now be conditionally wrapped in a Plain, not
  a Para block.

- The toLegacyTable function now lives in Writers.Shared.
2020-04-15 23:03:22 -04:00
despresc
7254a2ae0b Implement the new Table type 2020-04-15 23:03:22 -04:00
Jesse Rosenthal
4a7dad18b1 PowerPoint writer: Start numbering at appopriate numbers.
Starting numbers for ordered lists were previously ignored. Now we
specify the number if it is something other than 1.

Closes: #5709
2019-08-27 01:24:41 -04:00
Jeroen de Haas
e67f4c58f2 Powerpoint code formatting is now context dependent (#5573)
This commit alters the way in which the Powerpoint writer treats
inline code and code blocks.

- Inline code is now formatted at the same size as the surrounding
  text.
- Code blocks are now given a margin and font size according to their
  level.
- Furthermore this commit allows changing the font with which code is
  formatted via the `monofont` option.

Tested in
- PowerPoint 365 for Windows - 1808 (Build 10730.20344 Click-to-Run)
- PowerPoint 365 for Mac - 16.26 (19060901)
2019-06-14 08:42:06 -07:00
Jesse Rosenthal
ab5c701343 PowerPoint writer: expand builtin reference doc to model all layouts
The previous built-in reference doc had only title and content
layouts. Add in a section-header slide and a two-content slide, so
users can more easily modify it to build their own templates.

Golden files needed to be regenerated. Checked on MS PowerPoint 2013.
2019-04-05 08:50:39 -04:00
Jesse Rosenthal
7ac860be74 PowerPoint tests: Regenerate golden files
Due to viewProps change in 61dc0f9f.

Golden files checked on PowerPoint 2013 (Win 10 on virtualbox).
2019-04-04 10:46:30 -04:00
Jesse Rosenthal
0d1fc7dfff PowerPoint writer: add test for speaker notes after metadata. 2019-03-31 17:09:00 -04:00
Jesse Rosenthal
efa6304eee Pptx writer: test for speaker notes after breaking header. 2019-03-30 22:52:31 -04:00
Jesse Rosenthal
a908129d93 Powerpoint writer: add tests for underline. 2019-02-27 09:30:50 -05:00
Agustín Martín Barbero
9894d05fe3 Improve writing metadata for docx, pptx and odt (#5252)
* docx writer: support custom properties.  Solves the writer part of #3024.
  Also supports additional core properties:  `subject`, `lang`, `category`,
  `description`.

* odt writer: improve standard properties, including the following core properties:
  `generator` (Pandoc/VERSION), `description`, `subject`, `keywords`,
  `initial-creator` (from authors), `creation-date` (actual creation date).
  Also fix date.

* pptx writer: support custom properties.  Also supports additional core
  properties: `subject`, `category`, `description`.

* Includes golden tests.

* MANUAL: document metadata support for docx, odt, pptx writers
2019-01-26 16:14:35 -08:00
Jesse Rosenthal
11e681edac Powerpoint tests: test raw openxml
Output files confirmed not to be corrupt, and with content as
expected, on PowerPoint 2013 on Windows 10 (virtualbox on linux).
2018-10-20 09:00:23 -04:00
Alexander Krotov
41cf6d540f More spellcheck 2018-07-02 19:07:28 +03:00
Jesse Rosenthal
a295fed873 Update powerpoint golden tests:
Some internal changes in templating produced slightly different
xml. All have been checked, are not corrupt, and have output as expected.
2018-03-24 11:07:47 -04:00
Jesse Rosenthal
f12348cab5 Powerpoint writer: add tests for improved speaker notes.
Tests speaker notes appearing after (and inside of) separating blocks.

Output checked on Windows10 (archlinux virtualbox), PowerPoint
2013. Not corrupted, and output as expected.
2018-03-21 10:07:07 -04:00
Jesse Rosenthal
9abcb4f201 Powerpoint writer: Use table styles
This will use the default table style in the reference-doc file. As a
result they will be easier when using in a template, and match the
color scheme.
2018-02-27 10:19:35 -05:00
Jesse Rosenthal
cdaa80e718 Powerpoint writer: add test for table and list syntax
These were never added when the tests were first created.

Output files checked in MS PowerPoint 2013 (Windows 10, VBox). No
corruption, and output as expected.
2018-02-27 09:34:24 -05:00
Jesse Rosenthal
cdbe45e8ee Powerpoint writer: Remove empty slides
Make sure there are no empty slides in the pptx output. Because of the
way that slides were split, these could be accidentally produced by
comments after images.

When animations are added, there will be a way to add an empty slide
with either incremental lists or pauses.

Test outputs checked with MS PowerPoint (Office 2013, Windows 10,
VBox). Both files have expected output and are not corrupted.
2018-02-27 09:12:17 -05:00
Jesse Rosenthal
f6eac1ad7e Powerpoint writer tests: Test everything with template as well
Modify the PowerPoint tests to run all the tests with
template (--reference-doc) as well. Because there are so many
interlocking pieces, bugs can pop up in weird places when using
templates, since it changes how the writer builds its output
file.

For example, I recently discovered a bug in which speaker notes worked
fine and templating worked fine elsewhere, but templating with speaker
notes produced a file that would crash MS PowerPoint. That particular
bug was fixed, but this will forces us to check for that with each new
change.
2018-02-19 20:04:39 -05:00
Jesse Rosenthal
b3f2efd35a Powerpoint writer: Update.golden tests.
Checked with Office 2013. No corruption and output as expected.
2018-02-19 15:31:20 -05:00
Jesse Rosenthal
32e6ae4347 Powerpoint writer: Add tests for speaker notes. 2018-02-18 16:31:32 -05:00
Jesse Rosenthal
112602232c Powerpoint writer: update golden test files
Since the template changed, some small elements of these test files
changed as well.

All of these were checked with Powerpoint 2013 on Windows
10 (VirtualBox). All had expected outcomes and no corruption.
2018-02-18 16:31:32 -05:00
Jesse Rosenthal
f8640fdff0 Powerpoint writer tests: add tests for two-column layout and images
Powerpoint output checked in MS PowerPoint 2013 (Windows)
2018-01-22 14:06:47 -05:00
Jesse Rosenthal
145c3f54f9 Powerpoint writer: Add further tests
Tests added for:

 - table of contents
 - endnotes
 - endnotes with table of contents

Powerpoint output checked in MS PowerPoint 2013 (Windows)
2018-01-22 11:52:03 -05:00
Jesse Rosenthal
54526525bf Powerpoint writer tests: New test framework for pptx.
Previously we had tested certain properties of the output PowerPoint
slides. Corruption, though, comes as the result of a numebr of
interrelated issues in the output pptx archive. This is a new
approach, which compares the output of the Powerpoint writer with
files that we know to (a) not be corrupt, and (b) to show the desired
output behavior (details below). This commit introduces three tests
using the new framework. More will follow.

The test procedure: given a native file and a pptx file, we generate a
pptx archive from the native file, and then test:

1. Whether the same files are in the two archives

2. Whether each of the contained xml files is the same. (We skip time
   entries in `docProps/core.xml`, since these are derived from IO. We
   just check to make sure that they're there in the same way in both
   files.)

3. Whether each of the media files is the same.

Note that steps 2 and 3, though they compare multiple files, are one
test each, since the number of files depends on the input file (if
there is a failure, it will only report the first failed file
comparison in the test failure).
2018-01-21 12:15:35 -05:00