diff --git a/AUTHORS.md b/AUTHORS.md
--- a/AUTHORS.md
+++ b/AUTHORS.md
@@ -6,6 +6,7 @@
 - Agustín Martín Barbero
 - Akash Patel
 - Akos Marton
+- Alain Lesage
 - Albert Krewinkel
 - Albert Lei
 - Alex Ivkin
@@ -29,6 +30,7 @@
 - Andreas Deininger
 - Andreas Lööw
 - Andreas Scherer
+- Andrzej Rybczak
 - Andres Freund
 - Andrew Dunning
 - Andy Morris
@@ -46,6 +48,7 @@
 - Artyom Kazak
 - Aslak Hellesøy
 - Asliddinbek Azizovich
+- Asuka
 - B. Scott Michel
 - Bastien Dumont
 - Ben Firshman
@@ -64,6 +67,7 @@
 - Brent Yorgey
 - Brian Leung
 - Bryan O'Sullivan
+- Caio Vinícius
 - Caleb McDaniel
 - Caleb Mclennan
 - Calvin Beck
@@ -217,6 +221,7 @@
 - Jens Oehlschlägel
 - Jesse Hathaway
 - Jeremie Knuesel
+- Jeremy Levartovsky
 - Jérémy Bobbio
 - Jeroen de Haas
 - Jerry Sky
@@ -317,6 +322,7 @@
 - Mohamed Akram
 - Morgan Willcock
 - Morton Fox
+- Nacho García
 - Nathan Gass
 - Naveen
 - Neil Mayhew
@@ -345,6 +351,7 @@
 - Owen McGrath
 - Pablo Rodríguez
 - Pascal Wagler
+- Patrick Creighton
 - Pau RE
 - Paul Rivier
 - Paul Tilley
@@ -466,6 +473,7 @@
 - William Lupton
 - William Rusnack
 - Winnie Hellmann
+- Wleeaf
 - Wout Gevaert
 - Wrong-Code
 - Xavier Olive
@@ -496,6 +504,7 @@
 - dbecher-ito
 - ebiim
 - ech0
+- enieuwy
 - etclub
 - favonia
 - gemmaro
@@ -553,6 +562,7 @@
 - thsutton
 - thron7
 - timo-a
+- tyler000000
 - vijayphoenix
 - vkraven
 - wgevaert
diff --git a/MANUAL.txt b/MANUAL.txt
--- a/MANUAL.txt
+++ b/MANUAL.txt
@@ -1,7 +1,7 @@
 ---
 title: Pandoc User's Guide
 author: John MacFarlane
-date: 2026-10-07
+date: 2026-11-10
 ---
 
 # Synopsis
@@ -146,7 +146,7 @@
 [`babel`] (with `lang`).  If `CJKmainfont` is set, [`xeCJK`]
 is needed if `xelatex` is used, else [`luatexja`] is needed if
 `lualatex` is used. [`framed`] is required if code is highlighted in a
-scheme that use a colored background. The use of `xelatex` or
+scheme that uses a colored background. The use of `xelatex` or
 `lualatex` as the PDF engine requires [`fontspec`]. `lualatex`
 uses [`selnolig`] and [`lua-ul`]. `xelatex` uses [`bidi`] (with
 the `dir` variable set).
@@ -418,6 +418,19 @@
     is not created by pandoc, so you will need to create it yourself
     if you want to make use of it.)
 
+    If the `PANDOC_DATA_DIRS` environment variable is set to a list
+    of directories (separated by `:`, or `;` on Windows), these
+    directories will be searched, in order, for data files not
+    found in the user data directory, before pandoc falls back to
+    its default data files.  This applies to all data files that
+    are looked up in the user data directory, including templates,
+    filters, defaults files, metadata files, and CSL styles. Only
+    absolute paths in `PANDOC_DATA_DIRS` are used.  This makes it
+    possible for a package manager to install, for example, Lua
+    filters into `/some/prefix/share/pandoc/filters` and make them
+    available by adding `/some/prefix/share/pandoc` to
+    `PANDOC_DATA_DIRS`.
+
 `-d` *FILE*, `--defaults=`*FILE*
 
 :   Specify a set of default option settings.  *FILE* is a YAML or JSON
@@ -769,7 +782,7 @@
     `all` includes all insertions, deletions, and comments, wrapped
     in spans with `insertion`, `deletion`, `comment-start`, and
     `comment-end` classes, respectively. The author and time of
-    change is included. `all` is useful for scripting: only
+    change are included. `all` is useful for scripting: only
     accepting changes from a certain reviewer, say, or before a
     certain date. If a paragraph is inserted or deleted,
     `track-changes=all` produces a span with the class
@@ -781,7 +794,7 @@
 
 :   Extract images and other media contained in or linked from
     the source document to the path *DIR*, creating it if
-    necessary, and adjust the images references in the document
+    necessary, and adjust the image references in the document
     so they point to the extracted files.  Media are downloaded,
     read from the file system, or extracted from a binary
     container (e.g. docx), as needed.  The original file paths
@@ -1255,7 +1268,7 @@
 `--listings[=true|false]`
 
 :   *Deprecated, use `--syntax-highlighting=idiomatic` or
-    `--syntax-highlighting=default` instead.
+    `--syntax-highlighting=default` instead.*
 
     Use the [`listings`] package for LaTeX code blocks. The package
     does not support multi-byte encoding for source code. To handle UTF-8
@@ -1504,7 +1517,7 @@
     `<dc:title>` (from the document title), `<dc:creator>` (from the
     document authors), `<dc:date>` (from the document date, which should
     be in [ISO 8601 format]), `<dc:language>` (from the `lang`
-    variable, or, if is not set, the locale), and `<dc:identifier
+    variable, or, if it is not set, the locale), and `<dc:identifier
     id="BookId">` (a randomly generated UUID). Any of these may be
     overridden by elements in the metadata file.
 
@@ -1635,7 +1648,7 @@
 :   Set the `bibliography` field in the document's metadata to *FILE*,
     overriding any value set in the metadata.  If you supply
     this argument multiple times, each *FILE* will be added to
-    bibliography.  If *FILE* is a URL, it will be fetched
+    the bibliography.  If *FILE* is a URL, it will be fetched
     via HTTP. If *FILE* is not found relative to the
     working directory, it will be sought in the resource path
     (see `--resource-path`).
@@ -1689,7 +1702,7 @@
 
     `mathjax`[`:`*URL*]
 
-      : Render math using [MathJaX]. TeX math will be put between
+      : Render math using [MathJax]. TeX math will be put between
         `\(...\)` (for inline math) or `\[...\]` (for display
         math) and wrapped in `<span>` tags with class `math`.
         Then the MathJax JavaScript will render it. The *URL*
@@ -2369,7 +2382,7 @@
 | ```                              | ```                               |
 +----------------------------------+-----------------------------------+
 
-If the command line option accepts a URL argument, an `url:` field can
+If the command line option accepts a URL argument, a `url:` field can
 be added to `math-method:`.
 
 ## Options for wrapper scripts
@@ -2794,7 +2807,7 @@
 
 - `roman`:  Converts textual values that can be
   read as an integer into lowercase roman numerals.
-  This can be used to get lettered enumeration from array indices.
+  This can be used to get roman-numeral enumeration from array indices.
   To get uppercase roman, chain with `uppercase`.
 
 - `left n "leftborder" "rightborder"`:  Renders a textual value
@@ -2956,7 +2969,7 @@
 
 `quotebordercolor`, `quotebordercolordark`
 :   sets the CSS `border-color` property for the left-border of
-:   `blockquote` elements.
+    `blockquote` elements.
 
 `quotecolor`, `quotecolordark`
 :   sets the CSS `color` property for `blockquote` elements.
@@ -3492,7 +3505,7 @@
 
 `pdfaintent`
 :   when used in conjunction with `pdfa`, specifies the output intent for
-    the colors, e.g. `ISO coated v2 300\letterpercent\space (ECI)`
+    the colors, e.g. `ISO coated v2 300\letterpercent\space (ECI)`.
     If left unspecified, `sRGB IEC61966-2.1` is used as default.
 
 `toc`
@@ -3616,7 +3629,7 @@
 ### Variables for ms
 
 `fontfamily`
-:   `A` (Avant Garde), `B` (Bookman), `C` (Helvetica), `HN`
+:   `A` (Avant Garde), `B` (Bookman), `H` (Helvetica), `HN`
     (Helvetica Narrow), `P` (Palatino), or `T` (Times New Roman).
     This setting does not affect source code, which is always
     displayed using monospace Courier. These built-in fonts are
@@ -3658,8 +3671,8 @@
     The recognized formats for `date` are: `mm/dd/yyyy`,
     `mm/dd/yy`, `yyyy-mm-dd` (ISO 8601), `dd MM yyyy`
     (e.g. either `02 Apr 2018` or `02 April 2018`),
-    `MM dd, yyyy` (e.g. `Apr. 02, 2018` or `April 02, 2018),
-    `yyyy[mm[dd]]` (e.g. `20180402, `201804` or `2018`).
+    `MM dd, yyyy` (e.g. `Apr. 02, 2018` or `April 02, 2018`),
+    `yyyy[mm[dd]]` (e.g. `20180402`, `201804` or `2018`).
 
 `header-includes`
 :   contents specified by `-H/--include-in-header` (may have multiple
@@ -3771,7 +3784,7 @@
 then in reading LaTeX pandoc will parse these characters
 literally.  In writing LaTeX, enabling `smart` tells pandoc
 to use the ligatures when possible; if `smart` is disabled
-pandoc will use unicode quotation mark and dash characters.
+pandoc will use Unicode quotation mark and dash characters.
 
 ## Headings and sections
 
@@ -4018,9 +4031,9 @@
 substituted with cross-references that will use the number
 of the referenced item. The original link text is discarded.
 This extension can be combined with `xrefs_name` in which case
-the name or caption numbers will appear after the number.
+the name or caption will appear after the number.
 
-For the `xrefs_number` to be useful heading numbers must be enabled
+For the `xrefs_number` extension to be useful, heading numbers must be enabled
 in the generated document, also table and figure captions must be enabled
 using for example the `native_numbering` extension.
 
@@ -4043,8 +4056,20 @@
 (Table styles will be added to the Table elements directly.)
 This extension can be used with [docx custom styles](#custom-styles).
 
+When converting from odt or fodt, add `custom-styles`
+attributes for paragraph and character styles, using the
+style names shown in the word processor. Automatic styles,
+which only record direct formatting, are not recorded; instead,
+the named style they are based on is used. A few styles are not
+recorded: the default paragraph style (`Default Paragraph Style`,
+or `Standard`), the default styles of table cells, and styles
+that pandoc interprets itself (such as `Emphasis` and `Strong
+Emphasis`). The paragraphs of list items are not wrapped in Divs.
+A heading gets a `custom-style` attribute if its style is not the
+standard one for its level.
+
 input formats
-:  `docx`
+:  `docx`, `odt`, `fodt`
 
 ### Extension: `amuse` ###
 
@@ -4415,7 +4440,7 @@
 
 ### Extension: `fenced_code_attributes` ###
 
-Optionally, you may attach attributes to fenced or backtick code block using
+Optionally, you may attach attributes to a fenced or backtick code block using
 this syntax:
 
     ~~~~ {#mycode .haskell .numberLines startFrom="100"}
@@ -5090,7 +5115,7 @@
 the number of dashes in the line separating the table header
 from the table body. (For example `---|-` would make the first column 3/4
 and the second column 1/4 of the full text width.)
-On the other hand, if no lines are wider than column width, then
+On the other hand, if no lines are wider than the column width, then
 cell contents will not be wrapped, and the cells will be sized
 to their contents.
 
@@ -5127,6 +5152,13 @@
 
     : The caption of the table. {#ident .float latex-placement="ht"}
 
+To repeat the caption of a `longtable` on each page, add the
+`repeat-caption` class to the table's attributes. Repeated captions are
+not added to the list of tables. This class has no effect on tables with
+the `float` class, since those tables cannot span pages.
+
+    : The caption of the table. {.repeat-caption}
+
 Note that `longtable` does not work with two-column layouts, so if you
 are producing a two-column document using LaTeX, you will need to specify
 the `float` class on every table, or use this small Lua filter
@@ -5595,7 +5627,7 @@
 
 FictionBook2
   ~ If `--math-method=webtex` is used, formulas are rendered as images
-    using CodeCogs or other compatible web service, downloaded
+    using CodeCogs or another compatible web service, downloaded
     and embedded in the e-book. Otherwise, they will appear verbatim.
 
 HTML, Slidy, DZSlides, S5, EPUB
@@ -5622,12 +5654,13 @@
 For a more explicit way of including raw HTML in a Markdown
 document, see the [`raw_attribute` extension][Extension: `raw_attribute`].
 
-In the CommonMark format, if `raw_html` is enabled, superscripts,
+In commonmark output, if `raw_html` is enabled, superscripts,
 subscripts, strikeouts and small capitals will be represented as HTML.
-Otherwise, plain-text fallbacks will be used. Note that even if
-`raw_html` is disabled, tables will be rendered with HTML syntax if
-they cannot use pipe syntax.
+Otherwise, plain-text fallbacks will be used.
 
+Disabling the `raw_html` extension has no effect on `commonmark` (or
+`gfm` or `commonmark_x`) *input*.
+
 ### Extension: `markdown_in_html_blocks` ###
 
 Original Markdown allows you to include HTML "blocks":  blocks
@@ -5675,7 +5708,7 @@
 
 ### Extension: `native_spans` ###
 
-Use native pandoc `Span` blocks for content inside `<span>` tags.
+Use native pandoc `Span` elements for content inside `<span>` tags.
 For the most part this should give the same output as `raw_html`,
 but it makes it easier to write pandoc filters to manipulate groups
 of inlines.
@@ -5816,7 +5849,7 @@
 The link consists of link text in square brackets, followed by a label in
 square brackets. (There cannot be space between the two unless the
 `spaced_reference_links` extension is enabled.) If the label is empty
-(`[]`), then it will be implicitly be taken to be the same as the link text;
+(`[]`), then it will implicitly be taken to be the same as the link text;
 thus `[foo][]` is equivalent to `[foo][foo]`. (If the
 `shortcut_reference_links` extension is enabled, the empty `[]`
 may be omitted.)
@@ -5828,7 +5861,7 @@
 extension is enabled): citations take precedence over link
 labels.
 
-Here are some examples of reference links and link definitions;
+Here are some examples of reference links and link definitions:
 
     See [the website *I* built][my website].
 
@@ -5977,7 +6010,7 @@
   itself contains dpi information).
 - The `%` unit is generally relative to some available space.
   For example the above example will render to the following.
-  - HTML: `<img href="file.jpg" style="width: 50%;" />`
+  - HTML: `<img src="file.jpg" style="width: 50%;" />`
   - LaTeX: `\includegraphics[width=0.5\textwidth,height=\textheight]{file.jpg}`
     (If you're using a custom template, you need to configure `graphicx`
     as in the default template.)
@@ -6159,7 +6192,7 @@
 
 In complex cases, you can force something to be treated as
 a locator by enclosing it in curly braces or prevent parsing
-the suffix as locator by prepending curly braces:
+the suffix as a locator by prepending curly braces:
 
     [@smith{ii, A, D-Z}, with a suffix]
     [@smith, {pp. iv, vi-xi, (xv)-(xvii)} with suffix here]
@@ -6250,7 +6283,7 @@
 
 ### Extension: `mark` ###
 
-To highlight out a section of text, begin and end it with
+To highlight a section of text, begin and end it
 with `==`. Thus, for example,
 
     This ==is deleted text.==
@@ -6493,7 +6526,7 @@
 where `FORMAT` is replaced with the name of the format.
 
 Note that the list of extensions for `commonmark`,
-`gfm`, and `commonmark_x` are defined relative to default
+`gfm`, and `commonmark_x` is defined relative to default
 commonmark.  So, for example, `backtick_code_blocks`
 does not appear as an extension, since it is enabled by
 default and cannot be disabled.
@@ -6518,8 +6551,8 @@
 `bibliography` metadata field in a YAML metadata section or the
 `--bibliography` command line argument. If you want to use
 multiple bibliography files, you can supply multiple
-`--bibliography` arguments or set `bibliography` metadata field
-to YAML array.  A bibliography may have any of these formats:
+`--bibliography` arguments or set the `bibliography` metadata field
+to a YAML array.  A bibliography may have any of these formats:
 
   Format            File extension
   ------------      --------------
@@ -6800,8 +6833,8 @@
 
 For LaTeX output, you can also use [`natbib`] or [`biblatex`] to
 render the bibliography. In order to do so, specify bibliography
-files as outlined above, and add `--natbib` or `--biblatex`
-argument to pandoc invocation. Bear in mind that bibliography
+files as outlined above, and add the `--natbib` or `--biblatex`
+argument to the pandoc invocation. Bear in mind that bibliography
 files have to be in either BibTeX (for `--natbib`)
 or BibLaTeX (for `--biblatex`) format.
 
@@ -6815,7 +6848,7 @@
     numerical styles only).  Defaults to false.
 
 `link-bibliography`
-:   If true, DOIs, PMCIDs, PMID, and URLs in bibliographies will
+:   If true, DOIs, PMCIDs, PMIDs, and URLs in bibliographies will
     be rendered as hyperlinks.  (If an entry contains a DOI, PMCID,
     PMID, or URL, but none of these fields are rendered by the style,
     then the title, or in the absence of a title the whole entry, will
@@ -7017,6 +7050,11 @@
 pandoc, unless an alternative reference doc is specified using
 `--reference-doc`.
 
+When reading pptx, each slide becomes a level-2 heading with the
+identifier `slide-N`, followed by the slide's content. Slides hidden
+from the slide show are read too, with the class `hidden` on their
+heading.
+
 ## Incremental lists
 
 By default, these writers produce lists that display "all at once."
@@ -7132,6 +7170,10 @@
 Notes are not yet supported for other slide formats, but the notes
 will not appear on the slides themselves.
 
+When reading pptx, the speaker notes of each slide are read into a
+`notes` div at the end of the slide's content, so a pptx file
+converted to Markdown and back keeps its notes.
+
 ### Speaker notes on the title slide (PowerPoint)
 
 For PowerPoint output, the title slide is generated from the document's
@@ -7690,7 +7732,7 @@
 
 # Vimdoc
 
-Vimdoc writer generates Vim help files and makes use of the following metadata
+The Vimdoc writer generates Vim help files and makes use of the following metadata
 variables:
 
 ``` yaml
@@ -7703,8 +7745,8 @@
 vimdoc-prefix: pandoc
 ```
 
-Complete header requires `abstract`, `author`, `title` and `filename` to
-be set. Compiling file with such metadata produces the following file
+A complete header requires `abstract`, `author`, `title` and `filename` to
+be set. Compiling a file with such metadata produces the following file
 (assumes `--standalone`, see [Templates]):
 
 ``` vimdoc
@@ -7721,7 +7763,7 @@
 ```
 
 If `vimdoc-prefix` is set, all non-command tags are prefixed with its
-value, it is used to prevent tag collision: all headers have a tag
+value; this is used to prevent tag collision: all headers have a tag
 (either inferred or explicit) and multiple help pages can have the same
 header names, therefore collision is to be expected. Let our input be
 the following markdown file:
@@ -7759,7 +7801,7 @@
     inherently represent anything.
 ```
 
-Convert it to vimdoc with metadata variable set (e.g. with
+Convert it to vimdoc with the metadata variable set (e.g. with
 `-M vimdoc-prefix=pandoc`)
 
 ``` vimdoc
@@ -7919,6 +7961,8 @@
 attribute will be added for each style. Divs will be created to
 hold the paragraph styles, and Spans to hold the character styles.
 Table styles will be applied directly to the Table.
+The odt and fodt readers also support the `styles` extension
+(`-f odt+styles`), for paragraph and character styles.
 
 For example, using the `custom-style-reference.docx` file in the test
 directory, we have the following different outputs:
@@ -8073,12 +8117,12 @@
     pandoc -t context+tagging doc.md -o doc.pdf
 
 A recent `context` version should be used, as older versions
-contained a bug that lead to invalid PDF metadata.
+contained a bug that led to invalid PDF metadata.
 
 ## WeasyPrint
 
 The HTML-based engine WeasyPrint includes experimental support for
-PDF/A and PDF/UA since version 57. Tagged PDFs can created with
+PDF/A and PDF/UA since version 57. Tagged PDFs can be created with
 
     pandoc --pdf-engine=weasyprint \
            --pdf-engine-opt=--pdf-variant=pdf/ua-1 ...
@@ -8151,7 +8195,7 @@
 # A note on security
 
 1. Although pandoc itself will not create or modify any files other
-   than those you explicitly ask it create (with the exception
+   than those you explicitly ask it to create (with the exception
    of temporary files used in producing PDFs), a filter or custom
    writer could in principle do anything on your file system. Please
    audit filters and custom writers very carefully before using them.
@@ -8190,10 +8234,10 @@
      For example, in `wkhtmltopdf` the `footer-html` and `header-html`
      metadata fields will be passed directly to `wkhtmltopdf`
      as `--footer-html` and `--header-html` arguments, and by using
-     a `file:` URIs with these, one could exfiltrate local files.
+     a `file:` URI with these, one could exfiltrate local files.
      In addition, using `--pdf-engine=wkhtmltopdf` with `-f html+raw_html`
      enables an SSRF vulnerability in wkhtmltopdf ([CVE-2022-35583]).
-     Note that [`wkhtmltopdf`) is
+     Note that [`wkhtmltopdf`] is
      [deprecated](https://wkhtmltopdf.org/status.html) and
      its authors recommend not to use it with any untrusted input.
      However, there may be similar issues with other pdf-engines.
diff --git a/changelog.md b/changelog.md
--- a/changelog.md
+++ b/changelog.md
@@ -1,5 +1,375 @@
 # Revision history for pandoc
 
+## pandoc 3.14 (2026-11-10)
+
+  * Support `PANDOC_DATA_DIRS` for data file lookup (#7922).
+    If `PANDOC_DATA_DIRS` is set, the (absolute) directories it lists are
+    searched, in order, for data files not found in the user data directory,
+    before falling back to the default data files.  This covers templates,
+    filters, defaults files, metadata files, CSL styles, and other data files.
+    If `PANDOC_USER_DATA_DIRS` is set, print its value in `--version` output.
+
+  * Reset sourcepos when parsing footnotes and grid table cells (#12001,
+    extends fix for #11888). Otherwise, when one of these ends a
+    file, relative paths in it can be rebased against the next
+    file on the command line.
+
+  * LaTeX reader:
+
+    + Fix duplicated text after a control space at line end (#12051, Asuka).
+    + Handle pandoc's deferred footnotes (`\pandocfootnotemark{n}` and
+      `\pandocfootnotetext{n}{..}`) as produced by the LaTeX writer for
+      notes in tables, captions, etc.
+    + Ignore definitions of `\pandocbounded`, `\pandocfootnotemark`,
+      and `\pandocfootnotetext` (e.g. from pandoc's template), which
+      the reader handles directly. Previously these definitions were
+      expanded, producing garbage and losing content.
+    + Fix file-crossing bug in `rawLaTeXParser` (#12072).
+      The raw LaTeX parser didn't work properly when crossing
+      from one source file to another.
+
+  * Typst reader:
+
+    + Handle `columns: auto` in grid (#12061).
+
+  * HTML reader:
+
+    + Don't drop ordered lists and rules inside footnotes (#11852).
+      Previously an `<ol>` inside the body of a note was treated as the list of
+      notes, and its items were lost.  Similarly, an `<hr>` inside a note was
+      dropped.
+
+  * RST reader:
+
+    + Strip minimum indentation from indented blocks (#12071). Previously
+      the indentation of the first line was stripped, so lines with
+      less indentation lost all their leading whitespace. Now, as
+      in docutils, the minimum indentation is stripped and relative
+      indentation is preserved.
+    + Require descriptions in option list items (#12063).
+
+  * ODT reader:
+
+    + Support the `styles` extension (#12060).
+
+  * Docx reader:
+
+    + Merge adjacent styled code blocks (#9183, Caio Vinícius).
+      Without `+styles`, consecutive "Source Code" paragraphs are combined into
+      a single code block by `combineBlocks`. With `+styles`, each paragraph is
+      first wrapped in a `Div` carrying its `custom-style` attribute, so
+      the `CodeBlock` case no longer matched and every line became its
+      own `Div [CodeBlock]`.
+    + Don't drop contents of customXml element (#12050).
+    + Read all underline types (#11988, Patrick Creighton).
+    + Follow `w:numStyleLink` in abstract numberings (#9222, Caio Vinícius).
+
+  * Pptx reader:
+
+    + Don't add spaces between text runs (#12016, Nacho García).
+    + Read the shapes inside group shapes (#12017, Nacho García).
+    + Read equations and markup-compatibility blocks (#12025, Nacho Garcia).
+    + Read speaker notes (Nacho García, #12023). Each slide's notes are now read
+      into a `notes` div at the end of the slide's blocks, the form the pptx
+      writer turns into speaker notes, so pptx -> Markdown -> pptx keeps them.
+    + Read charts as tables (Nacho García, #12023). Previously, a chart was read
+      as a placeholder text. We now create a table from the chart's cached
+      data. The table is put in a `chart` Div whose `type` attribute holds
+      the chart type. The chart's title becomes the table captions.
+      The chart code is in Text.Pandoc.Readers.OOXML.Charts.
+    + Mark hidden slides with a `hidden` class on the header
+      (Nacho García, #12023).
+    + Handle merged table cells (Nacho García).
+    + Parse bold, italic, sub/superscript and hyperlinks (Nacho García). Text runs
+      were previously read as plain text, so their formatting and hyperlinks
+      were lost.
+    + Read inherited bullets, numbering and nested lists (#12042, Nacho García).
+    + Skip slide number placeholders (#12045, Nacho García).
+
+  * Xlsx reader:
+
+    + Resolve package-absolute relationship targets (#12013, Nacho García).
+    + Read inline strings and rich text as written (#12014, Nacho García).
+    + Look up a cell's font through its cell format (#12033, Nacho García).
+    + Read merged cells as spans (Nacho García).
+    + Render dates and times (Nacho García).
+    + Render numbers as Excel's General format (Nacho García, #12023).
+    + Read charts (#12043, Nacho García). Charts are now read as tables using
+      the cached data.
+
+  * Docx writer:
+
+    + Implement flip-flopping for emph (#11961). Emph within emph becomes upright.
+      This is important for correct formatting of titles in CSL, among other
+      things. LaTeX does this automatically, and in HTML we achieve it via CSS.
+
+  * EPUB writer:
+
+    + Fix `id` clash with added title header (#12003, Alain Lesage).
+    + Skip dates that cannot be normalized (#12002, Alain Lesage).
+
+  * Ipynb writer:
+
+    + Make ANSI escape stripping linear (#7744, Jeremy Levartovsky).
+
+  * Vimwiki reader:
+
+    + Support rejected todos (tyler000000).
+
+  * LaTeX writer:
+
+    + Fix hyperlinks for deferred footnotes (#11936). Notes in tables,
+      captions, and definition list terms are rendered as a mark
+      followed later by the note text. Previously we used
+      `\footnotemark{}` and `\footnotetext` with manual adjustments to
+      the footnote counter. But hyperref anchors each `\footnotetext` at
+      the destination of the most recent `\footnotemark`, so when there
+      were several such notes, all of the texts got the last mark's
+      anchor and the links for the other marks were broken. We now emit
+      `\pandocfootnotemark{n}` and `\pandocfootnotetext{n}{..}`, where
+      `n` is a unique id. These macros, defined in the default template
+      when the `deferred-notes` variable is set, save the footnote mark
+      and hyperref anchor at the mark and restore them at the text. This
+      removes the need for counter arithmetic, works when the footnote
+      counter is reset by chapter, and handles notes nested inside
+      deferred notes (whose texts are now emitted after the text
+      containing their marks). **Note:** Users of custom LaTeX
+      templates, or of LaTeX fragments produced without `--standalone`,
+      will need to include the definitions of `\pandocfootnotemark` and
+      `\pandocfootnotetext` from the default template.
+    + Allow repeated longtable captions (#4558, Václav Haisman). If a
+      table has a `repeat-caption` class, captions will be repeated on
+      each page of a longtable.
+
+  * HTML styles template:
+
+    + Add emph flip-flopping. So, emph within emph renders as upright, etc.
+    + Move `@print` rules to end (#12064), so they aren't overridden.
+
+  * Text.Pandoc.PDF:
+
+    + PDF via LaTeX: do at most 3 runs when only a TOC is present
+      (#12012, Alain Lesage).
+
+  * Text.Pandoc.Class:
+
+    + Export new functions `getDataDirs` and `getPandocDataDirs`. [API change]
+
+  * Text.Pandoc.Citeproc:
+
+    + `removeFinalPeriod` now acts across Link boundary.
+
+  * pandoc-lua-engine: raise lower bound for pandoc to 3.13 (#12066).
+
+  * Depend on texmath 0.13.3.5, commonmark 0.3.2, commonmark-extensions 0.2.8,
+    citeproc 0.14.2, typst 0.12.1, emojis 0.1.6, skylighting 0.15.0.1.
+
+  * New bounds for crypton in pandoc-lua-engine and pandoc.
+
+  * Makefile:
+
+    + Fix release-templates target so it pushes tags.
+    + Remove default CABALOPTS. These can be put in cabal.project.local.
+      This will ensure that the same options are used by HLS, so that rebuilds
+      aren't needed.
+    + `make check-cabal`: exit with error status on outdated deps.
+    + Reorganize `check-cabal; add `check-sdist` target we can run separately.
+
+  * cabal.project: specify `+http` flag for all ghc versions.
+
+  * Minimize the test docx, odt, pptx files. This reduces the
+    size of the test files (and release tarball) by 1.79 MB.
+
+## pandoc 3.13 (2026-10-26)
+
+  * Report the location of errors in defaults files (#8759, Andrzej Rybczak).
+    An invalid value in a defaults file gave an error at the start of the
+    file, with no indication of the field. The error now names the option and
+    points at its value.
+
+  * Use yamlet for YAML parsing. Pandoc parsed YAML with the yaml
+    package, which depends on the C library libyaml. It now uses
+    yamlet, a pure Haskell YAML 1.2 parser. Values still go
+    through the existing aeson instances. Note these behavior changes:
+
+    + `yes`, `no`, `on`, `off`, `y` and `n` are strings,
+      not booleans, as in YAML 1.2.
+    + YAML errors now show the file, the line and the column, with the
+      offending line. In metadata blocks the line is the line in the
+      document.
+    + Duplicate keys in a mapping are an error. They were a warning.
+    + `.5`, `.inf` and `.nan` are numbers.
+
+  * Docx reader:
+
+    + Read `w:fldSimple` fields (#11944, Aslak Hellesøy).
+    + Keep grid columns that have no width (#11989, Patrick Creighton).
+      `w:w` is optional on `w:gridCol`, but `elemToTblGrid` skipped the grid
+      columns that had none. The table then had fewer columns than its rows had
+      cells, and the extra cells were dropped. Every grid column is now kept.
+      If any of them has no (readable) width, all columns get the default
+      width.
+    + Fix namespaces in notes and comments (#11991, Patrick Creighton).
+      The contents of footnotes, endnotes and comments were read with the
+      namespace prefixes declared in word/document.xml rather than in their own
+      parts.
+    + Records the indentation of each list level and track the open
+      list levels; an unnumbered paragraph whose left indentation
+      matches the text indentation of an open level is treated as a continuation
+      of that level's current item, rather than as a block quote (cf. #9197).
+    + Recover from fields with a missing instruction (#11943, enieuwy).
+      This fixes a bug that could lead to content being omitted.
+    + Fix regression (from 3.11) in parsing column widths (#11969).
+      The regression caused only the first column to get
+      assigned its alignment; every other column received default alignment.
+      In addition, in 3.11 alignment was taken from the header row if present;
+      this changed behavior from earlier versions, which took it from the first
+      body row. We revert to the earlier behavior, using the header row only if
+      there are no body rows. It's common for the header to have different
+      alignment than the rest.
+    + Keep tracked paragraph marks inside notes (#11971, Aslak Hellesøy).
+
+  * RST reader:
+
+    + Allow inline markup and bare links after `:`, `/`, `'`, `"`, `<`
+      (Wleeaf). Fixes a regression since 3.2.1; these characters could no
+      longer precede an inline markup start-string or a bare URI or email
+      address, although the reStructuredText spec allows them.
+      Also implement the rule that a start-character between an opening
+      character and its closing counterpart, as in `(*)` or `"*"`,
+      does not trigger inline markup.
+
+  * RTF reader:
+
+    + Fix tokenization bug (#11981). We were consuming certain
+      symbols after `\uNNNN` during tokenization. This led to an
+      *extra* character being consumed as the "fallback," so
+      letters went missing after encoded unicode characters.
+
+  * LaTeX reader:
+
+    + Detect macro expansion loops across `doMacros` calls (#11088).
+
+  * ODT reader:
+
+    + Fix start numbers with `text:continue-numbering` (#9595).
+
+  * Markdown writer:
+
+    + Write wide tables as grid tables instead of falling back to HTML
+      (#11945, Aslak Hellesøy).
+    + Don't drop notes in notes.
+    + Fix regression with code block language (#11987). We try to
+      identify which class is a language name and emit that as the gfm
+      style info string. If none of the classes match a
+      recognized language, before 3.10.1 we emitted the first
+      class; fater 3.10.1, we emit nothing. This commit reverts to
+      the pre-3.10.1 behavior.
+
+  * RST writer:
+
+    + Don't drop notes in notes.
+
+  * Haddock writer:
+
+    + Don't drop notes in notes.
+
+  * Docx writer:
+
+    + Fix multi-paragraph list items (#9197). Previously the docx
+      writer gave the second and subsequent paragraphs of a list
+      item numbering from a separate list with an invisible bullet.
+      This looked right, but semantically these paragraphs were
+      items of another list, which is what Word, screen readers,
+      and pandoc's own docx reader saw; the list was also split in
+      three. The writer now gives these paragraphs no numbering,
+      just an indentation that lines them up with the text of the
+      list item (as Word's "List Continue" styles do).
+
+  * LaTeX writer:
+
+    + Use braces around term containing `=` (#11954). This is needed for
+      the new LaTeX list code, which is triggered by using `pdfstandard`.
+
+  * PowerPoint writer:
+
+    + Add `clrMapOvr` to notes slides (#11935, Gaurav Vijay Jadhav).
+      This makes them importable by Keynote.
+    + Include `lang` in core document properties.
+
+  * DocBook, JATS, TEI writers:
+
+    + Apply `writerIdentifierPrefix` prefix consistently.
+
+  * Typst writer:
+
+    + Escape `...` and `-?` ligatures (#11979).
+    + Use `getLang` to determine lang and region.
+      Previously only the `lang` metadata field was consulted, so
+      `lang` could not be set properly using a variable.
+
+  * Text.Pandoc.Translations:
+
+    + `readTranslations` now takes the path of the file, for error
+       messages [API change].
+
+  * Text.Pandoc.Writers.Shared:
+
+    + Add `wrapColumns`, `renderWithTemplate` [API change].
+      These factor out code that was repeated in about 20 writers: computing the
+      line length from writerWrapText/writerColumns, and rendering the body with
+      or without the template.
+
+  * Text.Pandoc.Shared:
+
+    + Export `plainToPara` and `paraToPlain`. [API change]
+
+  * Text.Pandoc.PDF:
+
+    + Make `--presentational-hints` default for weasyprint.
+      This is necessary to get list attributes (start, ordered
+      list type, etc.) working properly (#11976).
+
+  * cabal.project:
+
+    + Use bundle C option for zlib by default.
+      This allows pandoc to be built without first installing the C library
+      zlib. Those who want to use the system zlib can still compile pandoc
+      that way by overriding this setting in cabal.project.local, or
+      just installing directly from Hackage.
+    + Default to `+http` on GHC >= 9.14 (previously done only in
+      CI), so local builds behave the same; `-f-http` still overrides it.
+    + Pass wasm link flags for `pandoc-cli` as `ghc-options`.
+      cabal only passes ld-options along when it finds an `ld` program on the
+      PATH.  In an environment without one (e.g. `nix shell` with just the
+      ghc-wasm-meta toolchain), the flags were silently dropped and linking
+      pandoc.wasm failed with undefined `setjmp` and clock symbols.
+      Use `-optl- ghc-options` instead, which GHC passes to its
+      linker regardless.
+
+  * Makefile:
+
+    + Add `release` target.
+    + Improve `make pandoc-templates` so it does the whole job.
+    + Use bash as `SHELL` (`check-cabal` uses `pushd`, `check-version-sync`
+      uses `==`).
+    + Fix `$(id -u)` in `debpkg`, which make expanded to empty.
+    - Fix missing `echo` in `validate-docx-golden-tests{,2}`.
+    - Ensure pandoc is built before rules that run it to produce files.
+    - Use `git ls-files` for `SOURCEFILES`, not the main branch's tree.
+    - Drop redundant `embed_data_files` flag in `quick-stack`.
+
+  * Use released citeproc 0.14.1.1, texmath 0.13.3.3,
+    gridtables 0.1.1.1 (#9085).
+
+  * MANUAL.txt:
+
+    + Clarify the effect of `raw_html` in commonmark formats (#8305).
+
+  * Bump bounds on crypton, crypton-x509-system, tasty-bench.
+
+  * Add `tools/circleci-build-release.sh`, `tools/github-build-release.sh`.
+
 ## pandoc 3.12.1 (2026-10-07)
 
   * New input and output format: `fodt` (#4010). This is ODF's
diff --git a/data/templates/common.latex b/data/templates/common.latex
--- a/data/templates/common.latex
+++ b/data/templates/common.latex
@@ -91,6 +91,27 @@
 $endif$
 $endif$
 $--
+$-- deferred footnotes (in tables, captions, etc.)
+$--
+$if(deferred-notes)$
+% \pandocfootnotemark{n} saves the footnote mark and hyperref anchor;
+% \pandocfootnotetext{n}{text} restores them, so the footnote text
+% gets the right number and link target.
+\makeatletter
+\protected\def\pandocfootnotemark#1{\footnotemark{}%
+  \expandafter\xdef\csname pandoc@fn@#1\endcsname{%
+    \noexpand\pandoc@fnrestore
+    {\unexpanded\expandafter{\@thefnmark}}%
+    {\ifdefined\Hy@footnote@currentHref
+       \unexpanded\expandafter{\Hy@footnote@currentHref}\fi}}}
+\def\pandoc@fnrestore#1#2{%
+  \gdef\@thefnmark{#1}%
+  \ifdefined\Hy@footnote@currentHref\gdef\Hy@footnote@currentHref{#2}\fi}
+\newcommand\pandocfootnotetext[1]{%
+  \csname pandoc@fn@#1\endcsname\@footnotetext}
+\makeatother
+$endif$
+$--
 $-- graphics
 $--
 $if(graphics)$
diff --git a/data/templates/styles.html b/data/templates/styles.html
--- a/data/templates/styles.html
+++ b/data/templates/styles.html
@@ -39,27 +39,6 @@
     font-size: 1.8em;
   }
 }
-@media print {
-  html {
-    color-scheme: light only;
-  }
-  html, body, pre, code {
-    background-color: transparent;
-  }
-  body, a, a:visited, blockquote {
-    color: black;
-  }
-  pre, code {
-    padding: 0;
-  }
-  p, h2, h3 {
-    orphans: 3;
-    widows: 3;
-  }
-  h2, h3, h4 {
-    page-break-after: avoid;
-  }
-}
 p {
   margin: 1em 0;
 }
@@ -207,6 +186,12 @@
 }
 $endif$
 span.smallcaps{font-variant: small-caps;}
+em, em em em, em em em em em {
+  font-style: italic;
+}
+em em, em em em em {
+  font-style: normal;
+}
 div.columns{display: flex; gap: 1.5em;}
 div.column{flex: auto;}
 @media screen {
@@ -236,3 +221,24 @@
 $if(csl-css)$
 $styles.citations.html()$
 $endif$
+@media print {
+  html {
+    color-scheme: light only;
+  }
+  html, body, pre, code {
+    background-color: transparent;
+  }
+  body, a, a:visited, blockquote {
+    color: black;
+  }
+  pre, code {
+    padding: 0;
+  }
+  p, h2, h3 {
+    orphans: 3;
+    widows: 3;
+  }
+  h2, h3, h4 {
+    page-break-after: avoid;
+  }
+}
diff --git a/pandoc.cabal b/pandoc.cabal
--- a/pandoc.cabal
+++ b/pandoc.cabal
@@ -1,6 +1,6 @@
 cabal-version:   2.4
 name:            pandoc
-version:         3.12.1
+version:         3.14
 build-type:      Simple
 license:         GPL-2.0-or-later
 license-file:    COPYING.md
@@ -17,18 +17,19 @@
                  .
                  - light markup formats (many variants of Markdown,
                    reStructuredText, AsciiDoc, Org-mode, Muse, Textile,
-                   txt2tags, djot)
-                 - HTML formats (HTML 4 and 5)
+                   txt2tags, djot, bbcode)
+                 - HTML formats (HTML 4 and 5, chunked HTML)
                  - Ebook formats (EPUB v2 and v3, FB2)
                  - Documentation formats (GNU TexInfo, Haddock, Vimdoc)
-                 - Roff formats (man, ms)
+                 - Roff formats (man, ms, mdoc)
                  - TeX formats (LaTeX, ConTeXt)
                  - Typst
+                 - ANSI-formatted text
                  - XML formats (DocBook 4 and 5, JATS, TEI Simple, OpenDocument)
                  - Outline formats (OPML)
                  - Bibliography formats (BibTeX, BibLaTeX, CSL JSON, CSL YAML,
                    RIS)
-                 - Word processor formats (Docx, RTF, ODT)
+                 - Word processor formats (Docx, RTF, ODT, FODT)
                  - Interactive notebook formats (Jupyter notebook ipynb)
                  - Page layout formats (InDesign ICML)
                  - Wiki markup formats (MediaWiki, DokuWiki, TikiWiki, TWiki,
@@ -36,6 +37,8 @@
                  - Slide show formats (LaTeX Beamer, PowerPoint, Slidy,
                    reveal.js, Slideous, S5, DZSlides)
                  - Data formats (CSV and TSV tables, Excel spreadsheets)
+                 - Serialization formats (Haskell, JSON, or XML representation
+                   of the AST)
                  - PDF (via external programs such as pdflatex or wkhtmltopdf)
                  .
                  Pandoc can convert mathematical content in documents
@@ -227,6 +230,12 @@
                  test/command/11113.docx
                  test/command/11689.docx
                  test/command/11833.docx
+                 test/command/11944.docx
+                 test/command/11989.docx
+                 test/command/11991.docx
+                 test/command/11988.docx
+                 test/command/9222.docx
+                 test/command/9183.docx
                  test/command/11942.js
                  test/command/biblio.bib
                  test/command/averroes.bib
@@ -287,6 +296,9 @@
                  test/command/11888/section1/lab.md
                  test/command/11888/section2/lab.md
                  test/command/11888/section3/lab.md
+                 test/command/12001/note/doc.md
+                 test/command/12001/grid/doc.md
+                 test/command/12001/next/doc.md
                  test/asciidoc-reader.adoc
                  test/asciidoc-reader.native
                  test/asciidoc-reader-include.rb
@@ -444,8 +456,8 @@
                  test/pptx/*.pptx
                  test/pptx/**/*.pptx
                  test/pptx/**/*.native
-                 test/pptx-reader/basic.pptx
-                 test/pptx-reader/basic.native
+                 test/pptx-reader/*.pptx
+                 test/pptx-reader/*.native
                  test/ipynb/*.native
                  test/ipynb/*.in.native
                  test/ipynb/*.out.native
@@ -538,22 +550,22 @@
                  blaze-markup          >= 0.8      && < 0.9,
                  bytestring            >= 0.9      && < 0.13,
                  case-insensitive      >= 1.2      && < 1.3,
-                 citeproc              >= 0.14.1   && < 0.15,
-                 commonmark            >= 0.3.1    && < 0.4,
-                 commonmark-extensions >= 0.2.7.3  && < 0.3,
+                 citeproc              >= 0.14.2   && < 0.15,
+                 commonmark            >= 0.3.2    && < 0.4,
+                 commonmark-extensions >= 0.2.8    && < 0.3,
                  commonmark-pandoc     >= 0.3.0.2  && < 0.4,
                  containers            >= 0.6.0.1  && < 0.9,
-                 crypton               >= 0.30     && < 2.1,
+                 crypton               >= 1.0      && < 2.3,
                  data-default          >= 0.4      && < 0.9,
                  deepseq               >= 1.3      && < 1.6,
                  directory             >= 1.2.5    && < 1.4,
                  doclayout             >= 0.6      && < 0.7,
                  doctemplates          >= 0.11.1   && < 0.12,
-                 emojis                >= 0.1.5    && < 0.2,
+                 emojis                >= 0.1.6    && < 0.2,
                  exceptions            >= 0.8      && < 0.11,
                  file-embed            >= 0.0      && < 0.1,
                  filepath              >= 1.1      && < 1.6,
-                 gridtables            >= 0.1      && < 0.2,
+                 gridtables            >= 0.1.1.1  && < 0.2,
                  haddock-library       >= 1.10     && < 1.12,
                  http-types            >= 0.8      && < 0.13,
                  ipynb                 >= 0.2      && < 0.3,
@@ -567,25 +579,25 @@
                  random                >= 1.2      && < 1.4,
                  safe                  >= 0.3.18   && < 0.4,
                  scientific            >= 0.3      && < 0.4,
-                 skylighting           >= 0.15     && < 0.16,
-                 skylighting-core      >= 0.15     && < 0.16,
+                 skylighting           >= 0.15.0.1 && < 0.16,
+                 skylighting-core      >= 0.15.0.1 && < 0.16,
                  split                 >= 0.2      && < 0.3,
                  syb                   >= 0.1      && < 0.8,
                  tagsoup               >= 0.14.6   && < 0.15,
                  temporary             >= 1.1      && < 1.4,
-                 texmath               >= 0.13.3.1 && < 0.14,
+                 texmath               >= 0.13.3.5 && < 0.14,
                  text                  >= 2.0      && < 2.2,
                  text-conversions      >= 0.3      && < 0.4,
                  time                  >= 1.5      && < 1.17,
                  unicode-collation     >= 0.1.1    && < 0.2,
                  unicode-data          >= 0.6      && < 0.10,
                  unicode-transforms    >= 0.3      && < 0.5,
-                 yaml                  >= 0.11     && < 0.12,
-                 libyaml               >= 0.1.4    && < 0.2,
+                 yamlet                >= 1.0.0.1  && < 1.1,
+                 yamlet-aeson          >= 1.0.0.1  && < 1.1,
                  zip-archive           >= 0.5      && < 0.6,
                  zlib                  >= 0.6      && < 0.8,
                  xml                   >= 1.3.12   && < 1.4,
-                 typst                 >= 0.12     && < 0.13,
+                 typst                 >= 0.12.1   && < 0.13,
                  vector                >= 0.12     && < 0.14,
                  djot                  >= 0.1.4.3  && < 0.2,
                  asciidoc              >= 0.1.1    && < 0.2
@@ -599,11 +611,11 @@
      cpp-options:   -DPANDOC_HTTP_SUPPORT
      build-depends:
                  crypton-connection    >= 0.3.1    && < 0.5,
-                 crypton-x509-system   >= 1.6.7    && < 1.10,
+                 crypton-x509-system   >= 1.6.7    && < 1.11,
                  http-client           >= 0.4.30   && < 0.8,
                  http-client-tls       >= 0.2.4    && < 0.5,
                  network               >= 2.6      && < 3.3,
-                 tls                   >= 2.0.1    && < 2.5
+                 tls                   >= 2.0.1    && < 2.6
   hs-source-dirs:  src
 
   exposed-modules: Text.Pandoc,
@@ -759,6 +771,7 @@
                    Text.Pandoc.Readers.Docx.Symbols,
                    Text.Pandoc.Readers.Docx.Fields,
                    Text.Pandoc.Readers.OOXML.Shared,
+                   Text.Pandoc.Readers.OOXML.Charts,
                    Text.Pandoc.Readers.Pptx.Parse,
                    Text.Pandoc.Readers.Pptx.Shapes,
                    Text.Pandoc.Readers.Pptx.Slides,
@@ -877,6 +890,7 @@
                   Tests.Helpers
                   Tests.Shared
                   Tests.MediaBag
+                  Tests.Data
                   Tests.XML
                   Tests.ImageSize
                   Tests.Readers.LaTeX
@@ -944,7 +958,7 @@
   main-is:         benchmark-pandoc.hs
   hs-source-dirs:  benchmark
   build-depends:   bytestring,
-                   tasty-bench >= 0.4     && <= 0.5,
+                   tasty-bench >= 0.4     && <= 0.6,
                    mtl         >= 2.2     && < 2.4,
                    text        >= 2.0     && < 2.2,
                    temporary,
diff --git a/src/Text/Pandoc/App/CommandLineOptions.hs b/src/Text/Pandoc/App/CommandLineOptions.hs
--- a/src/Text/Pandoc/App/CommandLineOptions.hs
+++ b/src/Text/Pandoc/App/CommandLineOptions.hs
@@ -42,7 +42,7 @@
 import Safe (tailDef)
 import Skylighting (Syntax (..), defaultSyntaxMap)
 import System.Console.GetOpt
-import System.Environment (getArgs, getProgName)
+import System.Environment (getArgs, getProgName, lookupEnv)
 import System.Exit (exitSuccess)
 import System.FilePath
 import System.IO (stdout)
@@ -1457,10 +1457,12 @@
   let scriptingLine = case mbScriptingEngineName of
                         Nothing -> []
                         Just name -> ["Scripting engine: " ++ name]
+  mbPandocDirs <- System.Environment.lookupEnv "PANDOC_DATA_DIRS"
   UTF8.putStr $ T.unlines $ map T.pack $
     ["pandoc " ++ showVersion pandocVersion ++ suffix] ++
     featuresLine ++
     scriptingLine ++
-    ["User data directory: " ++ defaultDatadir,
-     copyrightMessage]
+    ["User data directory: " ++ defaultDatadir] ++
+    maybe [] (\d -> ["PANDOC_DATA_DIRS: " ++ d]) mbPandocDirs ++
+    [copyrightMessage]
   exitSuccess
diff --git a/src/Text/Pandoc/App/Opt.hs b/src/Text/Pandoc/App/Opt.hs
--- a/src/Text/Pandoc/App/Opt.hs
+++ b/src/Text/Pandoc/App/Opt.hs
@@ -1,6 +1,5 @@
 {-# LANGUAGE ScopedTypeVariables #-}
 {-# LANGUAGE OverloadedStrings   #-}
-{-# LANGUAGE CPP                 #-}
 {-# LANGUAGE DeriveGeneric       #-}
 {-# LANGUAGE PatternSynonyms     #-}
 {-# LANGUAGE TemplateHaskell     #-}
@@ -53,7 +52,8 @@
                             CiteMethod (Citeproc),
                             pattern DefaultHighlightingString)
 import Text.Pandoc.Class (readFileStrict, fileExists, setVerbosity, report,
-                          PandocMonad(lookupEnv), getUserDataDir)
+                          PandocMonad(lookupEnv), getUserDataDir,
+                          getPandocDataDirs)
 import Text.Pandoc.Error (PandocError (PandocParseError, PandocSomeError))
 import Data.Containers.ListUtils (nubOrd)
 import Text.Pandoc.Data (defaultUserDataDir)
@@ -67,11 +67,15 @@
 import qualified Data.Map as M
 import qualified Data.ByteString.Char8 as B8
 import Text.Pandoc.Definition (Meta(..), MetaValue(..))
-import Data.Aeson (defaultOptions, Options(..), Result(..),
-                   genericToJSON, fromJSON, camelTo2, eitherDecodeStrict)
 import Data.Aeson.TH (deriveJSON)
 import Control.Applicative ((<|>))
-import Data.Yaml
+import Data.Aeson
+import Data.Aeson.Types
+import qualified Data.Aeson.Key as K
+import qualified Data.List as L
+import qualified Data.List.NonEmpty as NE
+import qualified Yamlet as Y
+import Yamlet.Aeson
 
 -- | The type of line-endings to be used when writing plain-text.
 data LineEnding = LF | CRLF | Native deriving (Show, Generic)
@@ -357,11 +361,11 @@
       Success (opts :: M.Map Text Value) -> do
         dataDir <- case M.lookup "data-dir" opts of
           Nothing -> return Nothing
-          Just v -> Just . unpack <$> parseJSON v
+          Just v -> Just . unpack <$> parseJSON v <?> Key "data-dir"
         f <- parseOptions (M.toList opts)
         case M.lookup "defaults" opts of
           Just v -> do
-            g <- parseDefaults v dataDir
+            g <- parseDefaults v dataDir <?> Key "defaults"
             return  $ g >=> f >=> resolveVarsInOpt
           Nothing -> return $ f >=> resolveVarsInOpt
   parseJSON _ = fail "Expected a mapping"
@@ -541,7 +545,7 @@
     _ -> doOpt (k,v)
 
 doOpt :: (Text, Value) -> Parser (Opt -> Opt)
-doOpt (k,v) = do
+doOpt (k,v) = (<?> Key (K.fromText k)) $ do
   case k of
     "tab-stop" ->
       parseJSON v >>= \x -> return (\o -> o{ optTabStop = x })
@@ -938,11 +942,11 @@
          Left err' -> throwError $ PandocParseError $ T.pack $
             "Error parsing " <> file <> ":\n" <> err'
      else
-       case decodeEither' (B8.unlines . takeWhile (/= "...") . B8.lines $ inp) of
-           Right f -> f opt
-           Left err'  -> throwError $ PandocParseError $ T.pack $
+       case Y.decode (B8.unlines . takeWhile (/= "...") . B8.lines $ inp) of
+           Right (ViaAeson f) -> f opt
+           Left errs  -> throwError $ PandocParseError $ T.pack $
                   "Error parsing " <> file <> ":\n" <>
-                  Data.Yaml.prettyPrintParseException err'
+                  L.intercalate "\n" (map (Y.prettyError file) (NE.toList errs))
 
 fullDefaultsPath :: (PandocMonad m, MonadIO m)
                  => Maybe FilePath
@@ -950,17 +954,16 @@
                  -> m FilePath
 fullDefaultsPath dataDir file = do
   defaultDataDir <- liftIO defaultUserDataDir
-  let ddir = fromMaybe defaultDataDir dataDir </> "defaults"
+  pandocDataDirs <- getPandocDataDirs
+  let ddirs = map (</> "defaults") (fromMaybe defaultDataDir dataDir : pandocDataDirs)
   let findFile [] = return file
       findFile (fp:fps) = do
         fpExists <- fileExists fp
         if fpExists
            then return fp
            else findFile fps
-  findFile [file,
-            file <.> "yaml",
-            ddir </> file,
-            ddir </> file <.> "yaml"]
+  findFile $ [file, file <.> "yaml"] ++
+             concatMap (\ddir -> [ddir </> file, ddir </> file <.> "yaml"]) ddirs
 
 -- | In a list of lists, append another list in front of every list which
 -- starts with specific element.
diff --git a/src/Text/Pandoc/App/OutputSettings.hs b/src/Text/Pandoc/App/OutputSettings.hs
--- a/src/Text/Pandoc/App/OutputSettings.hs
+++ b/src/Text/Pandoc/App/OutputSettings.hs
@@ -1,4 +1,3 @@
-{-# LANGUAGE CPP                 #-}
 {-# LANGUAGE FlexibleContexts    #-}
 {-# LANGUAGE LambdaCase          #-}
 {-# LANGUAGE OverloadedStrings   #-}
diff --git a/src/Text/Pandoc/Citeproc.hs b/src/Text/Pandoc/Citeproc.hs
--- a/src/Text/Pandoc/Citeproc.hs
+++ b/src/Text/Pandoc/Citeproc.hs
@@ -24,6 +24,7 @@
 import qualified Text.Pandoc.Builder as B
 import Text.Pandoc.Definition as Pandoc
 import Text.Pandoc.Class (PandocMonad(..), getResourcePath, getUserDataDir,
+                          getPandocDataDirs,
                           fetchItem, report, setResourcePath, toTextM)
 import Text.Pandoc.Data (readDataFile)
 import Text.Pandoc.Error (PandocError(..))
@@ -132,9 +133,10 @@
   let getFile defaultExtension fp = do
         oldRp <- getResourcePath
         mbUdd <- getUserDataDir
-        setResourcePath $ oldRp ++ maybe []
-                                   (\u -> [u <> "/csl",
-                                           u <> "/csl/dependent"]) mbUdd
+        pandocDataDirs <- getPandocDataDirs
+        setResourcePath $ oldRp ++
+          concatMap (\u -> [u <> "/csl", u <> "/csl/dependent"])
+            (maybe id (:) mbUdd pandocDataDirs)
         let fp' = if T.any (=='.') fp || "data:" `T.isPrefixOf` fp
                      then fp
                      else fp <> defaultExtension
@@ -637,6 +639,8 @@
   case lastMay ils of
     Just (Span attr ils')
       -> initSafe ils ++ [Span attr (removeFinalPeriod ils')]
+    Just (Link attr ils' tgt)
+      -> initSafe ils ++ [Link attr (removeFinalPeriod ils') tgt]
     Just (Emph ils')
       -> initSafe ils ++ [Emph (removeFinalPeriod ils')]
     Just (Strong ils')
diff --git a/src/Text/Pandoc/Class/PandocMonad.hs b/src/Text/Pandoc/Class/PandocMonad.hs
--- a/src/Text/Pandoc/Class/PandocMonad.hs
+++ b/src/Text/Pandoc/Class/PandocMonad.hs
@@ -60,6 +60,8 @@
   , makeCanonical
   , findFileWithDataFallback
   , checkUserDataDir
+  , getDataDirs
+  , getPandocDataDirs
   ) where
 
 import Control.Monad.Except (MonadError (catchError, throwError))
@@ -75,8 +77,9 @@
 import Network.URI ( escapeURIString, nonStrictRelativeTo,
                      unEscapeString, parseURIReference, isAllowedInURI,
                      parseURI, URI(..) )
-import System.FilePath ((</>), takeExtension, dropExtension,
-                        isRelative, makeRelative, splitDirectories)
+import System.FilePath ((</>), takeExtension, dropExtension, isAbsolute,
+                        isRelative, makeRelative, splitDirectories,
+                        splitSearchPath)
 import System.Random (StdGen)
 import Text.Collate.Lang (Lang(..), parseLang)
 import Text.Pandoc.Class.CommonState (CommonState (..))
@@ -478,6 +481,27 @@
      then getUserDataDir
      else return Nothing
 
+-- | Returns the directories to search for a data file, in order of
+-- priority: the user data directory (if any), followed by the
+-- directories returned by 'getPandocDataDirs'.  Returns an empty list
+-- if the file path is absolute or relative to a parent directory.
+getDataDirs :: PandocMonad m => FilePath -> m [FilePath]
+getDataDirs fname =
+  if isRelative fname && not (isRelativeToParentDir fname)
+     then do
+       mbUserDataDir <- getUserDataDir
+       pandocDataDirs <- getPandocDataDirs
+       return $ maybe id (:) mbUserDataDir pandocDataDirs
+     else return []
+
+-- | Returns the directories listed in the @PANDOC_DATA_DIRS@
+-- environment variable, in order.  Relative paths (including
+-- empty entries) in @PANDOC_DATA_DIRS@ are ignored.
+getPandocDataDirs :: PandocMonad m => m [FilePath]
+getPandocDataDirs =
+  maybe [] (filter isAbsolute . splitSearchPath . T.unpack)
+    <$> lookupEnv "PANDOC_DATA_DIRS"
+
 -- | Read metadata file from the working directory or, if not found there, from
 -- the metadata subdirectory of the user data directory.
 readMetadataFile :: PandocMonad m => FilePath -> m B.ByteString
@@ -557,29 +581,29 @@
         Nothing -> Just (i, w)
 
 -- | Returns @fp@ if the file exists in the current directory; otherwise
--- searches for the data file relative to @/subdir/@. Returns @Nothing@
--- if neither file exists.
+-- searches for the data file relative to @/subdir/@ in the user data
+-- directory and then in the system data directories (see 'getDataDirs').
+-- Returns @Nothing@ if the file is not found.
 findFileWithDataFallback :: PandocMonad m
                          => FilePath  -- ^ subdir
                          -> FilePath  -- ^ fp
                          -> m (Maybe FilePath)
 findFileWithDataFallback subdir fp = do
   -- First we check to see if the file is found. If not, and if it's not
-  -- an absolute path, we check to see whether it's in @userdir/@. If
-  -- not, we leave it unchanged.
+  -- an absolute path, we check to see whether it's in @subdir@ of
+  -- one of the data directories. If not, we return Nothing.
   existsInWorkingDir <- fileExists fp
   if existsInWorkingDir
      then return $ Just fp
-     else do
-       mbDataDir <- checkUserDataDir fp
-       case mbDataDir of
-         Nothing -> return Nothing
-         Just datadir -> do
-           let datafp = datadir </> subdir </> fp
-           existsInDataDir <- fileExists datafp
-           return $ if existsInDataDir
-                    then Just datafp
-                    else Nothing
+     else getDataDirs fp >>= findFirst
+ where
+  findFirst [] = return Nothing
+  findFirst (d:ds) = do
+    let datafp = d </> subdir </> fp
+    exists <- fileExists datafp
+    if exists
+       then return $ Just datafp
+       else findFirst ds
 
 -- | Traverse tree, filling media bag for any images that
 -- aren't already in the media bag.
diff --git a/src/Text/Pandoc/Data.hs b/src/Text/Pandoc/Data.hs
--- a/src/Text/Pandoc/Data.hs
+++ b/src/Text/Pandoc/Data.hs
@@ -19,8 +19,8 @@
                         , getDataFileNames
                         , defaultUserDataDir
                         ) where
-import Text.Pandoc.Class (PandocMonad(..), checkUserDataDir, getTimestamp,
-                          getUserDataDir, getPOSIXTime)
+import Text.Pandoc.Class (PandocMonad(..), getDataDirs, getTimestamp,
+                          getPOSIXTime)
 import Data.Time.Clock.POSIX (utcTimeToPOSIXSeconds)
 import qualified Data.ByteString.Lazy as BL
 import qualified Data.ByteString as B
@@ -39,15 +39,31 @@
 import Paths_pandoc (getDataDir)
 #endif
 
--- | Read file from the default data files.
+-- | Read file from the default data files, ignoring the user data
+-- directory and @PANDOC_DATA_DIRS@.
 readDefaultDataFile :: PandocMonad m => FilePath -> m B.ByteString
-readDefaultDataFile "reference.docx" =
-  B.concat . BL.toChunks . fromArchive <$> getDefaultReferenceDocx
-readDefaultDataFile "reference.pptx" =
-  B.concat . BL.toChunks . fromArchive <$> getDefaultReferencePptx
-readDefaultDataFile "reference.odt" =
-  B.concat . BL.toChunks . fromArchive <$> getDefaultReferenceODT
 readDefaultDataFile fname =
+  case buildReferenceDoc readDefaultDataFile fname of
+    Just getArchive -> archiveToByteString <$> getArchive
+    Nothing -> readDefaultDataFile' fname
+
+-- | If the file is a reference document, returns an action that builds
+-- it from its component files, which are read using the supplied function.
+buildReferenceDoc :: PandocMonad m
+                  => (FilePath -> m B.ByteString) -> FilePath
+                  -> Maybe (m Archive)
+buildReferenceDoc readComponent fname =
+  case fname of
+    "reference.docx" -> Just $ getDefaultReferenceDocx readComponent
+    "reference.pptx" -> Just $ getDefaultReferencePptx readComponent
+    "reference.odt"  -> Just $ getDefaultReferenceODT readComponent
+    _                -> Nothing
+
+archiveToByteString :: Archive -> B.ByteString
+archiveToByteString = B.concat . BL.toChunks . fromArchive
+
+readDefaultDataFile' :: PandocMonad m => FilePath -> m B.ByteString
+readDefaultDataFile' fname =
 #ifdef EMBED_DATA_FILES
   case lookup (makeCanonical fname) dataFiles of
     Nothing       -> throwError $ PandocCouldNotFindDataFileError $ T.pack fname
@@ -66,22 +82,28 @@
      else throwError $ PandocCouldNotFindDataFileError $ T.pack fn
 #endif
 
---- | Read file from user data directory or,
---- if not found there, from the default data files.
+--- | Read file from user data directory or, if not found there,
+--- from one of the directories listed in @PANDOC_DATA_DIRS@,
+--- or, if not found there, from the default
+--- data files.  If a reference document (e.g. @reference.docx@)
+--- is not found, it is built from component files (e.g.
+--- @docx/word/styles.xml@), which are looked up in the same way.
 readDataFile :: PandocMonad m => FilePath -> m B.ByteString
-readDataFile fname = do
-  datadir <- checkUserDataDir fname
-  case datadir of
-       Nothing -> readDefaultDataFile fname
-       Just userDir -> do
-         exists <- fileExists (userDir </> fname)
-         if exists
-            then readFileStrict (userDir </> fname)
-            else readDefaultDataFile fname
+readDataFile fname = getDataDirs fname >>= go
+ where
+  go [] = case buildReferenceDoc readDataFile fname of
+            Just getArchive -> archiveToByteString <$> getArchive
+            Nothing -> readDefaultDataFile' fname
+  go (d:ds) = do
+    exists <- fileExists (d </> fname)
+    if exists
+       then readFileStrict (d </> fname)
+       else go ds
 
 -- | Retrieve default reference.docx.
-getDefaultReferenceDocx :: PandocMonad m => m Archive
-getDefaultReferenceDocx = do
+getDefaultReferenceDocx :: PandocMonad m
+                        => (FilePath -> m B.ByteString) -> m Archive
+getDefaultReferenceDocx readComponent = do
   let paths = ["[Content_Types].xml",
                "_rels/.rels",
                "docProps/app.xml",
@@ -101,24 +123,14 @@
   let toLazy = BL.fromChunks . (:[])
   let pathToEntry path = do
         epochtime <- floor . utcTimeToPOSIXSeconds <$> getTimestamp
-        contents <- toLazy <$> readDataFile ("docx/" ++ path)
+        contents <- toLazy <$> readComponent ("docx/" ++ path)
         return $ toEntry path epochtime contents
-  datadir <- getUserDataDir
-  mbArchive <- case datadir of
-                    Nothing   -> return Nothing
-                    Just d    -> do
-                       exists <- fileExists (d </> "reference.docx")
-                       if exists
-                          then return (Just (d </> "reference.docx"))
-                          else return Nothing
-  case mbArchive of
-     Just arch -> toArchive <$> readFileLazy arch
-     Nothing   -> foldr addEntryToArchive emptyArchive <$>
-                     mapM pathToEntry paths
+  foldr addEntryToArchive emptyArchive <$> mapM pathToEntry paths
 
 -- | Retrieve default reference.odt.
-getDefaultReferenceODT :: PandocMonad m => m Archive
-getDefaultReferenceODT = do
+getDefaultReferenceODT :: PandocMonad m
+                        => (FilePath -> m B.ByteString) -> m Archive
+getDefaultReferenceODT readComponent = do
   let paths = ["mimetype",
                "manifest.rdf",
                "styles.xml",
@@ -127,24 +139,14 @@
                "META-INF/manifest.xml"]
   let pathToEntry path = do epochtime <- floor `fmap` getPOSIXTime
                             contents <- (BL.fromChunks . (:[])) `fmap`
-                                          readDataFile ("odt/" ++ path)
+                                          readComponent ("odt/" ++ path)
                             return $ toEntry path epochtime contents
-  datadir <- getUserDataDir
-  mbArchive <- case datadir of
-                    Nothing   -> return Nothing
-                    Just d    -> do
-                       exists <- fileExists (d </> "reference.odt")
-                       if exists
-                          then return (Just (d </> "reference.odt"))
-                          else return Nothing
-  case mbArchive of
-     Just arch -> toArchive <$> readFileLazy arch
-     Nothing   -> foldr addEntryToArchive emptyArchive <$>
-                     mapM pathToEntry paths
+  foldr addEntryToArchive emptyArchive <$> mapM pathToEntry paths
 
 -- | Retrieve default reference.pptx.
-getDefaultReferencePptx :: PandocMonad m => m Archive
-getDefaultReferencePptx = do
+getDefaultReferencePptx :: PandocMonad m
+                        => (FilePath -> m B.ByteString) -> m Archive
+getDefaultReferencePptx readComponent = do
   -- We're going to narrow this down substantially once we get it
   -- working.
   let paths = [ "[Content_Types].xml"
@@ -201,20 +203,9 @@
   let toLazy = BL.fromChunks . (:[])
   let pathToEntry path = do
         epochtime <- floor <$> getPOSIXTime
-        contents <- toLazy <$> readDataFile ("pptx/" ++ path)
+        contents <- toLazy <$> readComponent ("pptx/" ++ path)
         return $ toEntry path epochtime contents
-  datadir <- getUserDataDir
-  mbArchive <- case datadir of
-                    Nothing   -> return Nothing
-                    Just d    -> do
-                       exists <- fileExists (d </> "reference.pptx")
-                       if exists
-                          then return (Just (d </> "reference.pptx"))
-                          else return Nothing
-  case mbArchive of
-     Just arch -> toArchive <$> readFileLazy arch
-     Nothing   -> foldr addEntryToArchive emptyArchive <$>
-                     mapM pathToEntry paths
+  foldr addEntryToArchive emptyArchive <$> mapM pathToEntry paths
 
 getDataFileNames :: IO [FilePath]
 getDataFileNames = do
diff --git a/src/Text/Pandoc/Extensions.hs b/src/Text/Pandoc/Extensions.hs
--- a/src/Text/Pandoc/Extensions.hs
+++ b/src/Text/Pandoc/Extensions.hs
@@ -1,4 +1,3 @@
-{-# LANGUAGE CPP                        #-}
 {-# LANGUAGE DeriveDataTypeable         #-}
 {-# LANGUAGE DeriveGeneric              #-}
 {-# LANGUAGE OverloadedStrings          #-}
@@ -542,7 +541,8 @@
     , Ext_xrefs_name
     , Ext_xrefs_number
     ]
-  getAll "odt"             = getAll "opendocument" <> autoIdExtensions
+  getAll "odt"             = getAll "opendocument" <> autoIdExtensions <>
+    extensionsFromList [ Ext_styles ]
   getAll "fodt"            = getAll "odt"
   getAll "muse"            = autoIdExtensions <>
     extensionsFromList
diff --git a/src/Text/Pandoc/Filter.hs b/src/Text/Pandoc/Filter.hs
--- a/src/Text/Pandoc/Filter.hs
+++ b/src/Text/Pandoc/Filter.hs
@@ -1,4 +1,3 @@
-{-# LANGUAGE CPP               #-}
 {-# LANGUAGE DeriveGeneric     #-}
 {-# LANGUAGE OverloadedStrings #-}
 {- |
diff --git a/src/Text/Pandoc/Image.hs b/src/Text/Pandoc/Image.hs
--- a/src/Text/Pandoc/Image.hs
+++ b/src/Text/Pandoc/Image.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE OverloadedStrings, ScopedTypeVariables, CPP #-}
+{-# LANGUAGE OverloadedStrings, ScopedTypeVariables #-}
 {- |
 Module      : Text.Pandoc.Image
 Copyright   : Copyright (C) 2020-2024 John MacFarlane
diff --git a/src/Text/Pandoc/MediaBag.hs b/src/Text/Pandoc/MediaBag.hs
--- a/src/Text/Pandoc/MediaBag.hs
+++ b/src/Text/Pandoc/MediaBag.hs
@@ -1,4 +1,3 @@
-{-# LANGUAGE CPP                        #-}
 {-# LANGUAGE OverloadedStrings          #-}
 {-# LANGUAGE DeriveDataTypeable         #-}
 {-# LANGUAGE GeneralizedNewtypeDeriving #-}
diff --git a/src/Text/Pandoc/Options.hs b/src/Text/Pandoc/Options.hs
--- a/src/Text/Pandoc/Options.hs
+++ b/src/Text/Pandoc/Options.hs
@@ -1,4 +1,3 @@
-{-# LANGUAGE CPP                #-}
 {-# LANGUAGE DeriveDataTypeable #-}
 {-# LANGUAGE DeriveGeneric      #-}
 {-# LANGUAGE LambdaCase         #-}
diff --git a/src/Text/Pandoc/PDF.hs b/src/Text/Pandoc/PDF.hs
--- a/src/Text/Pandoc/PDF.hs
+++ b/src/Text/Pandoc/PDF.hs
@@ -112,7 +112,7 @@
               >>= writer opts'
 
   verbosity <- getVerbosity
-  let compileHTML mkOutArgs = do
+  let compileHTML defaultOpts mkOutArgs = do
         -- check to see if there is anything in mediabag, and if so,
         -- make the HTML self contained
         mediabag <- getMediaBag
@@ -120,12 +120,12 @@
                       [] -> pure source
                       _ -> makeSelfContained source
         liftIO $
-          toPdfViaTempFile verbosity program pdfargs mkOutArgs ".html" source'
+          toPdfViaTempFile verbosity program (defaultOpts ++ pdfargs) mkOutArgs ".html" source'
   case takeBaseName program of
     "wkhtmltopdf" -> makeWithWkhtmltopdf program pdfargs writer opts' doc
-    "pagedjs-cli" -> compileHTML (\f -> ["-o", f])
-    "prince"      -> compileHTML (\f -> ["-o", f])
-    "weasyprint"  -> compileHTML (:[])
+    "pagedjs-cli" -> compileHTML [] (\f -> ["-o", f])
+    "prince"      -> compileHTML [] (\f -> ["-o", f])
+    "weasyprint"  -> compileHTML ["--presentational-hints"] (\f -> [f])
     "typst" -> liftIO $
         toPdfViaTempFile verbosity program ("compile":pdfargs) (:[]) ".typ" source
     "pdfroff" -> do
@@ -456,7 +456,8 @@
      let rerunWarnings = checkForRerun logContents
      tocFileExists <- fileExists (replaceExtension outfile ".toc")
        -- if we have a TOC we always need 3 runs, see #10308
-     let rerunWarnings' = rerunWarnings ++ ["TOC is present" | tocFileExists]
+     let rerunWarnings' = rerunWarnings ++
+           ["TOC is present" | tocFileExists, runNumber < 3]
      if not (null rerunWarnings') && runNumber < maxruns
         then do
           report $ MakePDFInfo "Rerun needed"
diff --git a/src/Text/Pandoc/Parsing/GridTable.hs b/src/Text/Pandoc/Parsing/GridTable.hs
--- a/src/Text/Pandoc/Parsing/GridTable.hs
+++ b/src/Text/Pandoc/Parsing/GridTable.hs
@@ -38,7 +38,8 @@
 import Text.Pandoc.Parsing.Capabilities
 import Text.Pandoc.Parsing.General
 import Text.Pandoc.Sources
-import Text.Parsec (Stream (..), ParsecT, optional, sepEndBy1, try)
+import Text.Parsec (Stream (..), ParsecT, getPosition, optional, sepEndBy1,
+                    setPosition, try)
 import Data.Maybe (mapMaybe)
 import qualified Data.Text as T
 import qualified Text.GridTable as GT
@@ -134,9 +135,10 @@
                -> ParsecT Sources st m (mf Blocks) -- ^ Block list parser
                -> ParsecT Sources st m (mf TableComponents)
 gridTableWith' normalization blocks = do
+  pos <- getPosition
   tbl <- GT.gridTable <* optional blanklines
   let blkTbl = GT.mapCells
-               (\lns -> parseFromString' blocks
+               (\lns -> parseFromString' (setPosition pos >> blocks)
                         . flip T.snoc '\n'  -- ensure proper block parsing
                         . T.unlines
                         . removeOneLeadingSpace
diff --git a/src/Text/Pandoc/Readers/Djot.hs b/src/Text/Pandoc/Readers/Djot.hs
--- a/src/Text/Pandoc/Readers/Djot.hs
+++ b/src/Text/Pandoc/Readers/Djot.hs
@@ -25,7 +25,8 @@
 import Text.Parsec.Pos (newPos)
 import Text.Pandoc.Options
 import Text.Pandoc.Definition
-import Text.Pandoc.Shared (addPandocAttributes, tshow, compactifyTable)
+import Text.Pandoc.Shared (addPandocAttributes, tshow, compactifyTable,
+                           paraToPlain)
 import qualified Text.Pandoc.UTF8 as UTF8
 import Djot (ParseOptions(..), SourcePosOption(..), parseDoc, Pos(..))
 import qualified Djot.AST as D
@@ -259,9 +260,6 @@
 
 toTight :: Blocks -> Blocks
 toTight (Many bls) = Many $ paraToPlain <$> bls
- where
-   paraToPlain (Para ils) = Plain ils
-   paraToPlain x = x
 
 toTaskListItem :: PandocMonad m
                => (D.TaskStatus, D.Blocks) -> ReaderT Env m Blocks
diff --git a/src/Text/Pandoc/Readers/DocBook.hs b/src/Text/Pandoc/Readers/DocBook.hs
--- a/src/Text/Pandoc/Readers/DocBook.hs
+++ b/src/Text/Pandoc/Readers/DocBook.hs
@@ -46,7 +46,7 @@
 import Text.Pandoc.Class.PandocMonad (PandocMonad, report)
 import Text.Pandoc.Options
 import Text.Pandoc.Logging (LogMessage(..))
-import Text.Pandoc.Shared (safeRead, addPandocAttributes)
+import Text.Pandoc.Shared (safeRead, addPandocAttributes, paraToPlain)
 import Text.Pandoc.Sources (ToSources(..), sourcesToText)
 import Text.Pandoc.Transforms (headerShift)
 import Text.TeXMath (readMathML, writeTeX)
@@ -1481,10 +1481,6 @@
 -- | Set the prefix of a name to 'Nothing'
 removePrefix :: QName -> QName
 removePrefix elname = elname { qPrefix = Nothing }
-
-paraToPlain :: Block -> Block
-paraToPlain (Para ils) = Plain ils
-paraToPlain x = x
 
 docbookEntityMap :: M.Map Text Text
 docbookEntityMap = M.fromList
diff --git a/src/Text/Pandoc/Readers/Docx.hs b/src/Text/Pandoc/Readers/Docx.hs
--- a/src/Text/Pandoc/Readers/Docx.hs
+++ b/src/Text/Pandoc/Readers/Docx.hs
@@ -1,4 +1,3 @@
-{-# LANGUAGE CPP               #-}
 {-# LANGUAGE OverloadedStrings #-}
 {-# LANGUAGE PatternGuards     #-}
 {-# LANGUAGE FlexibleContexts  #-}
@@ -60,6 +59,7 @@
        ) where
 
 import Codec.Archive.Zip
+import Control.Applicative ((<|>))
 import Control.Monad ( liftM, unless )
 import Control.Monad.Reader
     ( asks,
@@ -132,6 +132,11 @@
                      , docxListState :: M.Map (T.Text, T.Text) Integer
                      , docxPrevPara  :: Inlines
                      , docxReferences :: M.Map ItemId (Reference Inlines)
+                     -- the open list levels, innermost first, as
+                     -- (text indentation, level, numId); used to
+                     -- recognize unnumbered paragraphs continuing
+                     -- a list item
+                     , docxOpenListLevels :: [(Integer, T.Text, T.Text)]
                      }
 
 instance Default DState where
@@ -144,6 +149,7 @@
                , docxListState = M.empty
                , docxPrevPara  = mempty
                , docxReferences = mempty
+               , docxOpenListLevels = []
                }
 
 data DEnv = DEnv { docxOptions       :: ReaderOptions
@@ -270,6 +276,8 @@
   T.concat $ map parPartToText children
 parPartToText (ExternalHyperLink _ _ children) =
   T.concat $ map parPartToText children
+parPartToText (Field _ children) =
+  T.concat $ map parPartToText children
 parPartToText _                          = ""
 
 blacklistedCharStyles :: [CharStyleName]
@@ -323,7 +331,8 @@
             superscript . go rPr{rVertAlign = Nothing}
         | Just SubScrpt <- rVertAlign rPr =
             subscript . go rPr{rVertAlign = Nothing}
-        | Just "single" <- rUnderline rPr =
+        | Just u <- rUnderline rPr
+        , u /= "none" =
             Pandoc.underline . go rPr{rUnderline = Nothing}
         | otherwise = id
   return $ go rPr'
@@ -343,8 +352,8 @@
       let ils = smushInlines (map runElemToInlines runElems)
       transform <- runStyleToTransform rPr
       return $ transform ils
-runToInlines (Footnote bps) = note . smushBlocks <$> mapM bodyPartToBlocks bps
-runToInlines (Endnote bps) = note . smushBlocks <$> mapM bodyPartToBlocks bps
+runToInlines (Footnote bps) = note <$> notePartsToBlocks bps
+runToInlines (Endnote bps) = note <$> notePartsToBlocks bps
 runToInlines (InlineDrawing fp title alt bs ext) = do
   (lift . lift) $ P.insertMedia fp Nothing bs
   return $ imageWith (extentToAttr ext) (T.pack fp) title $ text alt
@@ -358,6 +367,19 @@
     showDim d = tshow (d / 914400) <> "in"
 extentToAttr _ = nullAttr
 
+-- A note is read in the middle of the paragraph that references it.
+-- Text held back from a paragraph whose mark is a tracked change
+-- (docxPrevPara) must therefore neither flow into the note from the
+-- body, nor out of the note into the referencing paragraph.
+notePartsToBlocks :: PandocMonad m => [BodyPart] -> DocxContext m Blocks
+notePartsToBlocks bps = do
+  outerPrevPara <- gets docxPrevPara
+  modify $ \s -> s { docxPrevPara = mempty }
+  blks <- smushBlocks <$> mapM bodyPartToBlocks bps
+  leftover <- gets docxPrevPara
+  modify $ \s -> s { docxPrevPara = outerPrevPara }
+  return $ if null leftover then blks else blks <> para leftover
+
 blocksToInlinesWarn :: PandocMonad m => T.Text -> Blocks -> DocxContext m Inlines
 blocksToInlinesWarn cmtId blks = do
   let paraOrPlain :: Block -> Bool
@@ -694,7 +716,17 @@
              | otherwise = c
 
 bodyPartToBlocks :: PandocMonad m => BodyPart -> DocxContext m Blocks
-bodyPartToBlocks (Heading n style pPr numId lvl mblvlInfo parparts) = do
+bodyPartToBlocks bp =
+  case bp of
+    Paragraph{} -> bodyPartToBlocks' bp
+    ListItem{}  -> bodyPartToBlocks' bp
+    -- anything else ends the open lists:
+    _ -> closeListLevels *> bodyPartToBlocks' bp <* closeListLevels
+ where
+  closeListLevels = modify $ \s -> s{ docxOpenListLevels = [] }
+
+bodyPartToBlocks' :: PandocMonad m => BodyPart -> DocxContext m Blocks
+bodyPartToBlocks' (Heading n style pPr numId lvl mblvlInfo parparts) = do
     ils <- local (\s-> s{docxInHeaderBlock=True})
            (smushInlines <$> mapM parPartToInlines parparts)
     let classes = map normalizeToClassName . delete style
@@ -712,7 +744,7 @@
          let start = case M.lookup (numId, lvl) listState of
                        Nothing -> case mblvlInfo of
                          Nothing -> 1
-                         Just (Level _ _ _ z) -> fromMaybe 1 z
+                         Just (Level _ _ _ z _) -> fromMaybe 1 z
                        Just z -> z + 1
          modify $ \st -> st{ docxListState =
              -- expire all the continuation data for lists of level > this one:
@@ -722,77 +754,28 @@
              in M.insert (numId, lvl) start
                   (M.filterWithKey notExpired listState) }
     makeHeaderAnchor $ headerWith ("", addNum classes, []) n ils
-bodyPartToBlocks (Paragraph pPr parparts) = do
-  let getMainPar
-        | Just True <- pBidi pPr = do
-            let pPr' = pPr { pBidi = Nothing }
-            local (\s -> s{ docxInBidi = True })
-              (bodyPartToBlocks (Paragraph pPr' parparts))
-        | isCodeDiv pPr = do
-            transform <- paragraphStyleToTransform pPr
-            return $
-              transform $
-              codeBlock $
-              T.concat $
-              map parPartToText parparts
-        | otherwise = do
-          ils <- trimSps . smushInlines <$> mapM parPartToInlines parparts
-          prevParaIls <- gets docxPrevPara
-          dropIls <- gets docxDropCap
-          let ils' = dropIls <> ils
-          let (paraOrPlain, pPr')
-                | hasStylesInheritedFrom ["Compact"] pPr = (plain, removeStyleNamed "Compact" pPr)
-                | otherwise = (para, pPr)
-          if dropCap pPr'
-            then do modify $ \s -> s { docxDropCap = ils' }
-                    return mempty
-            else do modify $ \s -> s { docxDropCap = mempty }
-                    let ils'' = (if null prevParaIls then mempty
-                                else prevParaIls <> space) <> ils'
-                        handleInsertion = do
-                          modify $ \s -> s {docxPrevPara = mempty}
-                          transform <- paragraphStyleToTransform pPr'
-                          return $ transform $ paraOrPlain ils''
-                    opts <- asks docxOptions
-                    case (pChange pPr', readerTrackChanges opts) of
-                        _ | null ils'', not (isEnabled Ext_empty_paragraphs opts) ->
-                          return mempty
-                        (Just (TrackedChange Insertion _), AcceptChanges) ->
-                            handleInsertion
-                        (Just (TrackedChange Insertion _), RejectChanges) -> do
-                            modify $ \s -> s {docxPrevPara = ils''}
-                            return mempty
-                        (Just (TrackedChange Insertion (ChangeInfo _ cAuthor cDate))
-                         , AllChanges) -> do
-                            let attr = ("", ["paragraph-insertion"], addAuthorAndDate cAuthor cDate)
-                                insertMark = spanWith attr mempty
-                            transform <- paragraphStyleToTransform pPr'
-                            return $ transform $
-                              paraOrPlain $ ils'' <> insertMark
-                        (Just (TrackedChange Deletion _), AcceptChanges) -> do
-                            modify $ \s -> s {docxPrevPara = ils''}
-                            return mempty
-                        (Just (TrackedChange Deletion _), RejectChanges) ->
-                            handleInsertion
-                        (Just (TrackedChange Deletion (ChangeInfo _ cAuthor cDate))
-                         , AllChanges) -> do
-                            let attr = ("", ["paragraph-deletion"], addAuthorAndDate cAuthor cDate)
-                                insertMark = spanWith attr mempty
-                            transform <- paragraphStyleToTransform pPr'
-                            return $ transform $
-                              paraOrPlain $ ils'' <> insertMark
-                        _ -> handleInsertion
-  (if pBottomBorder pPr
-      then (<> horizontalRule)
-      else id)
-    <$> getMainPar
-bodyPartToBlocks (ListItem pPr numId lvl isRestart (Just levelInfo) parparts) = do
+bodyPartToBlocks' (Paragraph pPr parparts) = do
+  openLevels <- gets docxOpenListLevels
+  let leftIndent = (indentation pPr >>= leftParIndent) <|>
+                   (pStyleIndentation pPr >>= leftParIndent)
+  -- An unnumbered paragraph indented like the text of an open list
+  -- item continues that item (this is how pandoc's docx writer and
+  -- Word's "List Continue" styles do multi-paragraph list items):
+  case break (\(ind, _, _) -> Just ind == leftIndent) openLevels of
+    (_, levels@((_, lvl, numId) : _)) | not (numbered pPr) -> do
+      modify $ \s -> s{ docxOpenListLevels = levels }
+      divWith ("", ["list-continuation"], [("level", lvl), ("num-id", numId)])
+        <$> paragraphToBlocks pPr{ indentation = Nothing } parparts
+    _ -> do
+      modify $ \s -> s{ docxOpenListLevels = [] }
+      paragraphToBlocks pPr parparts
+bodyPartToBlocks' (ListItem pPr numId lvl isRestart (Just levelInfo) parparts) = do
   -- We check whether this current abstract numbering id has previously been
   -- used, since Docx expects us to pick up where we left off -- unless this
   -- item explicitly restarts numbering (see #8367).
   listState <- gets docxListState
   let startFromState = M.lookup (numId, lvl) listState
-      Level _ fmt txt startFromLevelInfo = levelInfo
+      Level _ fmt txt startFromLevelInfo lvlIndent = levelInfo
       start = case startFromState of
         Just n | not isRestart -> n + 1
         _ -> fromMaybe 1 startFromLevelInfo
@@ -807,13 +790,20 @@
     -- a new level 1 list item resets continuation for level 2+
     let notExpired (_, lvl') _ = lvl' <= lvl
     in M.insert (numId, lvl) start (M.filterWithKey notExpired listState) }
-  blks <- bodyPartToBlocks (Paragraph pPr parparts)
+  -- record the indentation of the item's text, so that we can recognize
+  -- unnumbered paragraphs continuing this item:
+  let textIndent = (indentation pPr >>= leftParIndent) <|> lvlIndent <|>
+                   (pStyleIndentation pPr >>= leftParIndent)
+  modify $ \st -> st{ docxOpenListLevels =
+    maybe id (\ind -> ((ind, lvl, numId) :)) textIndent
+      (filter (\(_, lvl', _) -> lvl' < lvl) (docxOpenListLevels st)) }
+  blks <- paragraphToBlocks pPr parparts
   return $ divWith ("", ["list-item"], kvs) blks
-bodyPartToBlocks (ListItem pPr _ _ _ _ parparts) =
+bodyPartToBlocks' (ListItem pPr _ _ _ _ parparts) =
   let pPr' = pPr {pStyle = constructBogusParStyleData "list-paragraph": pStyle pPr}
   in
     bodyPartToBlocks $ Paragraph pPr' parparts
-bodyPartToBlocks (Captioned parstyle parparts bpart) = do
+bodyPartToBlocks' (Captioned parstyle parparts bpart) = do
   bs <- bodyPartToBlocks bpart
   captContents <- bodyPartToBlocks (Paragraph parstyle parparts)
   let capt = Caption Nothing (toList captContents)
@@ -830,9 +820,9 @@
           -> toCaptioned attr' bls'
         _ -> captContents
   pure $ toCaptioned nullAttr (toList bs)
-bodyPartToBlocks (Tbl _ _ _ _ []) =
+bodyPartToBlocks' (Tbl _ _ _ _ []) =
   return mempty
-bodyPartToBlocks (Tbl mbsty cap grid look parts) = do
+bodyPartToBlocks' (Tbl mbsty cap grid look parts) = do
   let fullCaption = if T.null cap then mempty else plain (text cap)
   let shortCaption = if T.null cap then Nothing else Just (toList (text cap))
       cap' = caption shortCaption fullCaption
@@ -847,11 +837,10 @@
       -- Horizontal column alignment is taken from the first row's cells.
       numcols = length widths
       getAlignment (Docx.Cell al colspan _ _) =
-        take numcols $ replicate (fromIntegral colspan) (convertAlign al) ++
-                       repeat Pandoc.AlignDefault
+        replicate (fromIntegral colspan) (convertAlign al)
       getAlignments (Docx.Row _ cs) = concatMap getAlignment cs
       alignments = take numcols $
-                   case hdr ++ rows of
+                   case rows ++ hdr of
                      [] -> repeat Pandoc.AlignDefault
                      r : _ -> getAlignments r
 
@@ -865,7 +854,75 @@
                  (TableHead nullAttr headerCells)
                  [TableBody nullAttr 0 [] bodyCells]
                  (TableFoot nullAttr [])
-bodyPartToBlocks HRule = pure Pandoc.horizontalRule
+bodyPartToBlocks' HRule = pure Pandoc.horizontalRule
+
+-- | Convert a paragraph (also used for the text of list items).
+paragraphToBlocks :: PandocMonad m
+                  => ParagraphStyle -> [ParPart] -> DocxContext m Blocks
+paragraphToBlocks pPr parparts = do
+  let getMainPar
+        | Just True <- pBidi pPr = do
+            let pPr' = pPr { pBidi = Nothing }
+            local (\s -> s{ docxInBidi = True })
+              (paragraphToBlocks pPr' parparts)
+        | isCodeDiv pPr = do
+            transform <- paragraphStyleToTransform pPr
+            return $
+              transform $
+              codeBlock $
+              T.concat $
+              map parPartToText parparts
+        | otherwise = do
+          ils <- trimSps . smushInlines <$> mapM parPartToInlines parparts
+          prevParaIls <- gets docxPrevPara
+          dropIls <- gets docxDropCap
+          let ils' = dropIls <> ils
+          let (paraOrPlain, pPr')
+                | hasStylesInheritedFrom ["Compact"] pPr = (plain, removeStyleNamed "Compact" pPr)
+                | otherwise = (para, pPr)
+          if dropCap pPr'
+            then do modify $ \s -> s { docxDropCap = ils' }
+                    return mempty
+            else do modify $ \s -> s { docxDropCap = mempty }
+                    let ils'' = (if null prevParaIls then mempty
+                                else prevParaIls <> space) <> ils'
+                        handleInsertion = do
+                          modify $ \s -> s {docxPrevPara = mempty}
+                          transform <- paragraphStyleToTransform pPr'
+                          return $ transform $ paraOrPlain ils''
+                    opts <- asks docxOptions
+                    case (pChange pPr', readerTrackChanges opts) of
+                        _ | null ils'', not (isEnabled Ext_empty_paragraphs opts) ->
+                          return mempty
+                        (Just (TrackedChange Insertion _), AcceptChanges) ->
+                            handleInsertion
+                        (Just (TrackedChange Insertion _), RejectChanges) -> do
+                            modify $ \s -> s {docxPrevPara = ils''}
+                            return mempty
+                        (Just (TrackedChange Insertion (ChangeInfo _ cAuthor cDate))
+                         , AllChanges) -> do
+                            let attr = ("", ["paragraph-insertion"], addAuthorAndDate cAuthor cDate)
+                                insertMark = spanWith attr mempty
+                            transform <- paragraphStyleToTransform pPr'
+                            return $ transform $
+                              paraOrPlain $ ils'' <> insertMark
+                        (Just (TrackedChange Deletion _), AcceptChanges) -> do
+                            modify $ \s -> s {docxPrevPara = ils''}
+                            return mempty
+                        (Just (TrackedChange Deletion _), RejectChanges) ->
+                            handleInsertion
+                        (Just (TrackedChange Deletion (ChangeInfo _ cAuthor cDate))
+                         , AllChanges) -> do
+                            let attr = ("", ["paragraph-deletion"], addAuthorAndDate cAuthor cDate)
+                                insertMark = spanWith attr mempty
+                            transform <- paragraphStyleToTransform pPr'
+                            return $ transform $
+                              paraOrPlain $ ils'' <> insertMark
+                        _ -> handleInsertion
+  (if pBottomBorder pPr
+      then (<> horizontalRule)
+      else id)
+    <$> getMainPar
 
 -- replace targets with generated anchors.
 rewriteLink' :: PandocMonad m => Inline -> DocxContext m Inline
diff --git a/src/Text/Pandoc/Readers/Docx/Combine.hs b/src/Text/Pandoc/Readers/Docx/Combine.hs
--- a/src/Text/Pandoc/Readers/Docx/Combine.hs
+++ b/src/Text/Pandoc/Readers/Docx/Combine.hs
@@ -191,6 +191,13 @@
   , CodeBlock attr' codeStr' :< cs' <- viewl (unMany cs)
   , attr == attr' =
       Many $ (bs' |> CodeBlock attr (codeStr <> "\n" <> codeStr')) >< cs'
+  -- with +styles, each code paragraph is wrapped in a custom-style Div (#9183)
+  | bs' :> Div divAttr [CodeBlock attr codeStr] <- viewr (unMany bs)
+  , Div divAttr' [CodeBlock attr' codeStr'] :< cs' <- viewl (unMany cs)
+  , divAttr == divAttr'
+  , attr == attr' =
+      Many $ (bs' |> Div divAttr [CodeBlock attr (codeStr <> "\n" <> codeStr')])
+        >< cs'
 combineBlocks bs cs = bs <> cs
 
 instance (Monoid a, Eq a) => Eq (Modifier a) where
diff --git a/src/Text/Pandoc/Readers/Docx/Lists.hs b/src/Text/Pandoc/Readers/Docx/Lists.hs
--- a/src/Text/Pandoc/Readers/Docx/Lists.hs
+++ b/src/Text/Pandoc/Readers/Docx/Lists.hs
@@ -32,6 +32,11 @@
 isListItem (Div (_, classes, _) _) | "list-item" `elem` classes = True
 isListItem _                       = False
 
+-- | An unnumbered paragraph continuing a list item.
+isListContinuation :: Block -> Bool
+isListContinuation (Div (_, classes, _) _) = "list-continuation" `elem` classes
+isListContinuation _                       = False
+
 getLevel :: Block -> Maybe Integer
 getLevel (Div (_, _, kvs) _) =  lookup "level" kvs >>= safeRead
 getLevel _                   = Nothing
@@ -115,6 +120,8 @@
 separateBlocks' b@(OrderedList _ _) acc = init acc ++ [last acc ++ [b]]
 -- The following is for the invisible bullet lists. This is how
 -- pandoc-generated ooxml does multiparagraph item lists.
+separateBlocks' b acc | isListContinuation b =
+  init acc ++ [last acc ++ [b]]
 separateBlocks' b acc | fmap trim (getText b) == Just "" =
   init acc ++ [last acc ++ [b]]
 separateBlocks' b acc = acc ++ [[b]]
@@ -219,6 +226,8 @@
     case delete "list-item" classes of
       []       -> blks
       classes' -> [Div (ident, classes', kvs) blks]
+removeListDivs' b@(Div _ blks)
+  | isListContinuation b = blks
 removeListDivs' (Div (ident, classes, kvs) blks)
   | not $ null $ listParagraphDivs `intersect` classes =
     case classes \\ listParagraphDivs of
diff --git a/src/Text/Pandoc/Readers/Docx/Parse.hs b/src/Text/Pandoc/Readers/Docx/Parse.hs
--- a/src/Text/Pandoc/Readers/Docx/Parse.hs
+++ b/src/Text/Pandoc/Readers/Docx/Parse.hs
@@ -249,8 +249,8 @@
 data AbstractNumb = AbstractNumb T.Text [Level]
                     deriving Show
 
---                 ilvl   format string  start
-data Level = Level T.Text T.Text T.Text (Maybe Integer)
+--                 ilvl   format string  start          left indent
+data Level = Level T.Text T.Text T.Text (Maybe Integer) (Maybe Integer)
   deriving Show
 
 data DocumentLocation = InDocument | InFootnote | InEndnote
@@ -620,9 +620,9 @@
   case lvlOverride of
     Just (LevelOverride _ _ (Just lvl')) -> Just lvl'
     Just (LevelOverride _ (Just strt) _) ->
-      lookup ilvl $ map (\(Level i fmt s _) -> (i, Level i fmt s (Just strt))) lvls
+      lookup ilvl $ map (\(Level i fmt s _ ind) -> (i, Level i fmt s (Just strt) ind)) lvls
     _ ->
-      lookup ilvl $ map (\l@(Level i _ _ _) -> (i, l)) lvls
+      lookup ilvl $ map (\l@(Level i _ _ _ _) -> (i, l)) lvls
 
 -- | Given a @numId@ and level, return the abstract numbering id (the stable
 -- identifier shared by all numbering instances based on the same abstract
@@ -690,7 +690,8 @@
       let start = findChildByName ns "w" "start" element
                   >>= findAttrByName ns "w" "val"
                   >>= stringToInteger
-      return (Level ilvl fmt txt start)
+      let ind = getIndentation ns element >>= leftParIndent
+      return (Level ilvl fmt txt start ind)
 levelElemToLevel _ _ = Nothing
 
 archiveToNumbering' :: Archive -> Maybe Numbering
@@ -703,7 +704,23 @@
           numElems = findChildrenByName namespaces "w" "num" numberingElem
           absNumElems = findChildrenByName namespaces "w" "abstractNum" numberingElem
           nums = mapMaybe (numElemToNum namespaces) numElems
-          absNums = mapMaybe (absNumElemToAbsNum namespaces) absNumElems
+          parsed = mapMaybe (\el -> (,) el <$> absNumElemToAbsNum namespaces el)
+                     absNumElems
+          linkVal name el = findChildByName namespaces "w" name el
+                            >>= findAttrByName namespaces "w" "val"
+          -- An abstractNum with w:numStyleLink has no levels of its own: they
+          -- are in the abstractNum whose w:styleLink names the same numbering
+          -- style (#9222).
+          levelsByStyle = M.fromList
+            [ (s, lvls) | (el, AbstractNumb _ lvls) <- parsed
+                        , Just s <- [linkVal "styleLink" el] ]
+          resolve (el, absNum@(AbstractNumb absNumId lvls))
+            | null lvls
+            , Just lvls' <- linkVal "numStyleLink" el
+                            >>= (`M.lookup` levelsByStyle)
+            = AbstractNumb absNumId lvls'
+            | otherwise = absNum
+          absNums = map resolve parsed
       return $ Numbering namespaces nums absNums
 
 archiveToNumbering :: Archive -> Numbering
@@ -763,9 +780,13 @@
         case sum xs of
           tot | tot > 1.0 -> map (/ tot) xs
           _ -> xs
-  normalizeFractions <$>
-    mapD (\e -> maybeToD (findAttrByName ns "w" "w" e >>=
-                          fmap toFraction . safeRead)) cols
+  -- w:w is optional. If a column has no width, we keep it but leave
+  -- every column's width unspecified (0), since writers don't handle
+  -- a mix of specified and unspecified widths well.
+  return $
+    case mapM (findAttrByName ns "w" "w" >=> safeRead) cols of
+      Just widths -> normalizeFractions (map toFraction widths)
+      Nothing -> replicate (length cols) 0
 elemToTblGrid _ _ = throwError WrongElem
 
 elemToTblLook :: NameSpaces -> Element -> D TblLook
@@ -1109,18 +1130,28 @@
           info <- eitherToD $ parseFieldInfo t
           modify $ \st -> st {stateFldCharState = FldCharContent info [] : ancestors}
           return []
+        -- A field with no instruction (e.g. a dead cross-reference, or
+        -- one whose w:instrText sits inside a tracked change):
+        FldCharOpen : ancestors | fldCharType == "separate" -> do
+          modify $ \st -> st {stateFldCharState = FldCharContent UnknownField [] : ancestors}
+          return []
         -- Some fields have no content, e.g. index XE:
         FldCharFieldInfo t : ancestors | fldCharType == "end" -> do
           modify $ \st -> st {stateFldCharState = ancestors}
           info <- eitherToD $ parseFieldInfo t
           return [Field info []]
-        [FldCharContent info children] | fldCharType == "end" -> do
-          modify $ \st -> st {stateFldCharState = []}
-          return [Field info $ reverse children]
+        FldCharOpen : ancestors | fldCharType == "end" -> do
+          modify $ \st -> st {stateFldCharState = ancestors}
+          return [Field UnknownField []]
         FldCharContent info children : FldCharContent parentInfo siblings : ancestors | fldCharType == "end" ->
           let parent = FldCharContent parentInfo $ (Field info (reverse children)) : siblings in do
             modify $ \st -> st {stateFldCharState = parent : ancestors}
             return []
+        -- Always pop the field, even if the enclosing field is not
+        -- (yet) in its content, so that the state cannot get stuck:
+        FldCharContent info children : ancestors | fldCharType == "end" -> do
+          modify $ \st -> st {stateFldCharState = ancestors}
+          return [Field info $ reverse children]
         _ -> throwError WrongElem
 elemToParPart ns element
   | isElem ns "w" "r" element
@@ -1204,7 +1235,7 @@
                 (matchQName "drawingml" "chart" (Just "c") "chart") drawingElem
   = return [Chart]
 elemToParPart' ns element
-  | isElem ns "w" "r" element = do
+  | isElem ns "w" "r" element || isElem ns "w" "customXml" element = do
     runs <- elemToRun ns element
     return $ map PlainRun runs
 elemToParPart' ns element
@@ -1212,6 +1243,12 @@
       runs <- mconcat <$> mapD (elemToParPart' ns) (elChildren element)
       return [ChangedRuns change runs]
 elemToParPart' ns element
+  | isElem ns "w" "fldSimple" element
+  , Just instr <- findAttrByName ns "w" "instr" element = do
+    info <- eitherToD $ parseFieldInfo instr
+    children <- mconcat <$> mapD (elemToParPart ns) (elChildren element)
+    return [Field info children]
+elemToParPart' ns element
   | isElem ns "w" "bookmarkStart" element
   , Just bmId <- findAttrByName ns "w" "id" element
   , Just bmName <- findAttrByName ns "w" "name" element =
@@ -1239,9 +1276,9 @@
 elemToParPart' ns element
   | isElem ns "w" "commentRangeStart" element
   , Just cmtId <- findAttrByName ns "w" "id" element = do
-      (Comments _ commentMap) <- asks envComments
+      (Comments cmtNs commentMap) <- asks envComments
       case M.lookup cmtId commentMap of
-        Just cmtElem -> elemToCommentStart ns cmtElem
+        Just cmtElem -> elemToCommentStart cmtNs cmtElem
         Nothing      -> throwError WrongElem
 elemToParPart' ns element
   | isElem ns "w" "commentRangeEnd" element
@@ -1310,17 +1347,17 @@
 childElemToRun ns element
   | isElem ns "w" "footnoteReference" element
   , Just fnId <- findAttrByName ns "w" "id" element = do
-    notes <- asks envNotes
+    notes@(Notes notesNs _ _) <- asks envNotes
     case lookupFootnote fnId notes of
-      Just e -> do bps <- local (\r -> r {envLocation=InFootnote}) $ mapD (elemToBodyPart ns) (elChildren e)
+      Just e -> do bps <- local (\r -> r {envLocation=InFootnote}) $ mapD (elemToBodyPart notesNs) (elChildren e)
                    return [Footnote bps]
       Nothing  -> return [Footnote []]
 childElemToRun ns element
   | isElem ns "w" "endnoteReference" element
   , Just enId <- findAttrByName ns "w" "id" element = do
-    notes <- asks envNotes
+    notes@(Notes notesNs _ _) <- asks envNotes
     case lookupEndnote enId notes of
-      Just e -> do bps <- local (\r -> r {envLocation=InEndnote}) $ mapD (elemToBodyPart ns) (elChildren e)
+      Just e -> do bps <- local (\r -> r {envLocation=InEndnote}) $ mapD (elemToBodyPart notesNs) (elChildren e)
                    return [Endnote bps]
       Nothing  -> return [Endnote []]
 childElemToRun _ _ = throwError WrongElem
@@ -1343,6 +1380,9 @@
     runElems <- elemToRunElems ns element
     runStyle <- elemToRunStyleD ns element
     return [Run runStyle runElems]
+elemToRun ns element
+  | isElem ns "w" "customXml" element =
+    mconcat <$> mapM (elemToRun ns) (elChildren element)
 elemToRun _ _ = throwError WrongElem
 
 getParentStyleValue :: (ParStyle -> Maybe a) -> ParStyle -> Maybe a
@@ -1513,11 +1553,14 @@
 stripCaptionLabel els =
     if null afters
        then els
-       else filter isBookmark befores <> afters
+       else filter isBookmark befores <> dropNumber afters
   where
     (befores, afters) = break isNumberElt els
     isBookmark (Element name _ _ _) =
       qName name == "bookmarkStart" || qName name == "bookmarkEnd"
+    -- A w:fldSimple carries the number as its result: drop it with the label.
+    dropNumber (el:rest) | qName (elName el) == "fldSimple" = rest
+    dropNumber rest = rest
     isNumberElt el@(Element name attribs _ _) =
        (qName name == "fldSimple" &&
              case lookupAttrBy ((== "instr") . qName) attribs of
diff --git a/src/Text/Pandoc/Readers/HTML.hs b/src/Text/Pandoc/Readers/HTML.hs
--- a/src/Text/Pandoc/Readers/HTML.hs
+++ b/src/Text/Pandoc/Readers/HTML.hs
@@ -66,7 +66,7 @@
 import Text.Pandoc.Parsing hiding ((<|>))
 import Text.Pandoc.Shared (
     addMetaField, extractSpaces, htmlSpanLikeElements, renderTags',
-    safeRead, tshow, formatCode)
+    safeRead, tshow, formatCode, plainToPara)
 import Text.Pandoc.URI (escapeURI)
 import Text.Pandoc.Walk
 import Text.TeXMath (readMathML, writeTeX)
@@ -310,7 +310,7 @@
        _ -> False)
   let attr = toStringAttr attr'
   let ident = fromMaybe "" (lookup "id" attr)
-  content <- pInTags tag block
+  content <- local (\s -> s{ inNoteBody = True }) $ pInTags tag block
   updateState $ \s ->
     s {noteTable = M.insert ident content (noteTable s)}
 
@@ -422,7 +422,11 @@
 pOrderedList :: PandocMonad m => TagParser m Blocks
 pOrderedList = try $ do
   TagOpen _ attribs' <- pSatisfy (matchTagOpen "ol" [])
-  isNoteList <- inFootnotes <$> getState
+  -- an <ol> inside the body of a note is an ordered list, not the
+  -- list of notes (#11852):
+  inNotes <- inFootnotes <$> getState
+  inBody <- asks inNoteBody
+  let isNoteList = inNotes && not inBody
   let attribs = toStringAttr attribs'
   let start = fromMaybe 1 $ lookup "start" attribs >>= safeRead
   let style = fromMaybe DefaultStyle
@@ -485,8 +489,6 @@
         isParaish OrderedList{}    = not inList
         isParaish DefinitionList{} = not inList
         isParaish _                = False
-        plainToPara (Plain xs) = Para xs
-        plainToPara x          = x
         bs' = B.toList bs
 
 pRawTag :: PandocMonad m => TagParser m Text
@@ -639,7 +641,8 @@
 pHrule = do
   pSelfClosing (=="hr") (const True)
   inNotes <- inFootnotes <$> getState
-  return $ if inNotes
+  inBody <- asks inNoteBody
+  return $ if inNotes && not inBody
               then mempty
               else B.horizontalRule
 
diff --git a/src/Text/Pandoc/Readers/HTML/Types.hs b/src/Text/Pandoc/Readers/HTML/Types.hs
--- a/src/Text/Pandoc/Readers/HTML/Types.hs
+++ b/src/Text/Pandoc/Readers/HTML/Types.hs
@@ -64,6 +64,7 @@
   , inChapter    :: Bool -- ^ Set if in chapter section
   , inPlain      :: Bool -- ^ Set if in pPlain
   , inListItem   :: Bool -- ^ Set if in <li> tag
+  , inNoteBody   :: Bool -- ^ Set if parsing the content of a footnote
   }
 
 
@@ -95,7 +96,7 @@
   deleteMeta s st = st {parserState = deleteMeta s $ parserState st}
 
 instance Default HTMLLocal where
-  def = HTMLLocal NoQuote False False False
+  def = HTMLLocal NoQuote False False False False
 
 instance HasLastStrPosition HTMLState where
   setLastStrPos s st = st {parserState = setLastStrPos s (parserState st)}
diff --git a/src/Text/Pandoc/Readers/LaTeX.hs b/src/Text/Pandoc/Readers/LaTeX.hs
--- a/src/Text/Pandoc/Readers/LaTeX.hs
+++ b/src/Text/Pandoc/Readers/LaTeX.hs
@@ -138,13 +138,15 @@
 
 -- | Resolve footnote marks (\footnotemark) to actual notes using
 -- the footnote texts collected from \footnotetext commands.
-resolveFootnoteMarks :: M.Map Int Blocks -> Inline -> Inline
+-- Marks inside the resolved note texts are resolved too (each text
+-- is used at most once, so this terminates).
+resolveFootnoteMarks :: M.Map Text Blocks -> Inline -> Inline
 resolveFootnoteMarks fnTexts (Span (_, classes, kvs) _)
   | "footnote-mark" `elem` classes
-  , Just numText <- lookup "note-num" kvs
-  , [(n, "")] <- reads (T.unpack numText)
-  = case M.lookup n fnTexts of
-      Just contents -> Note (toList contents)
+  , Just key <- lookup "note-key" kvs
+  = case M.lookup key fnTexts of
+      Just contents -> Note $ walk (resolveFootnoteMarks (M.delete key fnTexts))
+                            $ toList contents
       Nothing       -> Str ""  -- No matching footnotetext found
 resolveFootnoteMarks _ x = x
 
@@ -440,6 +442,8 @@
     , ("footnote", skipopts >> footnote)
     , ("footnotemark", footnotemark)
     , ("footnotetext", footnotetext)
+    , ("pandocfootnotemark", pandocfootnotemark)
+    , ("pandocfootnotetext", pandocfootnotetext)
     , ("newline", pure B.linebreak)
     -- xparse argument markers, in case they leak into the document:
     , ("NoValue", pure (B.str "-NoValue-"))
@@ -538,7 +542,7 @@
     Nothing -> do
       updateState $ \st -> st{ sLastNoteNum = sLastNoteNum st + 1 }
       sLastNoteNum <$> getState
-  return $ B.spanWith ("", ["footnote-mark"], [("note-num", tshow noteNum)]) mempty
+  return $ footnoteMarkSpan (tshow noteNum)
 
 -- | Parse \footnotetext[n]{text}. If n is not given, use current counter.
 -- Stores the text in state to be resolved later.
@@ -548,11 +552,51 @@
   noteNum <- case mbNum of
     Just n  -> return n
     Nothing -> sLastNoteNum <$> getState
+  storeFootnoteText (tshow noteNum)
+
+-- | Parse \pandocfootnotemark{id}, which is produced by the LaTeX writer
+-- for notes in tables, captions, etc. It is paired with
+-- \pandocfootnotetext{id}{text}.
+pandocfootnotemark :: PandocMonad m => LP m Inlines
+pandocfootnotemark = do
+  key <- untokenize <$> braced
+  updateState $ \st -> st{ sLastNoteNum = sLastNoteNum st + 1 }
+  return $ footnoteMarkSpan ("pandoc:" <> key)
+
+-- | Parse \pandocfootnotetext{id}{text}.
+pandocfootnotetext :: PandocMonad m => LP m Inlines
+pandocfootnotetext = do
+  key <- untokenize <$> braced
+  storeFootnoteText ("pandoc:" <> key)
+
+-- | A placeholder for a footnote mark, to be resolved later
+-- (see 'resolveFootnoteMarks').
+footnoteMarkSpan :: Text -> Inlines
+footnoteMarkSpan key = B.spanWith ("", ["footnote-mark"], [("note-key", key)]) mempty
+
+storeFootnoteText :: PandocMonad m => Text -> LP m Inlines
+storeFootnoteText key = do
   contents <- grouped block >>= walkM resolveNoteLabel
   updateState $ \st -> st{
-    sFootnoteTexts = M.insert noteNum contents (sFootnoteTexts st) }
+    sFootnoteTexts = M.insert key contents (sFootnoteTexts st) }
   return mempty
 
+-- | Parse \addtocounter{ctr}{n}. Adjustments to the footnote counter
+-- are tracked, so that \footnotetext gets the right number;
+-- otherwise the command is treated as raw LaTeX.
+addtocounter :: PandocMonad m => LP m Blocks
+addtocounter = do
+  (ctrAndNum, toks) <- withRaw $ (,) <$> (untokenize <$> braced)
+                                     <*> (untokenize <$> braced)
+  case ctrAndNum of
+    ("footnote", num) | Just n <- safeRead (T.strip num) -> do
+      updateState $ \st -> st{ sLastNoteNum = sLastNoteNum st + n }
+      return mempty
+    _ -> do
+      let raw = "\\addtocounter" <> untokenize toks
+      (guardEnabled Ext_raw_tex >> return (rawBlock "latex" raw))
+        <|> ignore raw
+
 -- | Parse optional footnote number argument [n]
 optionalFootnoteNum :: PandocMonad m => LP m (Maybe Int)
 optionalFootnoteNum = option Nothing $ do
@@ -765,7 +809,7 @@
    [ "special", "pdfannot", "pdfstringdef"
    , "bibliographystyle"
    , "maketitle", "makeindex", "makeglossary"
-   , "addcontentsline", "addtocontents", "addtocounter"
+   , "addcontentsline", "addtocontents"
       -- \ignore{} is used conventionally in literate haskell for definitions
       -- that are to be processed by the compiler but not printed.
    , "ignore"
@@ -1094,6 +1138,7 @@
 blockCommands :: PandocMonad m => M.Map Text (LP m Blocks)
 blockCommands = M.fromList
    [ ("par", mempty <$ skipopts)
+   , ("addtocounter", addtocounter)
    , ("parbox",  parbox)
    , ("title", mempty <$ (skipopts *>
                              (grouped inline >>= addMeta "title")
diff --git a/src/Text/Pandoc/Readers/LaTeX/Macro.hs b/src/Text/Pandoc/Readers/LaTeX/Macro.hs
--- a/src/Text/Pandoc/Readers/LaTeX/Macro.hs
+++ b/src/Text/Pandoc/Readers/LaTeX/Macro.hs
@@ -36,7 +36,9 @@
             newDocumentEnvironment <|> commandCopy <|> environmentCopy <|>
             checkGlobal (letmacro <|> edefmacro <|> defmacro <|> newif)
           guardDisabled Ext_latex_macros <|>
-            mapM_ insertMacro nameMacroPairs
+            mapM_ insertMacro
+              (filter ((`Set.notMember` pandocInternalMacros) . fst)
+                      nameMacroPairs)
         environmentDef = do
           mbenv <- newenvironment
           case mbenv of
@@ -49,6 +51,13 @@
         -- is equivalent to
         -- @\newcommand{\envname}[n-args][default]{begin}@
         -- @\newcommand{\endenvname}@
+
+-- | Macros defined in pandoc's LaTeX template and handled directly
+-- by the reader. Their definitions are too complex for the reader's
+-- macro expansion, so we ignore them.
+pandocInternalMacros :: Set.Set Text
+pandocInternalMacros = Set.fromList
+  [ "pandocbounded", "pandocfootnotemark", "pandocfootnotetext" ]
 
 -- | Control sequences that can begin a macro definition.  This
 -- must include every control sequence that one of the parsers
diff --git a/src/Text/Pandoc/Readers/LaTeX/Parsing.hs b/src/Text/Pandoc/Readers/LaTeX/Parsing.hs
--- a/src/Text/Pandoc/Readers/LaTeX/Parsing.hs
+++ b/src/Text/Pandoc/Readers/LaTeX/Parsing.hs
@@ -170,7 +170,10 @@
                             , sLastFigureNum :: DottedNum
                             , sLastTableNum  :: DottedNum
                             , sLastNoteNum   :: Int
-                            , sFootnoteTexts :: M.Map Int Blocks
+                            , sFootnoteTexts :: M.Map Text Blocks
+                              -- ^ keys are footnote numbers for
+                              -- \footnotetext and "pandoc:" ids for
+                              -- \pandocfootnotetext
                             , sTheoremMap    :: M.Map Text TheoremSpec
                             , sLastTheoremStyle :: TheoremStyle
                             , sLastLabel     :: Maybe Text
@@ -191,6 +194,11 @@
                             , sCaseExclusions :: M.Map Text (Set.Set Text)
                               -- ^ words excluded from case changing
                               -- (keys: @upper@, @lower@, @title@)
+                            , sLastExpansion :: Maybe (Text, SourcePos, Int)
+                              -- ^ name and position of the last macro
+                              -- expanded, and the number of consecutive
+                              -- times it has been expanded there
+                              -- (used to detect expansion loops)
                             }
      deriving Show
 
@@ -225,6 +233,7 @@
                               , sRawScopes     = 0
                               , sLigatures     = True
                               , sCaseExclusions = M.empty
+                              , sLastExpansion = Nothing
                               }
 
 instance PandocMonad m => HasQuoteContext LaTeXState m where
@@ -344,7 +353,7 @@
                 updateState (updateMacros ((NonEmpty.head (sMacros st)) <>))
                 let rawChar = do
                       pos <- getPosition
-                      if pos >= endpos
+                      if sourceName pos == sourceName endpos && pos >= endpos
                          then mzero
                          else anyChar
                 result <- (guardEnabled Ext_latex_macros
@@ -455,11 +464,10 @@
                                Just ('\n', _) ->
                                  Tok pos (CtrlSeq " ") ("\\" <> w1)
                                  : totoks atIsLetter
-                                    (incSourceColumn pos (T.length ws)) r1
+                                    (incSourceColumn pos (1 + T.length w1)) r1
                                _ ->
                                  Tok pos (CtrlSeq " ") ws
-                                 : totoks atIsLetter
-                                    (incSourceColumn pos (T.length ws)) r3
+                                 : totoks atIsLetter (advancePos pos ws) r3
                   | otherwise  ->
                       Tok pos (CtrlSeq (T.singleton d)) (T.pack [c,d])
                       : totoks atIsLetter (incSourceColumn pos 2) rest'
@@ -512,6 +520,12 @@
            Tok pos Symbol (T.singleton c) :
              totoks atIsLetter (incSourceColumn pos 1) rest
 
+  -- Keep tabs at one column, as in the rest of the tokenizer.
+  advancePos = T.foldl' $ \pos c ->
+    if c == '\n'
+       then setSourceColumn (incSourceLine pos 1) 1
+       else incSourceColumn pos 1
+
 isSpaceOrTab :: Char -> Bool
 isSpaceOrTab ' '  = True
 isSpaceOrTab '\t' = True
@@ -752,6 +766,18 @@
            -- macro call, so we continue expanding:
            Nothing -> trySpecialMacro name ts >>= doMacros' (n' + 1)
            Just (Macro _scope expansionPoint argspecs optarg newtoks) -> do
+             -- A macro whose expansion contains itself after an
+             -- unknown command (e.g. \def\small{\@setfontsize\small..})
+             -- would be expanded again and again at the same position,
+             -- each time in a fresh call to doMacros (#11088):
+             lastExp <- sLastExpansion <$> getState
+             let expCount = case lastExp of
+                              Just (name', spos', i)
+                                | name' == name, spos' == spos -> i + 1
+                              _ -> 1 :: Int
+             when (expCount > 1000) $ throwError $ PandocMacroLoop name
+             updateState $ \st -> st{ sLastExpansion =
+                                        Just (name, spos, expCount) }
              let getargs' = do
                    args <-
                      (case expansionPoint of
diff --git a/src/Text/Pandoc/Readers/Markdown.hs b/src/Text/Pandoc/Readers/Markdown.hs
--- a/src/Text/Pandoc/Readers/Markdown.hs
+++ b/src/Text/Pandoc/Readers/Markdown.hs
@@ -466,7 +466,7 @@
      rest <- many $ try $ blanklines >> indentSpaces >> rawLines
      let raw = T.unlines (first:rest) <> "\n"
      optional blanklines
-     parsed <- parseFromString' parseBlocks raw
+     parsed <- parseFromString' (setPosition pos >> parseBlocks) raw
      oldnotes <- stateNotes' <$> getState
      case M.lookup ref oldnotes of
        Just _  -> logMessage $ DuplicateNoteReference ref pos
@@ -1038,10 +1038,6 @@
               ((if isTight
                    then fmap (fmap (fmap paraToPlain))
                    else id) (sequence contents))
-
-paraToPlain :: Block -> Block
-paraToPlain (Para ils) = Plain ils
-paraToPlain x = x
 
 definitionList :: PandocMonad m => MarkdownParser m (F Blocks)
 definitionList = try $ do
diff --git a/src/Text/Pandoc/Readers/Metadata.hs b/src/Text/Pandoc/Readers/Metadata.hs
--- a/src/Text/Pandoc/Readers/Metadata.hs
+++ b/src/Text/Pandoc/Readers/Metadata.hs
@@ -1,5 +1,6 @@
 {-# LANGUAGE OverloadedStrings   #-}
 {-# LANGUAGE ScopedTypeVariables #-}
+{-# LANGUAGE TypeApplications    #-}
 {- |
    Module      : Text.Pandoc.Readers.Metadata
    Copyright   : Copyright (C) 2006-2024 John MacFarlane
@@ -20,24 +21,22 @@
 
 import Control.Monad.Except (throwError)
 import qualified Data.ByteString as B
+import qualified Data.List as L
 import qualified Data.Map as M
 import qualified Data.Vector as V
 import Data.Text (Text)
 import qualified Data.Text as T
-import qualified Data.Yaml as Yaml
-import qualified Data.Yaml.Internal as Yaml
-import qualified Text.Libyaml as Y
-import Data.Aeson (Value(..), Object, Result(..), fromJSON, (.:?), withObject,
-                   FromJSON)
-import Data.Aeson.Types (formatRelativePath, parse)
+import qualified Data.List.NonEmpty as NE
+import qualified Yamlet as Y
+import Yamlet.Aeson ()
+import Data.Aeson (Value(..), Object, Result(..), fromJSON, (.:?), withObject)
+import Data.Aeson.Types (parse)
 import Text.Pandoc.Shared (tshow, blocksToInlines)
-import Text.Pandoc.Class (PandocMonad (..), report)
+import Text.Pandoc.Class (PandocMonad (..))
 import Text.Pandoc.Definition
 import Text.Pandoc.Error
-import Text.Pandoc.Logging (LogMessage(YamlWarning))
 import Text.Pandoc.Parsing hiding (tableWith, parse)
 import qualified Text.Pandoc.UTF8 as UTF8
-import System.IO.Unsafe (unsafePerformIO)
 
 yamlBsToMeta :: (PandocMonad m, HasLastStrPosition st)
              => ParsecT Sources st m (Future st MetaValue)
@@ -45,37 +44,28 @@
              -> ParsecT Sources st m (Future st Meta)
 yamlBsToMeta pMetaValue bstr = do
   pos <- getPosition
-  case decodeAllWithWarnings bstr of
-       Right (warnings, xs) -> do
-         mapM_ (\(Yaml.DuplicateKey jpath) ->
-                          report (YamlWarning pos $ "Duplicate key: " <>
-                                  T.pack (formatRelativePath jpath)))
-           warnings
+  case Y.decodeAll @Value bstr of
+       Right xs ->
          case xs of
            (Object o : _) -> fmap Meta <$> yamlMap pMetaValue o
            [Null] -> return . return $ mempty
            [] -> return . return $ mempty
            _  -> Prelude.fail "expected YAML object"
-       Left err' -> do
-         let msg = T.pack $ "Error parsing YAML metadata at " <>
-                             show pos <> ":\n" <>
-                             Yaml.prettyPrintParseException err'
-         throwError $ PandocParseError $
-           if "did not find expected key" `T.isInfixOf` msg
-              then msg <>
-                   "\nConsider enclosing the entire field in 'single quotes'"
-              else msg
+       Left errs -> throwError $ PandocParseError $ T.pack $
+         "Error parsing YAML metadata at " <> show pos <> ":\n" <>
+         renderYamlErrors pos errs
 
-decodeAllWithWarnings :: FromJSON a
-                      => B.ByteString
-                      -> (Either Yaml.ParseException ([Yaml.Warning], [a]))
-decodeAllWithWarnings = either Left (\(ws,res)
-                       -> case res of
-                            Left s  -> Left (Yaml.AesonException s)
-                            Right v -> Right (ws, v))
-                   . unsafePerformIO
-                   . Yaml.decodeAllHelper
-                   . Y.decode
+-- | Render the errors with their lines in the source, given the position of
+-- the first line of the YAML input.
+renderYamlErrors :: SourcePos -> NE.NonEmpty Y.Error -> String
+renderYamlErrors pos =
+  L.intercalate "\n" . map (Y.prettyError (sourceName pos) . shift) . NE.toList
+  where
+    shift :: Y.Error -> Y.Error
+    shift err@Y.Error{Y.location = loc@Y.Location{Y.line = l}}
+      -- Line 0 means that the error has no position.
+      | l == 0 = err
+      | otherwise = err{Y.location = loc{Y.line = l + sourceLine pos - 1}}
 
 -- Returns filtered list of references.
 yamlBsToRefs :: (PandocMonad m, HasLastStrPosition st)
@@ -83,8 +73,9 @@
              -> (Text -> Bool) -- ^ Filter for id
              -> B.ByteString
              -> ParsecT Sources st m (Future st [MetaValue])
-yamlBsToRefs pMetaValue idpred bstr =
-  case Yaml.decodeAllEither' bstr of
+yamlBsToRefs pMetaValue idpred bstr = do
+  pos <- getPosition
+  case Y.decodeAll @Value bstr of
        Right (Object m : _) -> do
          case parse (withObject "metadata" (.:? "references")) (Object m) of
            Success (Just refs) -> sequence <$>
@@ -94,8 +85,8 @@
          let refs = filter hasSelectedId $ V.toList v
          sequence <$> mapM (yamlToMetaValue pMetaValue) (filter hasSelectedId refs)
        Right _ -> return . return $ []
-       Left err' -> throwError $ PandocParseError
-                               $ T.pack $ Yaml.prettyPrintParseException err'
+       Left errs -> throwError $ PandocParseError
+                               $ T.pack $ renderYamlErrors pos errs
  where
    isSelected (String t) = idpred t
    isSelected _ = False
diff --git a/src/Text/Pandoc/Readers/ODT.hs b/src/Text/Pandoc/Readers/ODT.hs
--- a/src/Text/Pandoc/Readers/ODT.hs
+++ b/src/Text/Pandoc/Readers/ODT.hs
@@ -61,10 +61,10 @@
          => ReaderOptions
          -> a
          -> m Pandoc
-readFODT _ inp = do
+readFODT opts inp = do
   root <- either (throwError . PandocXMLError "") pure
             (parseXMLElement (TL.fromStrict (sourcesToText (toSources inp))))
-  case elementToODT root of
+  case elementToODT opts root of
     Right (doc, mb) -> do
       P.setMediaBag mb
       return $ walk makeFigure doc
@@ -74,8 +74,8 @@
 -- package distributes over @content.xml@ and @styles.xml@, and they are
 -- all children of the root.  The converter addresses everything relative
 -- to the element it is given, so it can simply be handed that root.
-elementToODT :: Element -> Either PandocError (Pandoc, MediaBag)
-elementToODT root = do
+elementToODT :: ReaderOptions -> Element -> Either PandocError (Pandoc, MediaBag)
+elementToODT opts root = do
   -- the local name only, consistently with the URI-based namespace
   -- matching downstream; office:document-content is correctly rejected
   unless (XML.qName (XML.elName root) == "document") $
@@ -87,7 +87,8 @@
                (readStylesAt root)
   -- the media list is empty: all media arrives in office:binary-data
   either (\_ -> Left $ PandocParseError "Could not convert opendocument") Right
-    (runConverter read_body (readerState styles []) root)
+    (runConverter read_body
+       (readerState (isEnabled Ext_styles opts) styles []) root)
 
 -- the ODT parser uses old-style figures: an image with title beginning
 -- "fig:" in a paragraph by itself.  Convert these to new Figure elements.
@@ -108,20 +109,14 @@
 readODT' :: ReaderOptions
          -> B.ByteString
          -> Either PandocError (Pandoc, MediaBag)
-readODT' _ bytes = bytesToODT bytes-- of
---                    Right (pandoc, mediaBag) -> Right (pandoc , mediaBag)
---                    Left  err                -> Left err
-
---
-bytesToODT :: B.ByteString -> Either PandocError (Pandoc, MediaBag)
-bytesToODT bytes = case toArchiveOrFail bytes of
-  Right archive -> archiveToODT archive
+readODT' opts bytes = case toArchiveOrFail bytes of
+  Right archive -> archiveToODT opts archive
   Left err      -> Left $ PandocParseError
                         $ "Could not unzip ODT: " <> T.pack err
 
 --
-archiveToODT :: Archive -> Either PandocError (Pandoc, MediaBag)
-archiveToODT archive = do
+archiveToODT :: ReaderOptions -> Archive -> Either PandocError (Pandoc, MediaBag)
+archiveToODT opts archive = do
   let onFailure msg Nothing = Left $ PandocParseError msg
       onFailure _   (Just x) = Right x
   contentEntry <- onFailure "Could not find content.xml"
@@ -139,7 +134,7 @@
         let (dir, name) = splitFileName fp
         in  (dir == "Pictures/") || (dir /= "./" && name == "content.xml")
   let media = filteredFilesFromArchive archive filePathIsODTMedia
-  let startState = readerState styles media
+  let startState = readerState (isEnabled Ext_styles opts) styles media
   either (\_ -> Left $ PandocParseError "Could not convert opendocument") Right
     (runConverter read_body startState contentElem)
 
diff --git a/src/Text/Pandoc/Readers/ODT/ContentReader.hs b/src/Text/Pandoc/Readers/ODT/ContentReader.hs
--- a/src/Text/Pandoc/Readers/ODT/ContentReader.hs
+++ b/src/Text/Pandoc/Readers/ODT/ContentReader.hs
@@ -74,18 +74,21 @@
                  , styleTrace       :: [Style]
                    -- | Keeps track of the current depth in nested lists
                  , currentListLevel :: ListLevel
-                   -- | Keeps track of the previous list start counters,
-                   -- so whenever a new list continues numbering,
-                   -- we know what number to start from.
-                   -- If  list does not continue numbering, the counter
-                   -- is being reset.
-                 , listContinuationStartCounters :: M.Map ListLevel Int
+                   -- | Keeps track of the previous list start counters
+                   -- for each list style and level, so whenever a new
+                   -- list continues numbering, we know what number to
+                   -- start from. The counters for deeper levels are
+                   -- reset whenever a new list item starts.
+                 , listContinuationStartCounters
+                     :: M.Map (Maybe StyleName, ListLevel) Int
                    -- | Lists may provide their own style, but they don't have
                    -- to. If they do not, the style of a parent list may be used
                    -- or even a default list style from the paragraph style.
                    -- This value keeps track of the closest list style there
                    -- currently is.
                  , currentListStyle :: Maybe ListStyle
+                   -- | The name of 'currentListStyle', if known.
+                 , currentListStyleName :: Maybe StyleName
                    -- | A map from internal anchor names to "pretty" ones.
                    -- The mapping is a purely cosmetic one.
                  , bookmarkAnchors  :: M.Map Anchor Anchor
@@ -98,13 +101,16 @@
                  , envMedia         :: Media
                    -- | Hold binary resources used in the document
                  , odtMediaBag      :: MediaBag
+                   -- | Whether to record named styles in @custom-style@
+                   -- attributes (the @styles@ extension)
+                 , keepStyles       :: Bool
                  }
   deriving ( Show )
 
-readerState :: Styles -> [(FilePath, B.ByteString)] -> ReaderState
-readerState styles media =
-  ReaderState styles [] 0 M.empty Nothing M.empty Set.empty
-              (M.fromList media) mempty
+readerState :: Bool -> Styles -> [(FilePath, B.ByteString)] -> ReaderState
+readerState keepStyles' styles media =
+  ReaderState styles [] 0 M.empty Nothing Nothing M.empty Set.empty
+              (M.fromList media) mempty keepStyles'
 
 --
 pushStyle'  :: Style -> ReaderState -> ReaderState
@@ -120,10 +126,21 @@
 modifyListLevel f state = state { currentListLevel = f (currentListLevel state) }
 
 --
-modifyListContinuationStartCounter :: ListLevel -> Int -> (ReaderState -> ReaderState)
-modifyListContinuationStartCounter listLevel count state =
-    state { listContinuationStartCounters = M.insert listLevel count (listContinuationStartCounters state) }
+modifyListContinuationStartCounter :: Maybe StyleName -> ListLevel -> Int
+                                   -> (ReaderState -> ReaderState)
+modifyListContinuationStartCounter mStyleName listLevel count state =
+    state { listContinuationStartCounters =
+              M.insert (mStyleName, listLevel) count
+                (listContinuationStartCounters state) }
 
+-- | Reset the counters of all list levels deeper than the given one.
+resetDeeperListContinuationStartCounters :: ListLevel
+                                         -> (ReaderState -> ReaderState)
+resetDeeperListContinuationStartCounters listLevel state =
+    state { listContinuationStartCounters =
+              M.filterWithKey (\(_, lvl) _ -> lvl <= listLevel)
+                (listContinuationStartCounters state) }
+
 --
 shiftListLevel :: ListLevel -> (ReaderState -> ReaderState)
 shiftListLevel diff = modifyListLevel (+ diff)
@@ -169,11 +186,13 @@
 lookupListStyle name = getStyles >>= fromMaybeF . lookupListStyleByName name
 
 --
-switchCurrentListStyle :: Maybe ListStyle -> ODTReader (Maybe ListStyle)
+switchCurrentListStyle :: Maybe (StyleName, ListStyle)
+                       -> ODTReader (Maybe (StyleName, ListStyle))
 switchCurrentListStyle mListStyle = do
   state <- getExtraState
-  setExtraState $ state { currentListStyle = mListStyle }
-  return $ currentListStyle state
+  setExtraState $ state { currentListStyle = snd <$> mListStyle
+                        , currentListStyleName = fst <$> mListStyle }
+  return $ (,) <$> currentListStyleName state <*> currentListStyle state
 
 --
 pushStyle :: Style -> ODTReader ()
@@ -188,9 +207,10 @@
 getCurrentListLevel = currentListLevel <$> getExtraState
 
 --
-getPreviousListStartCounter :: ListLevel -> ODTReader Int
-getPreviousListStartCounter listLevel =
-  M.findWithDefault 0 listLevel . listContinuationStartCounters
+getPreviousListStartCounter :: Maybe StyleName -> ListLevel
+                            -> ODTReader (Maybe Int)
+getPreviousListStartCounter mStyleName listLevel =
+  M.lookup (mStyleName, listLevel) . listContinuationStartCounters
     <$> getExtraState
 
 --
@@ -253,9 +273,61 @@
   style <- getStyleByName name
   return (name, style)
 
---
-withNewStyle :: ODTReader Inlines -> ODTReader Inlines
-withNewStyle reader = do
+-- | With the @styles@ extension, the name (as shown to the user) of the
+-- named style that the current element is an instance of, unless the
+-- first argument says to ignore it. If the element's style is an automatic
+-- one, its named parent is used. A style that is not defined at all is
+-- taken to be a named one, since automatic styles are always defined.
+getCustomStyle :: (StyleName -> Bool) -> ODTReader (Maybe T.Text)
+getCustomStyle ignored = do
+  keep <- keepStyles <$> getExtraState
+  if not keep
+     then return Nothing
+     else do
+       fName  <- tryC (findAttr NsText "style-name")
+       styles <- getStyles
+       return $ case fName of
+         Right name
+           | Just (name', mbStyle) <- lookupNamedStyle name styles
+           , not (ignored name')
+           -> Just (styleUIName name' mbStyle)
+         _ -> Nothing
+
+customStyleAttr :: T.Text -> Attr
+customStyleAttr sty = ("", [], [("custom-style", sty)])
+
+-- | Paragraph styles not recorded with the @styles@ extension: the
+-- default style, the default styles of table cells, and styles that
+-- pandoc interprets itself.
+ignoredParaStyle :: StyleName -> Bool
+ignoredParaStyle name = name `elem` [ "Standard"
+                                    , "Table_20_Contents"
+                                    , "Table_20_Heading"
+                                    ] || isTableCaptionStyle name
+
+-- | Character styles not recorded with the @styles@ extension.
+ignoredCharStyle :: StyleName -> Bool
+ignoredCharStyle name = name `elem` [ "Internet_20_link"
+                                    , "Visited_20_Internet_20_Link"
+                                    , "Emphasis"
+                                    , "Strong_20_Emphasis"
+                                    ] || isCodeStyle name
+
+isCodeStyle :: StyleName -> Bool
+isCodeStyle "Source_Text" = True
+isCodeStyle "Source_20_Text" = True
+isCodeStyle _             = False
+
+isTableCaptionStyle :: StyleName -> Bool
+isTableCaptionStyle "Table" = True
+isTableCaptionStyle _       = False
+
+-- | Apply the text formatting of the current element's style. If the
+-- first argument is 'True', the formatting of a named (non-automatic)
+-- style is not applied, since it is recorded in a @custom-style@
+-- attribute instead; the direct formatting of an automatic style still is.
+withNewStyle :: Bool -> ODTReader Inlines -> ODTReader Inlines
+withNewStyle styleRecorded reader = do
   fStyle <- tryC readStyleByName
   case fStyle of
     Right (styleName, _) | isCodeStyle styleName ->
@@ -264,18 +336,15 @@
       | Just textProps <- textProperties (styleProperties style) -> do
           state <- getExtraState
           let mFamily  = styleFamily style
-              modifier = modifierFromStyleDiff (state, textProps, mFamily)
+              modifier
+                | styleRecorded && not (styleAutomatic style) = id
+                | otherwise = modifierFromStyleDiff (state, textProps, mFamily)
           pushStyle style
           inlines <- reader
           popStyle
           return $ modifier inlines
     _ -> reader
   where
-    isCodeStyle :: StyleName -> Bool
-    isCodeStyle "Source_Text" = True
-    isCodeStyle "Source_20_Text" = True
-    isCodeStyle _             = False
-
     inlineCode :: Inlines -> Inlines
     inlineCode = code . stringifyInlines
 
@@ -370,9 +439,6 @@
       listLevel <- getCurrentListLevel
       getParaModifier listLevel props <$> reader
   where
-    isTableCaptionStyle :: StyleName -> Bool
-    isTableCaptionStyle "Table" = True
-    isTableCaptionStyle _       = False
     tableCaptionP b = divWith ("", ["caption"], []) b
 
 type ListConstructor = [Blocks] -> Blocks
@@ -415,22 +481,28 @@
 constructList reader = do
   modifyExtraState (shiftListLevel 1)
   listLevel                    <- getCurrentListLevel
-  listContinuationStartCounter <- getPreviousListStartCounter listLevel
   fStyleName                   <- tryC (findAttr NsText "style-name")
   fContNumbering               <- tryC (findAttr NsText "continue-numbering")
+  inheritedStyleName           <- currentListStyleName <$> getExtraState
 
+  -- Numbering is continued from the previous list with the same
+  -- list style (and level), if there is one:
+  let mStyleName = either (const inheritedStyleName) Just fStyleName
+  listContinuationStartCounter <- getPreviousListStartCounter mStyleName
+                                    listLevel
+
   let continueNumbering = fContNumbering == Right "true"
 
       startNumForListLevelStyle mListLevelStyle
-        | continueNumbering      = listContinuationStartCounter
-        | isJust mListLevelStyle = listItemStart (fromJust mListLevelStyle)
-        | otherwise              = 1
+        | continueNumbering
+        , Just n <- listContinuationStartCounter = n
+        | otherwise = maybe 1 listItemStart mListLevelStyle
 
       constructWith startNum constructor = do
         items <- reader
         modifyExtraState (shiftListLevel (-1))
-        modifyExtraState (modifyListContinuationStartCounter listLevel
-                           (startNum + length items))
+        modifyExtraState (modifyListContinuationStartCounter mStyleName
+                           listLevel (startNum + length items))
         return $ constructor items
 
       constructOrderedList =
@@ -449,7 +521,8 @@
         Right listStyle ->
           case getListLevelStyle listLevel listStyle of
             Just listLevelStyle -> do
-              oldListStyle <- switchCurrentListStyle (Just listStyle)
+              oldListStyle <- switchCurrentListStyle
+                                (Just (styleName, listStyle))
               blocks       <- constructListWith listLevelStyle
               _            <- switchCurrentListStyle oldListStyle
               return blocks
@@ -541,8 +614,14 @@
                     $ return space
 --
 read_span        :: InlineMatcher
-read_span         = matchingElement NsText "span"
-                    $ withNewStyle matchInlineContent
+read_span         = matchingElement NsText "span" $ do
+                      mbCustom <- getCustomStyle ignoredCharStyle
+                      inlines  <- withNewStyle (isJust mbCustom)
+                                    matchInlineContent
+                      return $ case mbCustom of
+                        Just sty | not (null inlines)
+                          -> spanWith (customStyleAttr sty) inlines
+                        _ -> inlines
 
 -- | ODF wraps inline content in a few elements that carry nothing but
 -- metadata: @text:meta@ holds RDFa annotations, @text:meta-field@ marks
@@ -594,13 +673,27 @@
 
 --
 read_paragraph   :: Matcher CombiningBlocks
-read_paragraph    = matchingElement NsText "p" $ fmap CombiningBlocks $ do
-                      fStyle <- tryC readStyleByName
-                      case fStyle of
-                        Right style | isPreformattedStyle style ->
-                          codeBlock . stringifyInlines <$> matchInlineContent
-                        _ ->
-                          constructPara (para <$> withNewStyle matchInlineContent)
+read_paragraph    = read_paragraph' True
+
+-- | Read a paragraph. If the argument is 'True' and the @styles@ extension
+-- is enabled, a paragraph with a named style (other than one of the
+-- 'ignoredParaStyle's) is wrapped in a Div with a @custom-style@
+-- attribute. This is not done for the paragraphs of list items, which
+-- would make every list loose.
+read_paragraph'  :: Bool -> Matcher CombiningBlocks
+read_paragraph' recordStyle = matchingElement NsText "p" $ fmap CombiningBlocks $ do
+                      fStyle    <- tryC readStyleByName
+                      listLevel <- getCurrentListLevel
+                      mbCustom  <- if recordStyle && listLevel == 0
+                                      then getCustomStyle ignoredParaStyle
+                                      else return Nothing
+                      maybe id (divWith . customStyleAttr) mbCustom <$>
+                        case fStyle of
+                          Right style | isPreformattedStyle style ->
+                            codeBlock . stringifyInlines <$> matchInlineContent
+                          _ ->
+                            constructPara (para <$> withNewStyle (isJust mbCustom)
+                                                      matchInlineContent)
                     where
                       isPreformattedStyle :: (StyleName, Style) -> Bool
                       isPreformattedStyle ("Preformatted_20_Text", _) = True
@@ -657,7 +750,11 @@
   level    <- readAttrWithDefault NsText "outline-level" 1
   children <- matchInlineContent
   anchor   <- getHeaderAnchor children
-  let idAttr = (anchor, [], []) -- no classes, no key-value pairs
+  -- with the styles extension, record any style other than the
+  -- standard one for the heading's level
+  mbCustom <- getCustomStyle (\name -> name == "Heading_20_" <> tshow level
+                                    || name == "Heading")
+  let idAttr = (anchor, [], maybe [] (\sty -> [("custom-style", sty)]) mbCustom)
   return $ CombiningBlocks $ headerWith idAttr level children
 
 ----------------------
@@ -681,8 +778,14 @@
 
 read_list_element               :: ElementName -> Matcher [Blocks]
 read_list_element listElement   = matchingElement NsText listElement
-                                  $ compactify . (:[])
-                                  <$> matchBlockContent
+                                  $ do
+                                    -- a new item restarts the numbering
+                                    -- of nested lists:
+                                    listLevel <- getCurrentListLevel
+                                    modifyExtraState
+                                      (resetDeeperListContinuationStartCounters
+                                        listLevel)
+                                    compactify . (:[]) <$> matchBlockContent
 
 ----------------------
 -- Sections
@@ -976,7 +1079,9 @@
 
 read_frame_text_box :: XML.Element -> ODTReader (FirstMatch Inlines)
 read_frame_text_box box = do
-  paragraphs <- executeIn box (matchSmushedChildBlocks' [ read_paragraph ])
+  -- caption paragraphs must not be wrapped in Divs (see
+  -- 'read_img_with_caption')
+  paragraphs <- executeIn box (matchSmushedChildBlocks' [ read_paragraph' False ])
   return $ read_img_with_caption $ toList paragraphs
 
 read_img_with_caption :: [Block] -> FirstMatch Inlines
diff --git a/src/Text/Pandoc/Readers/ODT/StyleReader.hs b/src/Text/Pandoc/Readers/ODT/StyleReader.hs
--- a/src/Text/Pandoc/Readers/ODT/StyleReader.hs
+++ b/src/Text/Pandoc/Readers/ODT/StyleReader.hs
@@ -29,6 +29,8 @@
 , ListLevelType        (..)
 , LengthOrPercent      (..)
 , lookupStyle
+, lookupNamedStyle
+, styleUIName
 , getListLevelStyle
 , getStyleFamily
 , lookupDefaultStyle'
@@ -39,6 +41,7 @@
 
 import Control.Applicative ((<|>), optional)
 
+import Data.Char (chr, isHexDigit)
 import Data.Default
 import qualified Data.Foldable as F
 import qualified Data.Map as M
@@ -46,6 +49,7 @@
 import Data.Text (Text)
 import qualified Data.Text as T
 import qualified Data.Set as S
+import Numeric (readHex)
 
 import qualified Text.Pandoc.XML.Light as XML
 
@@ -178,10 +182,17 @@
                 ]
 
 -- | A named style
-data Style            = Style  { styleFamily     :: Maybe StyleFamily
-                               , styleParentName :: Maybe StyleName
-                               , listStyle       :: Maybe StyleName
-                               , styleProperties :: StyleProperties
+data Style            = Style  { styleFamily      :: Maybe StyleFamily
+                               , styleParentName  :: Maybe StyleName
+                               , listStyle        :: Maybe StyleName
+                               , styleProperties  :: StyleProperties
+                                 -- | The name shown to the user
+                                 -- (@style:display-name@), if given.
+                               , styleDisplayName :: Maybe Text
+                                 -- | Whether this is an automatic style,
+                                 -- i.e. one that only records direct
+                                 -- formatting and is not visible to the user.
+                               , styleAutomatic   :: Bool
                                }
   deriving ( Eq, Show )
 
@@ -404,14 +415,14 @@
 --
 readStyles :: StyleReader Styles
 readStyles = executeInSub NsOffice "styles" $
-  Styles <$> (M.fromList <$> tryAll NsStyle "style"         readStyle       )
+  Styles <$> (M.fromList <$> tryAll NsStyle "style"   (readStyle False) )
          <*> (M.fromList <$> tryAll NsText  "list-style"    readListStyle   )
          <*> (M.fromList <$> tryAll NsStyle "default-style" readDefaultStyle)
 
 --
 readAutomaticStyles :: StyleReader Styles
 readAutomaticStyles = executeInSub NsOffice "automatic-styles" $
-  Styles <$> (M.fromList <$> tryAll NsStyle "style"         readStyle       )
+  Styles <$> (M.fromList <$> tryAll NsStyle "style"   (readStyle True)  )
          <*> (M.fromList <$> tryAll NsText  "list-style"    readListStyle   )
          <*> pure M.empty
 
@@ -420,14 +431,16 @@
 readDefaultStyle = (,) <$> lookupAttr NsStyle "family"
                        <*> readStyleProperties
 
---
-readStyle :: StyleReader (StyleName, Style)
-readStyle = do
+-- | Read a style; the argument says whether it is an automatic style.
+readStyle :: Bool -> StyleReader (StyleName, Style)
+readStyle automatic = do
   name  <- findAttr NsStyle "name"
   style <- Style <$> lookupAttr' NsStyle "family"
                  <*> findAttr'   NsStyle "parent-style-name"
                  <*> findAttr'   NsStyle "list-style-name"
                  <*> readStyleProperties
+                 <*> findAttr'   NsStyle "display-name"
+                 <*> pure automatic
   return (name, style)
 
 --
@@ -553,6 +566,48 @@
 --
 lookupStyle           :: StyleName   -> Styles -> Maybe Style
 lookupStyle name Styles{..} = M.lookup name stylesByName
+
+-- | Find the named (i.e., non-automatic) style that an element with the
+-- given style name is an instance of. An automatic style (@P1@, @T3@, ...)
+-- only records direct formatting, so it is followed up its chain of parents.
+-- Returns the internal name of the style together with the style, which
+-- may not be defined: automatic styles always are, so an undefined style
+-- is a named one.
+lookupNamedStyle      :: StyleName   -> Styles
+                      -> Maybe (StyleName, Maybe Style)
+lookupNamedStyle name0 styles = go S.empty name0
+  where
+    go seen name
+      | name `S.member` seen = Nothing  -- cyclic parent references
+      | otherwise =
+          case lookupStyle name styles of
+            Nothing -> Just (name, Nothing)
+            Just style
+              | styleAutomatic style
+                -> styleParentName style >>= go (S.insert name seen)
+              | otherwise -> Just (name, Just style)
+
+-- | The name of a style as shown to the user: its @style:display-name@,
+-- if any, or else its internal name with ODF's escapes (@_20_@ for a
+-- space, etc.) decoded.
+styleUIName           :: StyleName   -> Maybe Style -> Text
+styleUIName name mbStyle =
+  fromMaybe (decodeStyleName name) (mbStyle >>= styleDisplayName)
+
+-- | Decode the hex escapes (e.g. @_20_@) that ODF uses for characters that
+-- are not allowed in style names.
+decodeStyleName :: StyleName -> Text
+decodeStyleName t =
+  case T.breakOn "_" t of
+    (before, rest)
+      | T.null rest -> before
+      | (hex, rest') <- T.span isHexDigit (T.drop 1 rest)
+      , not (T.null hex)
+      , "_" `T.isPrefixOf` rest'
+      , [(n, "")] <- readHex (T.unpack hex)
+      , n <= 0x10FFFF
+      -> before <> T.singleton (chr n) <> decodeStyleName (T.drop 1 rest')
+      | otherwise -> before <> "_" <> decodeStyleName (T.drop 1 rest)
 
 --
 lookupDefaultStyle'   :: Styles -> StyleFamily -> StyleProperties
diff --git a/src/Text/Pandoc/Readers/OOXML/Charts.hs b/src/Text/Pandoc/Readers/OOXML/Charts.hs
new file mode 100644
--- /dev/null
+++ b/src/Text/Pandoc/Readers/OOXML/Charts.hs
@@ -0,0 +1,171 @@
+{-# LANGUAGE OverloadedStrings #-}
+{- |
+   Module      : Text.Pandoc.Readers.OOXML.Charts
+   Copyright   : © 2026 Nacho García
+   License     : GNU GPL, version 2 or above
+
+   Maintainer  : Nacho García <hello@nachogarcia.dev>
+   Stability   : alpha
+   Portability : portable
+
+Reading of DrawingML charts (in PPTX slides and XLSX sheets), from the
+values cached in the chart part.
+-}
+module Text.Pandoc.Readers.OOXML.Charts
+  ( Chart(..)
+  , ChartSeries(..)
+  , readChart
+  , chartToBlocks
+  ) where
+
+import Codec.Archive.Zip (Archive, findEntryByPath, fromEntry)
+import Data.List (find, nub, transpose)
+import qualified Data.Map.Strict as M
+import Data.Maybe (fromMaybe, listToMaybe, mapMaybe)
+import qualified Data.Text as T
+import qualified Data.Text.Lazy.Encoding as TL
+import Data.Text (Text)
+import qualified Text.Pandoc.Builder as B
+import Text.Pandoc.Definition
+import Text.Pandoc.Readers.OOXML.Shared
+import Text.Pandoc.XML.Light
+import Text.Read (readMaybe)
+
+-- | A chart's data, as cached in its chart part
+data Chart = Chart
+  { chartTitle  :: Text     -- ^ Empty if the chart has no title
+  , chartTypes  :: [Text]   -- ^ Such as @bar@ or @line@, one per plot
+  , chartSeries :: [ChartSeries]
+  } deriving (Show)
+
+-- | One series: its name, and its points as (category, value)
+data ChartSeries = ChartSeries
+  { seriesName   :: Text
+  , seriesPoints :: [(Text, Text)]
+  } deriving (Show)
+
+-- | Read a chart part (@c:chartSpace@)
+readChart :: Archive -> FilePath -> Either Text Chart
+readChart archive path = do
+  entry <- maybe (Left $ "Entry not found: " <> T.pack path) Right $
+           findEntryByPath path archive
+  chartSpace <- parseXMLElement (TL.decodeUtf8 (fromEntry entry))
+  chart <- maybe (Left "Missing c:chart") Right $ child "chart" chartSpace
+  plotArea <- maybe (Left "Missing c:plotArea") Right $
+              child "plotArea" chart
+  let plots = filter (("Chart" `T.isSuffixOf`) . qName . elName)
+                     (elChildren plotArea)
+      series = zipWith parseSeries [1..] (concatMap (children "ser") plots)
+      title = maybe "" titleText (child "title" chart)
+  if all (all (T.null . snd) . seriesPoints) series
+     then Left "Chart has no cached values"
+     else Right Chart
+            { chartTitle = title
+            , chartTypes = nub $ map (T.dropEnd 5 . qName . elName) plots
+            , chartSeries = series
+            }
+
+-- | Text of a chart title: rich text, or a cached cell reference
+titleText :: Element -> Text
+titleText title =
+  case child "tx" title of
+    Just tx | Just rich <- child "rich" tx -> drawingMLText rich
+            | otherwise -> T.unwords (cachedValues tx)
+    Nothing -> ""
+
+-- | Parse a series (@c:ser@). Its categories come from @c:cat@, or
+-- @c:xVal@ in a scatter or bubble chart, and its values from @c:val@ or
+-- @c:yVal@. A series without categories is numbered from 1, as in
+-- PowerPoint.
+parseSeries :: Int -> Element -> ChartSeries
+parseSeries n ser =
+  ChartSeries
+    { seriesName = case child "tx" ser of
+        Just tx -> T.unwords (cachedValues tx)
+        Nothing -> "Series" <> T.pack (show n)
+    , seriesPoints =
+        [ (fromMaybe (T.pack (show (i + 1))) (M.lookup i categories), v)
+        | i <- [0 .. count - 1]
+        , let v = fromMaybe "" (M.lookup i values)
+        ]
+    }
+  where
+    points names = maybe (0, M.empty) cachedPoints $
+      listToMaybe (mapMaybe (`child` ser) names)
+    (catCount, categories) = points ["cat", "xVal"]
+    (valCount, values) = points ["val", "yVal"]
+    count = maximum [catCount, valCount, size values, size categories]
+    size m = maybe 0 ((+ 1) . fst) (M.lookupMax m)
+
+-- | The cached points of a data source (@c:cat@, @c:val@, ...): the
+-- point count and the value of each point by index. In multi-level
+-- categories only the innermost level is read.
+cachedPoints :: Element -> (Int, M.Map Int Text)
+cachedPoints source =
+  case listToMaybe (mapMaybe cache (elChildren source)) of
+    Just c ->
+      ( fromMaybe 0 $ child "ptCount" c >>= findAttr (unqual "val") >>=
+                        readMaybe . T.unpack
+      , M.fromList
+          [ (i, maybe "" strContent (child "v" pt))
+          | pt <- children "pt" c
+          , Just i <- [findAttr (unqual "idx") pt >>= readMaybe . T.unpack]
+          ]
+      )
+    Nothing -> (0, M.empty)
+  where
+    cache el = case qName (elName el) of
+      name | name `elem` ["strLit", "numLit"] -> Just el
+           | name `elem` ["strRef", "numRef"] ->
+               find ((`elem` ["strCache", "numCache"]) . qName . elName)
+                    (elChildren el)
+           | name == "multiLvlStrRef" ->
+               child "multiLvlStrCache" el >>= child "lvl"
+           | otherwise -> Nothing
+
+-- | The cached values of a text source such as a series name (@c:tx@),
+-- which is either a cell reference with its cache or a literal @c:v@
+cachedValues :: Element -> [Text]
+cachedValues tx =
+  case child "v" tx of
+    Just v -> [strContent v]
+    Nothing -> M.elems (snd (cachedPoints tx))
+
+-- | A chart as a table, in a @chart@ div with the chart types as its
+-- @type@ attribute. Series that share their categories go in one table,
+-- one column per series; otherwise each series gets its own table.
+chartToBlocks :: Chart -> [Block]
+chartToBlocks chart =
+  [Div ("", ["chart"], [("type", T.unwords (chartTypes chart))])
+       (map table groups)]
+  where
+    series = chartSeries chart
+    categoriesOf = map fst . seriesPoints
+    groups = case series of
+      s:rest | all ((== categoriesOf s) . categoriesOf) rest -> [series]
+      _ -> map (: []) series
+    caption = if T.null (chartTitle chart)
+                 then Caption Nothing []
+                 else Caption Nothing [Plain (B.toList (B.text
+                                               (chartTitle chart)))]
+    table group =
+      let cell t = Cell nullAttr AlignDefault (RowSpan 1) (ColSpan 1)
+                     [Plain (B.toList (B.text t))]
+          headerRow = Row nullAttr $ cell "" : map (cell . seriesName) group
+          categories = maybe [] categoriesOf (listToMaybe group)
+          values = transpose (map (map snd . seriesPoints) group)
+          bodyRows = zipWith (\category vs -> Row nullAttr
+                                              (map cell (category : vs)))
+                             categories values
+       in Table nullAttr caption
+            (replicate (length group + 1) (AlignDefault, ColWidthDefault))
+            (TableHead nullAttr [headerRow])
+            [TableBody nullAttr 0 [] bodyRows]
+            (TableFoot nullAttr [])
+
+-- Chart elements are matched by local name, as the c prefix can vary.
+child :: Text -> Element -> Maybe Element
+child name = find ((== name) . qName . elName) . elChildren
+
+children :: Text -> Element -> [Element]
+children name = filter ((== name) . qName . elName) . elChildren
diff --git a/src/Text/Pandoc/Readers/OOXML/Shared.hs b/src/Text/Pandoc/Readers/OOXML/Shared.hs
--- a/src/Text/Pandoc/Readers/OOXML/Shared.hs
+++ b/src/Text/Pandoc/Readers/OOXML/Shared.hs
@@ -26,6 +26,9 @@
   , findChildrenByName
   , findElementByName
   , findAttrByName
+    -- * DrawingML text
+  , drawingMLParagraphLines
+  , drawingMLText
   ) where
 
 import qualified Data.Map as M
@@ -93,3 +96,25 @@
 findAttrByName ns pref name el =
   let ns' = ns <> elemToNameSpaces el
   in  findAttr (elemName ns' pref name) el
+
+-- | The text of a DrawingML paragraph (@a:p@), one item per line: line
+-- breaks (@a:br@) split it. The text of runs (@a:r@) and fields
+-- (@a:fld@) is concatenated as written, without adding spaces between
+-- them, since a run boundary can fall anywhere, even inside a word.
+drawingMLParagraphLines :: Element -> [Text]
+drawingMLParagraphLines = T.splitOn "\n" . T.concat . map piece . elChildren
+  where
+    piece el = case qName (elName el) of
+      "r"   -> runText el
+      "fld" -> runText el
+      "br"  -> "\n"
+      _     -> ""
+    runText = T.concat . map strContent .
+              filter ((== "t") . qName . elName) . elChildren
+
+-- | The text of all DrawingML paragraphs (@a:p@) in an element, with a
+-- space between paragraphs and in place of line breaks.
+drawingMLText :: Element -> Text
+drawingMLText = T.unwords . filter (not . T.null) . map T.strip .
+                concatMap drawingMLParagraphLines .
+                filterElementsName ((== "p") . qName)
diff --git a/src/Text/Pandoc/Readers/Pptx/Parse.hs b/src/Text/Pandoc/Readers/Pptx/Parse.hs
--- a/src/Text/Pandoc/Readers/Pptx/Parse.hs
+++ b/src/Text/Pandoc/Readers/Pptx/Parse.hs
@@ -26,7 +26,9 @@
 import qualified Data.Text.Lazy.Encoding as TL
 import Data.Text (Text)
 import System.FilePath (splitFileName)
+import qualified System.FilePath.Posix as Posix
 import Text.Pandoc.Readers.OOXML.Shared
+import Text.Pandoc.Shared (collapseFilePath)
 import Text.Pandoc.XML.Light
 import Text.Read (readMaybe)
 
@@ -46,6 +48,9 @@
   , slidePath    :: FilePath
   , slideElement :: Element     -- The parsed p:sld element
   , slideRels    :: [(Text, Text)]  -- Slide relationships
+  , slideNotes   :: Maybe Element   -- The parsed p:notes element, if any
+  , slideLayout  :: Maybe Element   -- The slide's p:sldLayout
+  , slideMaster  :: Maybe Element   -- Its layout's p:sldMaster
   } deriving (Show)
 
 -- | Presentation-level information from presentation.xml
@@ -208,7 +213,53 @@
   slideRelsPath <- getPresentationRelsPath archive slidePath'
   slideRels' <- loadRelationships archive slideRelsPath
 
-  return $ PptxSlide sid slidePath' slideElem slideRels'
+  -- Follow the slide's own notesSlide relationship: notesSlideN.xml need
+  -- not belong to slideN.xml. A missing or unreadable notes part means
+  -- the slide has no notes; it never fails the conversion.
+  let notesElem = do
+        notesTarget <- findRelTargetByType archive slideRelsPath "notesSlide"
+        either (const Nothing) Just $
+          loadXMLFromArchive archive (resolveTarget slidePath' notesTarget)
+
+  -- The slide's layout and master, which the text of its placeholders
+  -- inherits from; either may be missing.
+  let related source typeName = do
+        t <- findRelTargetByType archive (relsPathOf source) typeName
+        let path = resolveTarget source t
+        el <- either (const Nothing) Just $ loadXMLFromArchive archive path
+        return (path, el)
+      layout = related slidePath' "slideLayout"
+      master = layout >>= \(layoutPath, _) -> related layoutPath "slideMaster"
+
+  return $ PptxSlide sid slidePath' slideElem slideRels' notesElem
+                     (snd <$> layout) (snd <$> master)
+
+-- | The path of a part's relationships
+relsPathOf :: FilePath -> FilePath
+relsPathOf path =
+  let (dir, file) = splitFileName path
+   in dir ++ "/_rels/" ++ file ++ ".rels"
+
+-- | Find the target of the first relationship in a .rels part whose Type
+-- ends with the given name, such as @notesSlide@.
+findRelTargetByType :: Archive -> FilePath -> Text -> Maybe Text
+findRelTargetByType archive relsPath typeName = do
+  entry <- findEntryByPath relsPath archive
+  relsElem <- either (const Nothing) Just $ parseXMLFromEntry entry
+  rel <- find hasType (onlyElems $ elContent relsElem)
+  findAttr (unqual "Target") rel
+  where
+    hasType el = maybe False (("/" <> typeName) `T.isSuffixOf`) $
+                 findAttr (unqual "Type") el
+
+-- | Resolve a relationship target to an archive path. A target starting
+-- with @/@ is relative to the package root; any other target is relative
+-- to the folder of the part that holds the relationship.
+resolveTarget :: FilePath -> Text -> FilePath
+resolveTarget source target =
+  case T.unpack target of
+    '/':path -> path
+    path -> collapseFilePath (Posix.takeDirectory source Posix.</> path)
 
 -- | Helper: Maybe a -> Either Text a
 maybeToEither :: Text -> Maybe a -> Either Text a
diff --git a/src/Text/Pandoc/Readers/Pptx/Shapes.hs b/src/Text/Pandoc/Readers/Pptx/Shapes.hs
--- a/src/Text/Pandoc/Readers/Pptx/Shapes.hs
+++ b/src/Text/Pandoc/Readers/Pptx/Shapes.hs
@@ -14,40 +14,68 @@
 module Text.Pandoc.Readers.Pptx.Shapes
   ( PptxShape(..)
   , PptxParagraph(..)
+  , TableCell(..)
   , BulletType(..)
   , parseShapes
   , parseShape
+  , parseShapeWith
+  , inheritedBullets
   , shapeToBlocks
+  , paragraphsToBlocks
   , isTitlePlaceholder
   , extractDrawingMLText
   ) where
 
 import Codec.Archive.Zip (Archive, findEntryByPath, fromEntry)
 import qualified Data.ByteString.Lazy as B
+import Data.Char (isSpace)
 import Data.List (find, groupBy)
-import Data.Maybe (mapMaybe)
+import Data.Maybe (fromMaybe, listToMaybe, mapMaybe)
+import qualified Data.Set as S
 import qualified Data.Text as T
 import Data.Text (Text)
 import Text.Read (readMaybe)
+import qualified Text.Pandoc.Builder as B
 import Text.Pandoc.Class.PandocMonad (PandocMonad)
 import qualified Text.Pandoc.Class.PandocMonad as P
 import Text.Pandoc.Definition
 import Text.Pandoc.Readers.OOXML.Shared
+import Text.Pandoc.Readers.OOXML.Charts
 import Text.Pandoc.Readers.Pptx.SmartArt
+import Text.Pandoc.Shared (collapseFilePath)
+import Text.Pandoc.Walk (walk)
 import Text.Pandoc.XML.Light
+import Text.TeXMath (writeTeX)
+import Text.TeXMath.Readers.OMML (readOMML)
+import qualified System.FilePath.Posix as Posix
 
 -- | Paragraph with bullet/numbering information
 data PptxParagraph = PptxParagraph
   { paraLevel   :: Int            -- Bullet level (0, 1, 2...)
   , paraBullet  :: BulletType
-  , paraText    :: Text
+  , paraText    :: [Inline]
   } deriving (Show)
 
+-- | A table cell (@a:tc@): its text, its row and column span, and whether
+-- another cell's span covers it from the left (@hMerge@) or from above
+-- (@vMerge@)
+data TableCell = TableCell
+  { tcText    :: Text
+  , tcRowSpan :: Int
+  , tcColSpan :: Int
+  , tcHMerge  :: Bool
+  , tcVMerge  :: Bool
+  } deriving (Show)
+
+tcCovered :: TableCell -> Bool
+tcCovered c = tcHMerge c || tcVMerge c
+
 -- | Bullet type
 data BulletType
   = NoBullet
   | Bullet                        -- Has bullet (character detected or implicit)
   | WingdingsBullet              -- Detected via Wingdings symbol
+  | Numbered ListAttributes      -- Automatic numbering (a:buAutoNum)
   deriving (Show, Eq)
 
 -- | Shape types in PPTX slides
@@ -58,11 +86,12 @@
       , picTitle  :: Text
       , picAlt    :: Text
       }
-  | PptxTable [[Text]]                  -- Simple text cells for now
+  | PptxTable [[TableCell]]             -- Rows of cells
   | PptxDiagramRef
       { dgmDataRelId   :: Text          -- Relationship to data.xml
       , dgmLayoutRelId :: Text          -- Relationship to layout.xml
       }
+  | PptxChartRef Text Text              -- Relationship to the chart, URI
   | PptxGraphic Text                    -- Placeholder for other graphics
   deriving (Show)
 
@@ -76,12 +105,20 @@
 
 -- | Parse individual shape element
 parseShape :: NameSpaces -> Element -> Maybe PptxShape
-parseShape ns el
+parseShape = parseShapeWith (const Nothing)
+
+-- | Parse a shape, given the bullet its paragraphs inherit at each level
+-- (0 for the first) when they don't set one themselves
+parseShapeWith :: (Int -> Maybe BulletType) -> NameSpaces -> Element
+               -> Maybe PptxShape
+parseShapeWith inherited ns el
   -- Text box: <p:sp> with <p:txBody>
+  -- A slide number placeholder only holds the number PowerPoint shows
+  | isSlideNumberPlaceholder ns el = Nothing
   | isElem ns "p" "sp" el =
       case findChildByName ns "p" "txBody" el of
         Just txBody ->
-          let paras = parseParagraphs ns txBody
+          let paras = parseParagraphs inherited ns txBody
            in if null paras
               then Nothing
               else Just $ PptxTextBox paras
@@ -133,34 +170,53 @@
                                   (Just dataRelId, Just layoutRelId) ->
                                     Just $ PptxDiagramRef dataRelId layoutRelId
                                   _ -> Just $ PptxGraphic "diagram-missing-rels"
+                  else if uri == chartUri
+                    then
+                      -- The c prefix is usually declared on c:chart itself
+                      case find ((== "chart") . qName . elName)
+                                (elChildren graphicData) of
+                        Just chartElem
+                          | Just relId <- findAttrByName
+                              (ns <> elemToNameSpaces chartElem) "r" "id"
+                              chartElem
+                          -> Just $ PptxChartRef relId uri
+                        _ -> Just $ PptxGraphic ("other: " <> uri)
                   else
-                    -- Other graphic (chart, etc.)
+                    -- Other graphic
                     Just $ PptxGraphic ("other: " <> uri)
 
   -- Skip other shapes for now
   | otherwise = Nothing
 
 -- | Parse table rows (simple text extraction)
-parseTableRows :: NameSpaces -> Element -> [[Text]]
+parseTableRows :: NameSpaces -> Element -> [[TableCell]]
 parseTableRows ns tblElem =
   let trElems = findChildrenByName ns "a" "tr" tblElem
    in map (parseTableRow ns) trElems
 
-parseTableRow :: NameSpaces -> Element -> [Text]
+parseTableRow :: NameSpaces -> Element -> [TableCell]
 parseTableRow ns trElem =
   let tcElems = findChildrenByName ns "a" "tc" trElem
-   in map extractCellText tcElems
+   in map parseCell tcElems
   where
-    extractCellText tcElem =
-      -- Get text from txBody/a:p/a:r/a:t
-      case findChildByName ns "a" "txBody" tcElem of
-        Just txBody -> extractDrawingMLText txBody
-        Nothing -> ""
+    parseCell tcElem = TableCell
+      { tcText = case findChildByName ns "a" "txBody" tcElem of
+          -- Get text from txBody/a:p/a:r/a:t
+          Just txBody -> extractDrawingMLText txBody
+          Nothing -> ""
+      , tcRowSpan = span' "rowSpan" tcElem
+      , tcColSpan = span' "gridSpan" tcElem
+      , tcHMerge = flag "hMerge" tcElem
+      , tcVMerge = flag "vMerge" tcElem
+      }
+    span' name el = maybe 1 (max 1) $
+      findAttr (unqual name) el >>= readMaybe . T.unpack
+    flag name el = findAttr (unqual name) el `elem` [Just "1", Just "true"]
 
 -- | Convert shape to Pandoc blocks
 shapeToBlocks :: PandocMonad m => Archive -> [(Text, Text)] -> PptxShape -> m [Block]
-shapeToBlocks _archive _rels (PptxTextBox paras) =
-  return $ paragraphsToBlocks paras
+shapeToBlocks _archive rels (PptxTextBox paras) =
+  return $ resolveLinks rels $ paragraphsToBlocks paras
 shapeToBlocks archive rels (PptxPicture relId title alt) = do
   -- Resolve relationship to get media path
   case lookup relId rels of
@@ -178,13 +234,15 @@
           return [Para [Image nullAttr altText (mediaPath, title)]]
 
 shapeToBlocks _archive _rels (PptxTable rows) =
-  -- Simple table representation for now
-  case rows of
+  case spannedRows rows of
     [] -> return []
     (headerRow:bodyRows) -> do
-      let makeCell text = Cell nullAttr AlignDefault (RowSpan 1) (ColSpan 1) [Plain [Str text]]
-          headerCells = map makeCell headerRow
-          bodyCells = map (map makeCell) bodyRows
+      let makeCell (TableCell text rs cs _ _) =
+            Cell nullAttr AlignDefault (RowSpan rs) (ColSpan cs)
+                 [Plain (B.toList (B.text text))]
+          visible = map makeCell . filter (not . tcCovered)
+          headerCells = visible headerRow
+          bodyCells = map visible bodyRows
           caption = Caption Nothing []
           colSpec = replicate (length headerRow) (AlignDefault, ColWidthDefault)
           headerRow' = Row nullAttr headerCells
@@ -202,10 +260,46 @@
       return [Para [Str $ "[Diagram parse error: " <> err <> "]"]]
     Right diagram ->
       return $ diagramToBlocks diagram
+shapeToBlocks archive rels (PptxChartRef relId uri) =
+  -- A chart whose part can't be read keeps the placeholder
+  return $ either (const [Para [Str $ "[Graphic: other: " <> uri <> "]"]])
+                  chartToBlocks $ do
+    target <- maybe (Left $ "Relationship not found: " <> relId) Right $
+              lookup relId rels
+    readChart archive $ case T.unpack target of
+      '/':path -> path
+      path -> collapseFilePath ("ppt/slides" Posix.</> path)
 shapeToBlocks _archive _rels (PptxGraphic text) =
   -- Placeholder for other graphics (charts, etc.)
   return [Para [Str $ "[Graphic: " <> text <> "]"]]
 
+-- | Make the spans of a table's cells fit pandoc's table model. Each row
+-- has a cell for every grid column, with the cells covered by a span
+-- marked. As a cell can't span the header row and the body, the header
+-- row's spans are kept to that row, and the body cells they covered
+-- become empty cells of their own. Row spans are clipped to the rows
+-- there are.
+spannedRows :: [[TableCell]] -> [[TableCell]]
+spannedRows [] = []
+spannedRows (header:body) =
+  map (\c -> c{ tcRowSpan = 1 }) header : go headerSpanCols (length body) body
+  where
+    headerSpanCols = S.fromList
+      [ col' | (col, c) <- zip [0 :: Int ..] header
+             , tcRowSpan c > 1, not (tcCovered c)
+             , col' <- [col .. col + tcColSpan c - 1] ]
+    -- cols: the columns still covered by a span from the header row;
+    -- left: the number of rows from this one to the last
+    go _ _ [] = []
+    go cols left (row:rows) =
+      let cells = zip [0 ..] row
+          fix (col, c)
+            | col `S.member` cols && tcVMerge c =
+                TableCell "" 1 1 False False
+            | otherwise = c{ tcRowSpan = min (tcRowSpan c) left }
+          stillCovered col = maybe False tcVMerge (lookup col cells)
+       in map fix cells : go (S.filter stillCovered cols) (left - 1) rows
+
 -- | Resolve media path (handle relative paths)
 resolveMediaPath :: Text -> Text
 resolveMediaPath target =
@@ -223,17 +317,19 @@
     Nothing -> Nothing
 
 -- | Parse paragraphs from text box
-parseParagraphs :: NameSpaces -> Element -> [PptxParagraph]
-parseParagraphs ns txBody =
+parseParagraphs :: (Int -> Maybe BulletType) -> NameSpaces -> Element
+                -> [PptxParagraph]
+parseParagraphs inherited ns txBody =
   let pElems = findChildrenByName ns "a" "p" txBody
-   in map (parseParagraph ns) pElems
+   in map (parseParagraph inherited ns) pElems
 
 -- | Parse individual paragraph
-parseParagraph :: NameSpaces -> Element -> PptxParagraph
-parseParagraph ns pElem =
+parseParagraph :: (Int -> Maybe BulletType) -> NameSpaces -> Element
+               -> PptxParagraph
+parseParagraph inherited ns pElem =
   let level = parseBulletLevel ns pElem
-      bullet = detectBulletType ns pElem
-      text = extractParagraphText ns pElem
+      bullet = detectBulletType (inherited level) ns pElem
+      text = paragraphInlines pElem
    in PptxParagraph level bullet text
 
 -- | Parse bullet level from paragraph properties
@@ -245,19 +341,85 @@
     Just lvl -> lvl
     Nothing -> 0  -- Default to level 0
 
--- | Detect bullet type
-detectBulletType :: NameSpaces -> Element -> BulletType
-detectBulletType ns pElem =
-  -- Check for explicit <a:pPr><a:buChar>
-  case findChildByName ns "a" "pPr" pElem >>=
-       findChildByName ns "a" "buChar" of
-    Just _buCharElem -> Bullet
-    Nothing ->
+-- | Detect bullet type: the paragraph's own, or else the one it inherits
+detectBulletType :: Maybe BulletType -> NameSpaces -> Element -> BulletType
+detectBulletType inherited ns pElem =
+  case findChildByName ns "a" "pPr" pElem >>= explicitBullet of
+    Just bullet -> bullet
+    Nothing
       -- Check for Wingdings symbol (common in PowerPoint)
-      if hasWingdingsSymbol ns pElem
-        then WingdingsBullet
-        else NoBullet
+      | hasWingdingsSymbol ns pElem -> WingdingsBullet
+      | otherwise -> fromMaybe NoBullet inherited
 
+-- | The bullet that paragraph properties (@a:pPr@ or @a:lvlNpPr@) set,
+-- if they set one
+explicitBullet :: Element -> Maybe BulletType
+explicitBullet pPr = listToMaybe (mapMaybe bullet (elChildren pPr))
+  where
+    bullet el = case qName (elName el) of
+      "buChar"    -> Just Bullet
+      "buBlip"    -> Just Bullet
+      "buNone"    -> Just NoBullet
+      "buAutoNum" -> Just (Numbered (numbering el))
+      _           -> Nothing
+    numbering el =
+      let scheme = fromMaybe "arabicPeriod" (findAttr (unqual "type") el)
+          start = fromMaybe 1 $
+                  findAttr (unqual "startAt") el >>= readMaybe . T.unpack
+          style | "arabic" `T.isPrefixOf` scheme = Decimal
+                | "alphaLc" `T.isPrefixOf` scheme = LowerAlpha
+                | "alphaUc" `T.isPrefixOf` scheme = UpperAlpha
+                | "romanLc" `T.isPrefixOf` scheme = LowerRoman
+                | "romanUc" `T.isPrefixOf` scheme = UpperRoman
+                | otherwise = DefaultStyle
+          delim | "ParenBoth" `T.isSuffixOf` scheme = TwoParens
+                | "ParenR" `T.isSuffixOf` scheme = OneParen
+                | "Period" `T.isSuffixOf` scheme = Period
+                | otherwise = DefaultDelim
+       in (start, style, delim)
+
+-- | The bullet a shape's paragraphs inherit at each level (0 for the
+-- first), from the shape's own list style, then the matching placeholder
+-- on the slide layout and on the slide master, then the master's text
+-- style for that kind of placeholder (or for other text).
+inheritedBullets :: Maybe Element  -- ^ Slide layout
+                 -> Maybe Element  -- ^ Slide master
+                 -> Element        -- ^ Shape
+                 -> Int -> Maybe BulletType
+inheritedBullets layout master shape level =
+  listToMaybe $ mapMaybe (>>= explicitBullet) $
+    [lstLevel shape] ++
+    case placeholder shape of
+      Just (phType, phIdx) ->
+        [ layout >>= findPlaceholder phType phIdx >>= lstLevel
+        , master >>= findPlaceholder (masterType phType) Nothing >>= lstLevel
+        , textStyle (styleFor phType) ]
+      Nothing -> [textStyle "otherStyle"]
+  where
+    lvlName = "lvl" <> T.pack (show (level + 1)) <> "pPr"
+    child name el = find ((== name) . qName . elName) (elChildren el)
+    lstLevel sp = child "txBody" sp >>= child "lstStyle" >>= child lvlName
+    textStyle name = master >>= child "txStyles" >>= child name >>=
+                     child lvlName
+    placeholder sp = do
+      ph <- child "nvSpPr" sp >>= child "nvPr" >>= child "ph"
+      return ( fromMaybe "obj" (findAttr (unqual "type") ph)
+             , findAttr (unqual "idx") ph )
+    -- A placeholder is matched by index if it has one, else by type
+    findPlaceholder phType phIdx root = do
+      tree <- child "cSld" root >>= child "spTree"
+      let phs = [ (sp, p) | sp <- elChildren tree
+                          , Just p <- [placeholder sp] ]
+          byIdx = [ sp | Just i <- [phIdx], (sp, (_, j)) <- phs, j == Just i ]
+          byType = [ sp | (sp, (t, _)) <- phs, masterType t == phType ||
+                                              t == phType ]
+      listToMaybe (byIdx ++ byType)
+    masterType t = if t `elem` ["obj", "body"] then "body" else t
+    styleFor t
+      | t `elem` ["title", "ctrTitle"] = "titleStyle"
+      | t `elem` ["obj", "body", "subTitle"] = "bodyStyle"
+      | otherwise = "otherStyle"
+
 -- | Check if paragraph starts with Wingdings symbol
 hasWingdingsSymbol :: NameSpaces -> Element -> Bool
 hasWingdingsSymbol ns pElem =
@@ -271,51 +433,163 @@
                      Nothing -> False
    in any checkRun runs
 
--- | Extract text from paragraph
-extractParagraphText :: NameSpaces -> Element -> Text
-extractParagraphText _ns pElem =
-  -- Find all <a:t> elements and concatenate
-  let textElems = filterElementsName (\qn -> qName qn == "t") pElem
-      texts = map strContent textElems
-   in T.unwords $ filter (not . T.null) texts
+-- | Inlines of a paragraph: the text of its runs and fields with their
+-- bold, italic, superscript and subscript, its line breaks, its
+-- hyperlinks, and its equations (@a14:m@) as math. A hyperlink's target
+-- is a relationship id at this point, which 'resolveLinks' replaces.
+paragraphInlines :: Element -> [Inline]
+paragraphInlines pElem =
+  B.toList $ foldMap linked $ groupBy (\a b -> fst a == fst b) $
+    concatMap piece (elChildren pElem)
+  where
+    piece el = case qName (elName el) of
+      "r"   -> [(runLink el, Left (runFormat el, runText el))]
+      "fld" -> [(runLink el, Left (runFormat el, runText el))]
+      "br"  -> [(Nothing, Right B.linebreak)]
+      "m"   -> [(Nothing, Right (foldMap mathInlines (elChildren el)))]
+      _     -> []
+    linked grp =
+      let inls = foldMap formatted $ groupBy sameFormat (map snd grp)
+       in case grp of
+            (Just relId, _) : _ ->
+              B.linkWith ("", [], [(linkRelAttr, relId)]) "" "" inls
+            _ -> inls
+    sameFormat (Left (f, _)) (Left (g, _)) = f == g
+    sameFormat _ _ = False
+    -- Runs with the same format are joined before it is applied, so
+    -- that adjacent bold runs make one strong span.
+    formatted pieces@(Left (fmt, _) : _) =
+      applyFormat fmt (T.concat [t | Left (_, t) <- pieces])
+    formatted pieces = mconcat [ils | Right ils <- pieces]
 
--- | Extract text from DrawingML element (finds all <a:t> descendants)
+-- | The format of a run: bold, italic, and its baseline shift (positive
+-- for superscript, negative for subscript)
+type RunFormat = (Bool, Bool, Int)
+
+runFormat :: Element -> RunFormat
+runFormat run =
+  case find ((== "rPr") . qName . elName) (elChildren run) of
+    Nothing -> (False, False, 0)
+    Just rPr ->
+      ( flag "b" rPr, flag "i" rPr
+      , fromMaybe 0 $
+          findAttr (unqual "baseline") rPr >>= readMaybe . T.unpack )
+  where
+    flag name el = findAttr (unqual name) el `elem` [Just "1", Just "true"]
+
+runText :: Element -> Text
+runText = T.concat . map strContent .
+          filter ((== "t") . qName . elName) . elChildren
+
+-- | Text with a run format. Spaces at the edges stay outside the
+-- formatting, as Markdown emphasis can't start or end with a space.
+applyFormat :: RunFormat -> Text -> B.Inlines
+applyFormat (bold, italic, baseline) txt
+  | not (bold || italic || baseline /= 0) || T.null core = B.text txt
+  | otherwise = edge leading <> wrap (B.text core) <> edge trailing
+  where
+    isBlank = (`elem` (" \t\r\n" :: String))
+    core = T.dropAround isBlank txt
+    leading = T.takeWhile isBlank txt
+    trailing = T.takeWhileEnd isBlank txt
+    edge t = if T.null t then mempty else B.space
+    wrap = (if bold then B.strong else id) .
+           (if italic then B.emph else id) .
+           (if baseline > 0 then B.superscript
+              else if baseline < 0 then B.subscript else id)
+
+-- | The relationship id of a run's hyperlink (@a:hlinkClick@). Links
+-- that act within the presentation, such as a jump to another slide,
+-- carry an @action@ and are not kept.
+runLink :: Element -> Maybe Text
+runLink run = do
+  rPr <- find ((== "rPr") . qName . elName) (elChildren run)
+  link <- find ((== "hlinkClick") . qName . elName) (elChildren rPr)
+  case findAttr (unqual "action") link of
+    Just _ -> Nothing
+    Nothing -> fmap attrVal $ find isRelId (elAttribs link)
+  where
+    isRelId a = qName (attrKey a) == "id" && qURI (attrKey a) == Just relNs
+    relNs =
+      "http://schemas.openxmlformats.org/officeDocument/2006/relationships"
+
+-- | The attribute that marks a hyperlink whose target is still a
+-- relationship id
+linkRelAttr :: Text
+linkRelAttr = "pptx-relationship"
+
+-- | Replace the relationship id of each hyperlink read by
+-- 'paragraphInlines' with the relationship's target. A link whose
+-- relationship is missing is replaced by its text.
+resolveLinks :: [(Text, Text)] -> [Block] -> [Block]
+resolveLinks rels = walk resolve
+  where
+    resolve (Link (_, _, [(key, relId)]) inls _)
+      | key == linkRelAttr =
+          case lookup relId rels of
+            Just target -> Link nullAttr inls (target, "")
+            Nothing -> Span nullAttr inls
+    resolve x = x
+
+-- | An equation (@m:oMathPara@ or @m:oMath@) as math. If texmath can't
+-- read it, its text is kept.
+mathInlines :: Element -> B.Inlines
+mathInlines el =
+  case readOMML (showElement el) of
+    Right exps
+      | qName (elName el) == "oMathPara" -> B.displayMath (writeTeX exps)
+      | otherwise -> B.math (writeTeX exps)
+    Left _ -> B.text $ T.concat $ map strContent $
+                filterElementsName ((== "t") . qName) el
+
+-- | Extract text from DrawingML element (all its paragraphs)
 extractDrawingMLText :: Element -> Text
-extractDrawingMLText el =
-  let textElems = filterElementsName (\qn -> qName qn == "t") el
-      texts = map strContent textElems
-   in T.unwords $ filter (not . T.null) texts
+extractDrawingMLText = drawingMLText
 
--- | Convert paragraphs to blocks, grouping bullets into lists
+-- | Convert paragraphs to blocks, grouping bulleted and numbered
+-- paragraphs into lists. Paragraphs at a deeper level than a list item
+-- go inside that item, as a nested list or as further paragraphs.
 paragraphsToBlocks :: [PptxParagraph] -> [Block]
-paragraphsToBlocks paras =
-  -- If we have multiple paragraphs with bullets, group them
-  let hasBullets = any (\p -> paraBullet p /= NoBullet) paras
-   in if hasBullets
-      then groupBulletParagraphs paras
-      else map (\p -> Para [Str $ paraText p]) paras
-
--- | Group bullet paragraphs into lists
-groupBulletParagraphs :: [PptxParagraph] -> [Block]
-groupBulletParagraphs paras =
-  let grouped = groupBy sameBulletLevel paras
-   in concatMap groupToBlock grouped
+paragraphsToBlocks [] = []
+paragraphsToBlocks (p:ps)
+  | paraBullet p == NoBullet = Para (paraText p) : paragraphsToBlocks ps
+  -- PowerPoint shows no bullet or number on an empty paragraph
+  | isEmpty p = paragraphsToBlocks ps
+  | otherwise =
+      let (items, rest) = listItems p (p:ps)
+       in listBlock (paraBullet p) items : paragraphsToBlocks rest
   where
-    sameBulletLevel p1 p2 =
-      (paraBullet p1 /= NoBullet) &&
-      (paraBullet p2 /= NoBullet) &&
-      (paraLevel p1 == paraLevel p2)
+    -- The items of a list that starts with the paragraph first, with the
+    -- deeper paragraphs that follow each item
+    listItems first (q:qs)
+      | isEmpty q, paraBullet q /= NoBullet = listItems first qs
+      | paraLevel q == paraLevel first, sameKind q first =
+          let (inner, rest) = span ((> paraLevel first) . paraLevel) qs
+              (items, rest') = listItems first rest
+           in ((Plain (paraText q) : paragraphsToBlocks inner) : items, rest')
+    listItems _ qs = ([], qs)
+    sameKind a b = case (paraBullet a, paraBullet b) of
+      (Numbered _, Numbered _) -> True
+      (Numbered _, _) -> False
+      (_, Numbered _) -> False
+      (x, y) -> (x == NoBullet) == (y == NoBullet)
+    listBlock (Numbered attrs) items = OrderedList attrs items
+    listBlock _ items = BulletList items
+    isEmpty = all blank . paraText
+    blank il = case il of
+      Space -> True
+      SoftBreak -> True
+      LineBreak -> True
+      Str t -> T.all isSpace t
+      _ -> False
 
-    groupToBlock :: [PptxParagraph] -> [Block]
-    groupToBlock [] = []
-    groupToBlock ps@(p:_)
-      | paraBullet p /= NoBullet =
-          -- Bullet list
-          let items = map (\para -> [Plain [Str $ paraText para]]) ps
-           in [BulletList items]
-      | otherwise =
-          -- Plain paragraph
-          map (\para -> Para [Str $ paraText para]) ps
+-- | Check if shape is a slide number placeholder
+isSlideNumberPlaceholder :: NameSpaces -> Element -> Bool
+isSlideNumberPlaceholder ns el =
+  maybe False ((== Just "sldNum") . findAttr (unqual "type")) $
+    findChildByName ns "p" "nvSpPr" el >>=
+    findChildByName ns "p" "nvPr" >>=
+    findChildByName ns "p" "ph"
 
 -- | Check if shape is title placeholder (also used in Slides module)
 isTitlePlaceholder :: NameSpaces -> Element -> Bool
@@ -328,3 +602,7 @@
         Just phType -> phType == "title" || phType == "ctrTitle"
         Nothing -> False
     Nothing -> False
+
+-- | The graphic data URI of a chart
+chartUri :: Text
+chartUri = "http://schemas.openxmlformats.org/drawingml/2006/chart"
diff --git a/src/Text/Pandoc/Readers/Pptx/Slides.hs b/src/Text/Pandoc/Readers/Pptx/Slides.hs
--- a/src/Text/Pandoc/Readers/Pptx/Slides.hs
+++ b/src/Text/Pandoc/Readers/Pptx/Slides.hs
@@ -15,16 +15,20 @@
   ) where
 
 import Codec.Archive.Zip (Archive)
+import Control.Applicative ((<|>))
 import Data.List (find)
-import Data.Maybe (mapMaybe)
+import qualified Data.Map as M
+import Data.Maybe (fromMaybe, mapMaybe)
 import qualified Data.Text as T
 import Data.Text (Text)
+import qualified Text.Pandoc.Builder as B
 import Text.Pandoc.Class.PandocMonad (PandocMonad)
 import Text.Pandoc.Definition
 import Text.Pandoc.Options (ReaderOptions)
 import Text.Pandoc.Readers.OOXML.Shared
 import Text.Pandoc.Readers.Pptx.Parse
 import Text.Pandoc.Readers.Pptx.Shapes
+import Text.Pandoc.Shared (stringify)
 import Text.Pandoc.XML.Light
 
 -- | Convert Pptx intermediate representation to Pandoc AST
@@ -42,7 +46,7 @@
 slideToBlocks :: PandocMonad m => Archive -> PptxSlide -> m [Block]
 slideToBlocks archive slide = do
   let SlideId n = slideId slide
-      slideElem = slideElement slide
+      slideElem = resolveAlternateContent (slideElement slide)
       rels = slideRels slide
       ns = elemToNameSpaces slideElem
 
@@ -54,20 +58,61 @@
       headerText = if T.null title
                    then "Slide " <> T.pack (show n)
                    else title
-      header = Header 2 (slideIdent, [], []) [Str headerText]
+      -- A slide hidden from the slide show (show="0") is still read,
+      -- with a "hidden" class on its header.
+      classes = ["hidden" | findAttr (unqual "show") slideElem == Just "0"]
+      header = Header 2 (slideIdent, classes, [])
+                 (B.toList (B.text headerText))
 
   -- Parse shapes and convert to blocks
   case findChildByName ns "p" "cSld" slideElem >>=
        findChildByName ns "p" "spTree" of
-    Nothing -> return [header]
+    Nothing -> return $ header : notesBlocks
     Just spTree -> do
       -- Filter out title placeholder shapes before parsing
-      let allShapeElems = onlyElems $ elContent spTree
+      let allShapeElems = ungroupShapes ns (onlyElems $ elContent spTree)
           nonTitleShapeElems = filter (not . isTitlePlaceholder ns) allShapeElems
-          shapes = mapMaybe (parseShape ns) nonTitleShapeElems
+          inherited = inheritedBullets (slideLayout slide) (slideMaster slide)
+          shapes = mapMaybe (\el -> parseShapeWith (inherited el) ns el)
+                            nonTitleShapeElems
       shapeBlocks <- concat <$> mapM (shapeToBlocks archive rels) shapes
-      return $ header : shapeBlocks
+      return $ header : shapeBlocks ++ notesBlocks
+  where
+    notesBlocks = maybe [] notesToBlocks (slideNotes slide)
 
+-- | Convert a notes slide (@p:notes@) to a @notes@ div, the form the pptx
+-- writer turns into speaker notes. The notes text is in the shape holding
+-- the body placeholder; the slide image and slide number placeholders are
+-- ignored. Notes without text yield nothing.
+notesToBlocks :: Element -> [Block]
+notesToBlocks notesElem =
+  case filter isBody shapeElems >>= textBoxBlocks of
+    blocks | T.null (T.strip (stringify blocks)) -> []
+           | otherwise -> [Div ("", ["notes"], []) blocks]
+  where
+    ns = elemToNameSpaces notesElem
+    shapeElems = maybe [] elChildren $
+      findChildByName ns "p" "cSld" notesElem >>=
+      findChildByName ns "p" "spTree"
+    isBody el =
+      case findChildByName ns "p" "nvSpPr" el >>=
+           findChildByName ns "p" "nvPr" >>=
+           findChildByName ns "p" "ph" of
+        Just ph -> findAttr (unqual "type") ph == Just "body"
+        Nothing -> False
+    textBoxBlocks el = case parseShape ns el of
+      Just (PptxTextBox paras) -> paragraphsToBlocks paras
+      _ -> []
+
+-- | Replace each group shape (@p:grpSp@, possibly nested) by the shapes
+-- it contains, keeping document order.
+ungroupShapes :: NameSpaces -> [Element] -> [Element]
+ungroupShapes ns = concatMap ungroup
+  where
+    ungroup el
+      | isElem ns "p" "grpSp" el = ungroupShapes ns (elChildren el)
+      | otherwise = [el]
+
 -- | Extract title from title placeholder
 extractSlideTitle :: NameSpaces -> Element -> Text
 extractSlideTitle ns slideElem =
@@ -81,3 +126,38 @@
        in maybe "" extractDrawingMLText titleShape
 
 -- isTitlePlaceholder is imported from Shapes module
+
+-- | Replace each markup-compatibility block (@mc:AlternateContent@) by
+-- the content of its first @mc:Choice@ whose required namespaces the
+-- reader understands, or else by its @mc:Fallback@. PowerPoint and the
+-- pptx writer put the shapes holding equations (@a14:m@) in such blocks.
+resolveAlternateContent :: Element -> Element
+resolveAlternateContent = resolve mempty
+  where
+    resolve ns el =
+      let ns' = elemToNameSpaces el <> ns
+       in el{ elContent = concatMap (content ns') (elContent el) }
+    content ns (Elem el)
+      | isMce "AlternateContent" el =
+          let ns' = elemToNameSpaces el <> ns
+              branches = elChildren el
+              chosen = find (understood ns') branches <|>
+                       find (isMce "Fallback") branches
+           in case chosen of
+                Just branch ->
+                  concatMap (content (elemToNameSpaces branch <> ns'))
+                            (elContent branch)
+                Nothing -> []
+      | otherwise = [Elem (resolve ns el)]
+    content _ c = [c]
+    understood ns branch =
+      isMce "Choice" branch &&
+      all (\prefix -> M.lookup prefix (elemToNameSpaces branch <> ns)
+                         `elem` map Just understoodNamespaces)
+          (T.words $ fromMaybe "" $ findAttr (unqual "Requires") branch)
+    isMce name el =
+      qName (elName el) == name &&
+      qURI (elName el) ==
+        Just "http://schemas.openxmlformats.org/markup-compatibility/2006"
+    understoodNamespaces =
+      [ "http://schemas.microsoft.com/office/drawing/2010/main" ] -- a14
diff --git a/src/Text/Pandoc/Readers/Pptx/SmartArt.hs b/src/Text/Pandoc/Readers/Pptx/SmartArt.hs
--- a/src/Text/Pandoc/Readers/Pptx/SmartArt.hs
+++ b/src/Text/Pandoc/Readers/Pptx/SmartArt.hs
@@ -22,6 +22,7 @@
 import qualified Data.Text as T
 import qualified Data.Text.Lazy.Encoding as TL
 import Data.Text (Text)
+import qualified Text.Pandoc.Builder as B
 import Text.Pandoc.Definition
 import Text.Pandoc.Readers.OOXML.Shared
 import Text.Pandoc.XML.Light
@@ -136,8 +137,7 @@
   -- Extract text from dgm:t element (which contains a:p/a:r/a:t)
   let text = case findChildByName ns "dgm" "t" ptElem of
         Just tElem ->
-          -- Recursively get ALL text content from all descendants
-          getAllText tElem
+          drawingMLText tElem
         Nothing -> ""
 
   -- Only return nodes with actual text
@@ -200,19 +200,12 @@
 nodeToBlocks :: (Text, [Text]) -> [Block]
 nodeToBlocks (nodeText, childTexts) =
   if null childTexts
-    then [Para [Strong [Str nodeText]]]
-    else [ Para [Strong [Str nodeText]]
-         , BulletList [[Plain [Str child]] | child <- childTexts]
+    then [Para [Strong (inlines nodeText)]]
+    else [ Para [Strong (inlines nodeText)]
+         , BulletList [[Plain (inlines child)] | child <- childTexts]
          ]
-
--- | Recursively extract all text from an element and its descendants
-getAllText :: Element -> Text
-getAllText el =
-  let textFromContent (Text cdata) = cdData cdata
-      textFromContent (Elem e) = getAllText e
-      textFromContent _ = ""
-      texts = map textFromContent (elContent el)
-   in T.unwords $ filter (not . T.null) texts
+  where
+    inlines = B.toList . B.text
 
 -- Helper functions
 maybeToEither :: Text -> Maybe a -> Either Text a
diff --git a/src/Text/Pandoc/Readers/RST.hs b/src/Text/Pandoc/Readers/RST.hs
--- a/src/Text/Pandoc/Readers/RST.hs
+++ b/src/Text/Pandoc/Readers/RST.hs
@@ -393,6 +393,7 @@
   bodyElements <- do
     raw <- option "" indentedBlock
     parseFromString' parseBlocks $ (rawfirst <> raw) <> "\n\n"
+  guard (not (null bodyElements))
   optional blanklines
   pure (B.code opts, [bodyElements])
 
@@ -554,25 +555,22 @@
 -- code blocks
 --
 
--- read a line indented by a given string
-indentedLine :: (HasReaderOptions st, Monad m)
-             => Int -> ParsecT Sources st m Text
-indentedLine indents = try $ do
-  lookAhead spaceChar
-  gobbleAtMostSpaces indents
-  anyLine
-
 -- one or more indented lines, possibly separated by blank lines.
--- any amount of indentation will work.
+-- any amount of indentation will work; the minimum indentation
+-- is stripped from all lines (#12071).
 indentedBlock :: (HasReaderOptions st, Monad m)
               => ParsecT Sources st m Text
 indentedBlock = try $ do
-  indents <- length <$> lookAhead (many1 spaceChar)
+  lookAhead spaceChar
   lns <- many1 $ try $ do b <- option "" blanklines
-                          l <- indentedLine indents
-                          return (b <> l)
+                          lookAhead spaceChar
+                          n <- gobbleAtMostSpaces maxBound
+                          l <- anyLine
+                          return (b, n, l)
   optional blanklines
-  return $ T.unlines lns
+  let minIndent = minimum [n | (_, n, _) <- lns]
+  return $ T.unlines
+    [b <> T.replicate (n - minIndent) " " <> l | (b, n, l) <- lns]
 
 quotedBlock :: Monad m => ParsecT Sources st m Text
 quotedBlock = try $ do
@@ -1570,6 +1568,7 @@
 inline :: PandocMonad m => RSTParser m Inlines
 inline =
   (note          -- can start with whitespace, so try before ws
+    <|> quotedSymbol
     <|> do notAfterString >>= guard
            (link <|> inlineAnchor <|> strong <|> emph)
     <|> code
@@ -1599,8 +1598,11 @@
                       unless (canPrecedeOpener c) updateLastStrPos
                       return $ B.str $ T.singleton c
 
+-- Characters that may precede an inline markup start-string: the ASCII
+-- characters - : / ' " < ( [ { and similar non-ASCII punctuation.
 canPrecedeOpener :: Char -> Bool
 canPrecedeOpener c =
+  c == ':' || c == '/' || c == '\'' || c == '"' || c == '<' ||
   generalCategory c `elem`
    [OpenPunctuation, InitialQuote, FinalQuote, DashPunctuation, OtherSymbol]
 
@@ -1609,6 +1611,21 @@
   c <- satisfy isSpecialChar
   unless (canPrecedeOpener c) updateLastStrPos
   return $ B.str $ T.singleton c
+
+-- A start-string between an opening character and the matching closing
+-- character, as in (*) or "*", is not inline markup.
+quotedSymbol :: Monad m => RSTParser m Inlines
+quotedSymbol = try $ do
+  opener <- oneOf "([{<\"'\8216\8220"
+  case lookup opener openersClosers of
+    Nothing -> mzero
+    Just closer ->
+      B.text . (\c -> T.pack [opener, c, closer])
+         <$> try (oneOf "*`|" <* char closer)
+ where
+  openersClosers = [('(', ')'), ('[', ']'), ('{', '}'), ('<', '>'),
+                    ('"', '"'), ('\'', '\''),
+                    ('\8216', '\8217'), ('\8220', '\8221')]
 
 -- parses inline code, between codeStart and codeEnd
 code :: Monad m => RSTParser m Inlines
diff --git a/src/Text/Pandoc/Readers/RTF.hs b/src/Text/Pandoc/Readers/RTF.hs
--- a/src/Text/Pandoc/Readers/RTF.hs
+++ b/src/Text/Pandoc/Readers/RTF.hs
@@ -34,7 +34,7 @@
 import Text.Pandoc.Parsing
 import Text.Pandoc.Logging (LogMessage(UnsupportedCodePage))
 import Text.Pandoc.Shared (tshow)
-import Data.Char (isAlphaNum, chr, isAscii, isLetter, isSpace, ord)
+import Data.Char (chr, isAscii, isLetter, isSpace, ord)
 import qualified Data.ByteString.Lazy as BL
 import Data.Maybe (mapMaybe, fromMaybe)
 import Safe (lastMay, initSafe, headDef)
@@ -261,7 +261,8 @@
      <|> (ControlSymbol <$> anyChar) )
   controlWord = do
     name <- letterSequence
-    param <- parameter <* optional delimChar
+    param <- parameter
+    optional (char ' ')
     case name of
       "bin" -> do
         let n = fromMaybe 0 param
@@ -318,9 +319,6 @@
 isSpecial '\\' = True
 isSpecial '\n' = True
 isSpecial _ = False
-
-delimChar :: PandocMonad m => RTFParser m Char
-delimChar = satisfy (\c -> not (isAlphaNum c || isSpecial c))
 
 modifyGroup :: PandocMonad m
             => (Properties -> Properties)
diff --git a/src/Text/Pandoc/Readers/Typst.hs b/src/Text/Pandoc/Readers/Typst.hs
--- a/src/Text/Pandoc/Readers/Typst.hs
+++ b/src/Text/Pandoc/Readers/Typst.hs
@@ -752,6 +752,7 @@
     VInteger x -> pure $ replicate (fromIntegral x) B.ColWidthDefault
     VArray x -> pure $ normalizeWidths $ map toWidth (V.toList x)
     VNone -> pure [B.ColWidthDefault]
+    VAuto -> pure [B.ColWidthDefault]
     _ -> fail $ "Could not determine number of columns: " <> show columns
   let numcols = length widths
   align <- getField "align" fields
diff --git a/src/Text/Pandoc/Readers/Vimwiki.hs b/src/Text/Pandoc/Readers/Vimwiki.hs
--- a/src/Text/Pandoc/Readers/Vimwiki.hs
+++ b/src/Text/Pandoc/Readers/Vimwiki.hs
@@ -1,5 +1,4 @@
 {-# LANGUAGE OverloadedStrings #-}
-{-# LANGUAGE CPP #-}
 {- |
    Module      : Text.Pandoc.Readers.Vimwiki
    Copyright   : Copyright (C) 2017-2020 Yuchen Pei
@@ -372,7 +371,7 @@
 listTodoMarker :: PandocMonad m => VwParser m Inlines
 listTodoMarker = try $ do
   x <- (many spaceChar >> char '[')
-       *> oneOf " .oOX"
+       *> oneOf " .oOX-"
        <* (char ']' >> spaceChar)
   return $ makeListMarkerSpan x
 
@@ -384,6 +383,7 @@
             'o' -> "done2"
             'O' -> "done3"
             'X' -> "done4"
+            '-' -> "rejected"
             _   -> ""
     in
       B.spanWith ("", [cl], []) mempty
diff --git a/src/Text/Pandoc/Readers/Xlsx/Cells.hs b/src/Text/Pandoc/Readers/Xlsx/Cells.hs
--- a/src/Text/Pandoc/Readers/Xlsx/Cells.hs
+++ b/src/Text/Pandoc/Readers/Xlsx/Cells.hs
@@ -32,6 +32,7 @@
 data CellValue
   = TextValue Text
   | NumberValue Double
+  | BoolValue Bool
   | EmptyValue
   deriving (Show, Eq)
 
diff --git a/src/Text/Pandoc/Readers/Xlsx/Parse.hs b/src/Text/Pandoc/Readers/Xlsx/Parse.hs
--- a/src/Text/Pandoc/Readers/Xlsx/Parse.hs
+++ b/src/Text/Pandoc/Readers/Xlsx/Parse.hs
@@ -22,16 +22,22 @@
   ) where
 
 import Codec.Archive.Zip (Archive, Entry, findEntryByPath, fromEntry)
+import Control.Monad (join)
+import Data.Char (toLower)
 import Data.List (find)
 import qualified Data.Map.Strict as M
 import Data.Maybe (mapMaybe, fromMaybe)
 import qualified Data.Text as T
 import qualified Data.Text.Lazy.Encoding as TL
 import Data.Text (Text)
+import Data.Time.Calendar (Day, addDays, fromGregorian, showGregorian)
 import qualified Data.Vector as V
 import System.FilePath (splitFileName)
+import qualified System.FilePath.Posix as Posix
+import Text.Pandoc.Readers.OOXML.Charts (Chart, readChart)
 import Text.Pandoc.Readers.OOXML.Shared
 import Text.Pandoc.Readers.Xlsx.Cells
+import Text.Pandoc.Shared (collapseFilePath)
 import Text.Pandoc.XML.Light
 import Text.Read (readMaybe)
 
@@ -51,8 +57,19 @@
 -- | Style information
 data Styles = Styles
   { styleFonts :: V.Vector FontInfo
+  , styleCellFonts :: V.Vector Int
+    -- ^ For each cell format (@cellXfs@), the index of its font
+  , styleDateFormats :: V.Vector (Maybe DateFormat)
+    -- ^ For each cell format (@cellXfs@), what it shows of a date
   } deriving (Show)
 
+-- | What a date or time number format shows
+data DateFormat = DateFormat
+  { dateShowsDate :: Bool
+  , dateShowsTime :: Bool
+  , dateShowsSeconds :: Bool
+  } deriving (Show)
+
 -- | Complete XLSX document
 data Xlsx = Xlsx
   { xlsxWorkbook :: XlsxWorkbook
@@ -64,6 +81,7 @@
 -- | Workbook information
 data XlsxWorkbook = XlsxWorkbook
   { workbookSheetNames :: [(SheetId, Text, Text)]  -- (id, name, relId)
+  , workbookDate1904 :: Bool  -- ^ Dates count from 1904 rather than 1900
   } deriving (Show)
 
 -- | Individual worksheet
@@ -71,6 +89,9 @@
   { sheetId :: SheetId
   , sheetName :: Text
   , sheetCells :: M.Map CellRef XlsxCell
+  , sheetMerges :: [(CellRef, CellRef)]
+    -- ^ Merged ranges, as their top-left and bottom-right cells
+  , sheetCharts :: [Chart]  -- ^ In the order they are drawn
   } deriving (Show)
 
 -- | Parse XLSX archive
@@ -88,21 +109,20 @@
   -- Parse shared strings (look for sharedStrings relationship)
   sharedStrings <- case findRelWithTarget workbookRels "sharedStrings" of
     Just (_, target) -> do
-      let path = "xl/" ++ T.unpack target
-      el <- loadXMLFromArchive archive path
+      el <- loadXMLFromArchive archive (resolveTarget workbookPath target)
       parseSharedStrings el
     Nothing -> Right V.empty
 
   -- Parse styles
   styles <- case findRelWithTarget workbookRels "styles" of
     Just (_, target) -> do
-      let path = "xl/" ++ T.unpack target
-      el <- loadXMLFromArchive archive path
+      el <- loadXMLFromArchive archive (resolveTarget workbookPath target)
       parseStyles el
-    Nothing -> Right $ Styles V.empty
+    Nothing -> Right $ Styles V.empty V.empty V.empty
 
   -- Parse worksheets
-  sheets <- mapM (\sheetInfo -> parseSheet archive workbookRels sharedStrings styles sheetInfo)
+  sheets <- mapM (parseSheet archive workbookPath workbookRels sharedStrings
+                    styles (workbookDate1904 workbook))
                  (workbookSheetNames workbook)
 
   return $ Xlsx workbook sheets sharedStrings styles
@@ -119,7 +139,8 @@
     Nothing -> Left "No workbook.xml relationship found"
     Just rel -> do
       target <- maybeToEither "Missing Target" $ findAttr (unqual "Target") rel
-      return $ T.unpack target
+      -- The root relationships belong to the package itself.
+      return $ resolveTarget "" target
   where
     isOfficeDocRel el =
       case (findAttr (unqual "Type") el, findAttr (unqual "Target") el) of
@@ -139,8 +160,12 @@
   let sheetElems = filter (\e -> qName (elName e) == "sheet") (onlyElems $ elContent sheets)
   sheetRefs <- mapM (parseSheetRef ns) (zip [1..] sheetElems)
 
-  return $ XlsxWorkbook sheetRefs
+  let date1904 = maybe False (`elem` ["1", "true"]) $
+        find (\e -> qName (elName e) == "workbookPr") (elChildren wbElem)
+          >>= findAttr (unqual "date1904")
 
+  return $ XlsxWorkbook sheetRefs date1904
+
 parseSheetRef :: NameSpaces -> (Int, Element) -> Either Text (SheetId, Text, Text)
 parseSheetRef ns (idx, sheetElem) = do
   let name = fromMaybe ("Sheet" <> T.pack (show idx)) $
@@ -153,14 +178,22 @@
 parseSharedStrings :: Element -> Either Text SharedStrings
 parseSharedStrings sstElem = do
   let siElems = filter (\e -> qName (elName e) == "si") (onlyElems $ elContent sstElem)
-      strings = map extractString siElems
+      strings = map stringItemText siElems
   return $ V.fromList strings
-  where
-    extractString siElem =
-      case find (\e -> qName (elName e) == "t") (onlyElems $ elContent siElem) of
-        Just tElem -> strContent tElem
-        Nothing -> getAllText siElem
 
+-- | Text of a string item (@si@ in the shared strings, @is@ in an inline
+-- string cell): its @t@, or the @t@ of its rich-text runs (@r@)
+-- concatenated as written. Phonetic runs (@rPh@) are skipped.
+stringItemText :: Element -> Text
+stringItemText el = T.concat
+  [ strContent t
+  | child <- elChildren el
+  , t <- case qName (elName child) of
+           "t" -> [child]
+           "r" -> filter (\e -> qName (elName e) == "t") (elChildren child)
+           _   -> []
+  ]
+
 -- | Parse styles (fonts only for MVP)
 parseStyles :: Element -> Either Text Styles
 parseStyles stylesElem = do
@@ -169,8 +202,108 @@
       fontElems = maybe [] (\fe -> filter (\e -> qName (elName e) == "font") (onlyElems $ elContent fe)) fontsElem
       fonts = V.fromList $ map (parseFont mempty) fontElems
 
-  return $ Styles fonts
+      -- A cell's style index (@s@) refers to a cell format in <cellXfs>,
+      -- which refers to its font by @fontId@ and its number format by
+      -- @numFmtId@.
+      children name el = filter (\e -> qName (elName e) == name) (elChildren el)
+      cellFormats =
+        [ xf
+        | cellXfs <- children "cellXfs" stylesElem
+        , xf <- children "xf" cellXfs
+        ]
+      cellFonts = V.fromList
+        [ fromMaybe 0 $ findAttr (unqual "fontId") xf >>= readMaybe . T.unpack
+        | xf <- cellFormats
+        ]
 
+      -- Number formats: custom ones from <numFmts>, by id
+      customFormats = M.fromList
+        [ (fmtId, code)
+        | numFmts <- children "numFmts" stylesElem
+        , numFmt <- children "numFmt" numFmts
+        , Just fmtId <- [findAttr (unqual "numFmtId") numFmt >>=
+                           readMaybe . T.unpack]
+        , Just code <- [findAttr (unqual "formatCode") numFmt]
+        ]
+      xfDateFormat xf = do
+        fmtId <- findAttr (unqual "numFmtId") xf >>= readMaybe . T.unpack
+        maybe (builtinDateFormat fmtId) customDateFormat
+          (M.lookup fmtId customFormats)
+      dateFormats = V.fromList $ map xfDateFormat cellFormats
+
+  return $ Styles fonts cellFonts dateFormats
+
+-- | The built-in number formats that show dates or times. Format 46,
+-- @[h]:mm:ss@, shows a duration rather than a time of day.
+builtinDateFormat :: Int -> Maybe DateFormat
+builtinDateFormat fmtId
+  | fmtId >= 14 && fmtId <= 17 = Just $ DateFormat True False False
+  | fmtId == 18 || fmtId == 20 = Just $ DateFormat False True False
+  | fmtId == 19 || fmtId == 21 || fmtId == 45 || fmtId == 47
+                               = Just $ DateFormat False True True
+  | fmtId == 22                = Just $ DateFormat True True False
+  | otherwise                  = Nothing
+
+-- | Whether a custom format code shows a date or a time: whether its
+-- first section has a date or time token (y, m, d, h, s) outside quoted
+-- text, escaped characters and brackets. A bracketed elapsed-time token
+-- such as @[h]@ makes it a duration, which isn't treated as a date.
+customDateFormat :: Text -> Maybe DateFormat
+customDateFormat code
+  | elapsed = Nothing
+  | showsDate || showsTime = Just $ DateFormat showsDate showsTime hasS
+  | otherwise = Nothing
+  where
+    (tokens, brackets) = scan (T.unpack (T.takeWhile (/= ';') code)) [] []
+    has c = c `elem` tokens
+    hasS = has 's'
+    showsTime = has 'h' || hasS
+    showsDate = has 'y' || has 'd' || (has 'm' && not showsTime)
+    elapsed = any (\b -> not (null b) && all (`elem` ("hms" :: String)) b)
+                  brackets
+    -- Collect the letters outside quotes, escapes and brackets, and the
+    -- contents of brackets.
+    scan [] ts bs = (ts, bs)
+    scan ('"':cs) ts bs = scan (drop 1 (dropWhile (/= '"') cs)) ts bs
+    scan ('\\':_:cs) ts bs = scan cs ts bs
+    scan ('_':_:cs) ts bs = scan cs ts bs
+    scan ('*':_:cs) ts bs = scan cs ts bs
+    scan ('[':cs) ts bs =
+      let (inside, rest) = break (== ']') cs
+       in scan (drop 1 rest) ts (map toLower inside : bs)
+    scan (c:cs) ts bs = scan cs (toLower c : ts) bs
+
+-- | Render a date serial number under a date or time format, as an ISO
+-- 8601 date (@2023-11-01@), time (@14:30@ or @14:30:05@), or both joined
+-- by a space. Nothing if the number isn't a date the format can show:
+-- negative, or before the first day of the date system for a format
+-- that shows the date.
+formatDate :: Bool -> DateFormat -> Double -> Maybe Text
+formatDate date1904 fmt serial
+  | serial < 0 = Nothing
+  | otherwise = do
+      dateText <- if dateShowsDate fmt
+                    then (\d -> [showGregorian d]) <$> day
+                    else Just []
+      let timeText = [ showTime | dateShowsTime fmt ]
+      return $ T.pack $ unwords (dateText ++ timeText)
+  where
+    seconds = round (serial * 86400) :: Integer
+    (days, secs) = seconds `divMod` 86400
+    day :: Maybe Day
+    day
+      | date1904 = Just $ addDays days (fromGregorian 1904 1 1)
+      -- 1900 system: day 1 is 1900-01-01, and day 60 is the 29 February
+      -- 1900 that Excel counts but that didn't exist.
+      | days < 1 || days == 60 = Nothing
+      | days < 60 = Just $ addDays days (fromGregorian 1899 12 31)
+      | otherwise = Just $ addDays days (fromGregorian 1899 12 30)
+    (h, rest) = secs `divMod` 3600
+    (m, s) = rest `divMod` 60
+    pad n = (if n < 10 then ('0' :) else id) (show n)
+    showTime = pad h ++ ":" ++ pad m ++
+               (if dateShowsSeconds fmt then ":" ++ pad s else "")
+
 parseFont :: NameSpaces -> Element -> FontInfo
 parseFont _ns fontElem =
   FontInfo
@@ -180,33 +313,86 @@
     }
 
 -- | Parse individual worksheet
-parseSheet :: Archive -> [(Text, Text)] -> SharedStrings -> Styles -> (SheetId, Text, Text) -> Either Text XlsxSheet
-parseSheet archive rels sharedStrings styles (sid, name, relId) = do
+parseSheet :: Archive -> FilePath -> [(Text, Text)] -> SharedStrings -> Styles
+           -> Bool -> (SheetId, Text, Text) -> Either Text XlsxSheet
+parseSheet archive wbPath rels sharedStrings styles date1904
+           (sid, name, relId) = do
   target <- maybeToEither ("Sheet relationship not found: " <> relId) $
             lookup relId rels
 
-  let sheetPath = "xl/" ++ T.unpack target
+  let sheetPath = resolveTarget wbPath target
   sheetElem <- loadXMLFromArchive archive sheetPath
 
-  cells <- parseSheetCells sheetElem sharedStrings styles
+  cells <- parseSheetCells sheetElem sharedStrings styles date1904
 
-  return $ XlsxSheet sid name cells
+  let merges =
+        [ (from, to)
+        | mergeCells <- filter (\e -> qName (elName e) == "mergeCells")
+                               (elChildren sheetElem)
+        , mergeCell <- filter (\e -> qName (elName e) == "mergeCell")
+                              (elChildren mergeCells)
+        , Just ref <- [findAttr (unqual "ref") mergeCell]
+        , (fromText, toText) <- [T.breakOn ":" ref]
+        , Right from <- [parseCellRef fromText]
+        , Right to <- [parseCellRef (T.drop 1 toText)]
+        ]
 
+  return $ XlsxSheet sid name cells merges
+           (sheetChartsOf archive sheetPath)
+
+-- | The charts on a worksheet or chart sheet: those its drawing refers
+-- to, in document order. A drawing or chart that can't be read is left
+-- out.
+sheetChartsOf :: Archive -> FilePath -> [Chart]
+sheetChartsOf archive sheetPath = fromMaybe [] $ do
+  drawingTarget <- findRelTargetByType archive (relsPathFor sheetPath)
+                     "drawing"
+  let drawingPath = resolveTarget sheetPath drawingTarget
+  drawing <- either (const Nothing) Just $
+             loadXMLFromArchive archive drawingPath
+  drawingRels <- either (const Nothing) Just $
+                 loadRelationships archive (relsPathFor drawingPath)
+  return
+    [ chart
+    | chartElem <- filterElementsName ((== "chart") . qName) drawing
+    , Just relId <- [lookupRelId chartElem]
+    , Just chartTarget <- [lookup relId drawingRels]
+    , Right chart <- [readChart archive
+                        (resolveTarget drawingPath chartTarget)]
+    ]
+  where
+    lookupRelId el = attrVal <$> find isRelId (elAttribs el)
+    isRelId a = qName (attrKey a) == "id" && qURI (attrKey a) == Just
+      "http://schemas.openxmlformats.org/officeDocument/2006/relationships"
+
+-- | Find the target of the first relationship in a .rels part whose Type
+-- ends with the given name, such as @drawing@
+findRelTargetByType :: Archive -> FilePath -> Text -> Maybe Text
+findRelTargetByType archive relsPath typeName = do
+  entry <- findEntryByPath relsPath archive
+  relsElem <- either (const Nothing) Just $ parseXMLFromEntry entry
+  rel <- find hasType (onlyElems $ elContent relsElem)
+  findAttr (unqual "Target") rel
+  where
+    hasType el = maybe False (("/" <> typeName) `T.isSuffixOf`) $
+                 findAttr (unqual "Type") el
+
 -- | Parse sheet cells
-parseSheetCells :: Element -> SharedStrings -> Styles -> Either Text (M.Map CellRef XlsxCell)
-parseSheetCells sheetElem sharedStrings styles = do
+parseSheetCells :: Element -> SharedStrings -> Styles -> Bool
+                -> Either Text (M.Map CellRef XlsxCell)
+parseSheetCells sheetElem sharedStrings styles date1904 = do
   -- Find sheetData by local name
   case find (\e -> qName (elName e) == "sheetData") (onlyElems $ elContent sheetElem) of
     Nothing -> return M.empty
     Just sheetData -> do
       let rowElems = filter (\e -> qName (elName e) == "row") (onlyElems $ elContent sheetData)
           cellElems = concatMap (\r -> filter (\e -> qName (elName e) == "c") (onlyElems $ elContent r)) rowElems
-          cells = mapMaybe (parseCell sharedStrings styles) cellElems
+          cells = mapMaybe (parseCell sharedStrings styles date1904) cellElems
       return $ M.fromList [(cellRef c, c) | c <- cells]
 
 -- | Parse individual cell
-parseCell :: SharedStrings -> Styles -> Element -> Maybe XlsxCell
-parseCell sharedStrings styles cElem = do
+parseCell :: SharedStrings -> Styles -> Bool -> Element -> Maybe XlsxCell
+parseCell sharedStrings styles date1904 cElem = do
   -- Get cell reference
   refText <- findAttr (unqual "r") cElem
   cellRefParsed <- either (const Nothing) Just $ parseCellRef refText
@@ -227,20 +413,32 @@
                   Just idx | idx >= 0 && idx < V.length sharedStrings ->
                     TextValue (sharedStrings V.! idx)
                   _ -> EmptyValue
+              else if cellType == "inlineStr"
+                then
+                  -- Inline string, held in the cell itself rather than in <v>
+                  maybe EmptyValue (TextValue . stringItemText) $
+                    find (\e -> qName (elName e) == "is") (elChildren cElem)
               else if T.null vText
                 then EmptyValue
+              else if cellType == "b"
+                then BoolValue (vText == "1")
                 else
                   -- Number
                   case readMaybe (T.unpack vText) of
-                    Just n -> NumberValue n
+                    Just n
+                      | Just txt <- dateFormat >>= \f -> formatDate date1904 f n
+                      -> TextValue txt
+                      | otherwise -> NumberValue n
                     Nothing -> TextValue vText
+      dateFormat = join $ styleIdx >>= (styleDateFormats styles V.!?)
 
   -- Get formatting from style
-  let (bold, italic) = case styleIdx of
-        Just idx | idx >= 0 && idx < V.length (styleFonts styles) ->
-          let font = styleFonts styles V.! idx
-           in (fontBold font, fontItalic font)
-        _ -> (False, False)
+  let font = do
+        idx <- styleIdx
+        fontIdx <- styleCellFonts styles V.!? idx
+        styleFonts styles V.!? fontIdx
+      (bold, italic) = maybe (False, False)
+                         (\f -> (fontBold f, fontItalic f)) font
 
   return $ XlsxCell cellRefParsed value bold italic
 
@@ -275,6 +473,15 @@
   let (dir, file) = splitFileName path
    in dir ++ "/_rels/" ++ file ++ ".rels"
 
+-- | Resolve a relationship target to an archive path. A target starting
+-- with @/@ is relative to the package root; any other target is relative
+-- to the folder of the part that holds the relationship.
+resolveTarget :: FilePath -> Text -> FilePath
+resolveTarget source target =
+  case T.unpack target of
+    '/':path -> path
+    path -> collapseFilePath (Posix.takeDirectory source Posix.</> path)
+
 findRelWithTarget :: [(Text, Text)] -> Text -> Maybe (Text, Text)
 findRelWithTarget rels targetName =
   find (\(_, target) -> targetName `T.isInfixOf` target) rels
@@ -282,14 +489,6 @@
 maybeToEither :: Text -> Maybe a -> Either Text a
 maybeToEither err Nothing = Left err
 maybeToEither _ (Just x) = Right x
-
-getAllText :: Element -> Text
-getAllText el =
-  let textFromContent (Text cdata) = cdData cdata
-      textFromContent (Elem e) = getAllText e
-      textFromContent _ = ""
-      texts = map textFromContent (elContent el)
-   in T.unwords $ filter (not . T.null) texts
 
 addContext :: Either Text a -> Text -> Either Text a
 addContext (Right x) _ = Right x
diff --git a/src/Text/Pandoc/Readers/Xlsx/Sheets.hs b/src/Text/Pandoc/Readers/Xlsx/Sheets.hs
--- a/src/Text/Pandoc/Readers/Xlsx/Sheets.hs
+++ b/src/Text/Pandoc/Readers/Xlsx/Sheets.hs
@@ -15,11 +15,14 @@
   ) where
 
 import qualified Data.Map.Strict as M
+import qualified Data.Set as S
 import qualified Data.Text as T
 import Data.List (sort, dropWhileEnd)
+import Numeric (floatToDigits)
 import Data.Char (isSpace)
 import Text.Pandoc.Definition
 import Text.Pandoc.Options (ReaderOptions)
+import Text.Pandoc.Readers.OOXML.Charts (chartToBlocks)
 import Text.Pandoc.Readers.Xlsx.Parse
 import Text.Pandoc.Readers.Xlsx.Cells
 import qualified Text.Pandoc.Builder as B
@@ -43,7 +46,7 @@
       tableBlock = case cellsToTable sheet of
         Just tbl -> [tbl]
         Nothing -> []  -- Empty sheet
-   in header : tableBlock
+   in header : tableBlock ++ concatMap chartToBlocks (sheetCharts sheet)
 
 -- | Convert cells to Pandoc Table
 cellsToTable :: XlsxSheet -> Maybe Block
@@ -59,7 +62,7 @@
           maxRow = maximum $ map cellRefRow refs
 
           -- Build dense grid
-          grid = [ [ M.lookup (CellRef col row) cells
+          grid = [ [ (CellRef col row, M.lookup (CellRef col row) cells)
                    | col <- [minCol..maxCol]
                    ]
                  | row <- [minRow..maxRow]
@@ -71,19 +74,42 @@
             [] -> ([], [])
 
           -- Filter out trailing empty rows (rows with only whitespace)
-          filteredBodyRows = dropWhileEnd isEmptyRow bodyRows
+          filteredBodyRows = dropWhileEnd (isEmptyRow . map snd) bodyRows
+          lastRow = minRow + length filteredBodyRows
 
-          makeCell mcell = case mcell of
-            Just cell ->
-              let inlines = cellToInlines cell
-               in Cell nullAttr AlignDefault (RowSpan 1) (ColSpan 1) [Plain inlines]
-            Nothing ->
-              Cell nullAttr AlignDefault (RowSpan 1) (ColSpan 1) [Plain []]
+          -- A merged range becomes one cell spanning its rows and
+          -- columns, clipped to the table and kept within the header row
+          -- or within the body, as a cell can't span both.
+          spans = M.fromList
+            [ (from, (rows, cols))
+            | (from, to) <- sheetMerges sheet
+            , cellRefCol from >= minCol, cellRefCol from <= maxCol
+            , cellRefRow from >= minRow, cellRefRow from <= lastRow
+            , let rows = if cellRefRow from == minRow
+                            then 1
+                            else min (cellRefRow to) lastRow
+                                   - cellRefRow from + 1
+                  cols = min (cellRefCol to) maxCol - cellRefCol from + 1
+            , rows > 1 || cols > 1
+            ]
+          covered = S.fromList
+            [ CellRef col row
+            | (CellRef c r, (rows, cols)) <- M.toList spans
+            , row <- [r .. r + rows - 1], col <- [c .. c + cols - 1]
+            , (col, row) /= (c, r)
+            ]
 
+          makeCell (ref, mcell) =
+            let (rows, cols) = M.findWithDefault (1, 1) ref spans
+             in Cell nullAttr AlignDefault (RowSpan rows) (ColSpan cols)
+                     [Plain (maybe [] cellToInlines mcell)]
+          makeRow = Row nullAttr . map makeCell .
+                    filter (\(ref, _) -> not (ref `S.member` covered))
+
           numCols = length headerRow
           colSpec = replicate numCols (AlignDefault, ColWidthDefault)
-          thead = TableHead nullAttr [Row nullAttr $ map makeCell headerRow]
-          tbody = [TableBody nullAttr 0 [] $ map (Row nullAttr . map makeCell) filteredBodyRows]
+          thead = TableHead nullAttr [makeRow headerRow]
+          tbody = [TableBody nullAttr 0 [] $ map makeRow filteredBodyRows]
           tfoot = TableFoot nullAttr []
 
        in Just $ Table nullAttr (Caption Nothing []) colSpec thead tbody tfoot
@@ -97,16 +123,62 @@
       EmptyValue -> True
       TextValue t -> T.all isSpace t
       NumberValue _ -> False
+      BoolValue _ -> False
 
 -- | Convert cell to Pandoc inlines
 cellToInlines :: XlsxCell -> [Inline]
 cellToInlines cell =
   let base = case cellValue cell of
         TextValue t -> B.toList $ B.text t
-        NumberValue n -> [Str $ T.pack $ show n]
+        NumberValue n -> [Str $ formatGeneral n]
+        BoolValue b -> [Str $ if b then "TRUE" else "FALSE"]
         EmptyValue -> []
 
       applyBold inls = if cellBold cell then [Strong inls] else inls
       applyItalic inls = if cellItalic cell then [Emph inls] else inls
 
    in applyItalic $ applyBold base
+
+-- | Render a number as Excel's General format does, without rounding
+-- it to fit a column: at most 15 significant digits (Excel's precision)
+-- and no trailing zeros. Numbers with 12 or more digits before the
+-- decimal point use scientific notation (@1.23456789012E+11@), as General
+-- does, keeping all their digits; so do numbers below 1e-9.
+formatGeneral :: Double -> T.Text
+formatGeneral x
+  | isNaN x || isInfinite x = T.pack (show x)
+  | x == 0 = "0"
+  | otherwise = T.pack $ sign ++ body
+  where
+    sign = if x < 0 then "-" else ""
+    (ds, e) = roundDigits 15 (floatToDigits 10 (abs x))
+    digits = concatMap show ds
+    -- abs x == 0.d1d2d3... * 10^e
+    body
+      | e > 11 || e < -8 = scientific
+      | e <= 0 = "0." ++ replicate (negate e) '0' ++ digits
+      | length ds <= e = digits ++ replicate (e - length ds) '0'
+      | otherwise = take e digits ++ "." ++ drop e digits
+    scientific =
+      let mantissa = case digits of
+            d:rest@(_:_) -> d : '.' : rest
+            _ -> digits
+          ex = e - 1
+       in mantissa ++ "E" ++ (if ex < 0 then "-" else "+") ++
+          (let a = show (abs ex) in if length a < 2 then '0' : a else a)
+
+-- | Round a digit list (as from 'floatToDigits') to at most n digits,
+-- dropping trailing zeros.
+roundDigits :: Int -> ([Int], Int) -> ([Int], Int)
+roundDigits n (ds, e) =
+  case splitAt n ds of
+    (_, []) -> (ds, e)
+    (keep, d:_) ->
+      case if d >= 5 then carry (reverse keep) else Just keep of
+        Just ds' -> (dropWhileEnd (== 0) ds', e)
+        Nothing -> ([1], e + 1)
+  where
+    -- Add one to a reversed digit list; Nothing if it overflows (all 9s).
+    carry [] = Nothing
+    carry (9:rest) = (++ [0]) <$> carry rest
+    carry (k:rest) = Just (reverse (k + 1 : rest))
diff --git a/src/Text/Pandoc/Shared.hs b/src/Text/Pandoc/Shared.hs
--- a/src/Text/Pandoc/Shared.hs
+++ b/src/Text/Pandoc/Shared.hs
@@ -1,5 +1,4 @@
 {-# LANGUAGE BangPatterns          #-}
-{-# LANGUAGE CPP                   #-}
 {-# LANGUAGE FlexibleContexts      #-}
 {-# LANGUAGE MultiParamTypeClasses #-}
 {-# LANGUAGE ScopedTypeVariables   #-}
@@ -50,6 +49,8 @@
                      compactify,
                      compactifyDL,
                      compactifyTable,
+                     plainToPara,
+                     paraToPlain,
                      linesToPara,
                      figureDiv,
                      makeSections,
@@ -457,10 +458,15 @@
              -> items
            _ -> map (fmap plainToPara) items
 
+-- | Convert a @Plain@ block to a @Para@; leave other blocks unchanged.
 plainToPara :: Block -> Block
 plainToPara (Plain ils) = Para ils
 plainToPara x = x
 
+-- | Convert a @Para@ block to a @Plain@; leave other blocks unchanged.
+paraToPlain :: Block -> Block
+paraToPlain (Para ils) = Plain ils
+paraToPlain x = x
 
 -- | Like @compactify@, but acts on items of definition lists.
 compactifyDL :: [(Inlines, [Blocks])] -> [(Inlines, [Blocks])]
@@ -490,8 +496,6 @@
   isSimpleCell [Plain _] = All True
   isSimpleCell _ = All False
   isSimpleTable = getAll . query isSimpleCell
-  paraToPlain (Para ils) = Plain ils
-  paraToPlain b = b
   -- walk descends into the notes, so we need to fix them back up:
   fixNotes (Note [Plain ils]) = Note [Para ils]
   fixNotes i = i
diff --git a/src/Text/Pandoc/Transforms.hs b/src/Text/Pandoc/Transforms.hs
--- a/src/Text/Pandoc/Transforms.hs
+++ b/src/Text/Pandoc/Transforms.hs
@@ -127,11 +127,13 @@
                   removeANSI (CodeBlock attr code) =
                     CodeBlock attr (removeANSIEscapes code)
                   removeANSI x = x
-                  removeANSIEscapes t
-                    | Just cs <- T.stripPrefix "\x1b[" t =
-                        removeANSIEscapes $ T.drop 1 $ T.dropWhile (/='m') cs
-                    | Just (c, cs) <- T.uncons t = T.cons c $ removeANSIEscapes cs
-                    | otherwise = ""
+                  removeANSIEscapes = T.concat . stripEscapes
+                  stripEscapes t =
+                    case T.breakOn "\x1b[" t of
+                      (before, rest)
+                        | T.null rest -> [before]
+                        | otherwise -> before :
+                            stripEscapes (T.drop 1 $ T.dropWhile (/= 'm') rest)
         go x = x
 
 -- | Remove soft breaks between East Asian characters.
diff --git a/src/Text/Pandoc/Translations.hs b/src/Text/Pandoc/Translations.hs
--- a/src/Text/Pandoc/Translations.hs
+++ b/src/Text/Pandoc/Translations.hs
@@ -1,5 +1,5 @@
-{-# LANGUAGE CPP                        #-}
 {-# LANGUAGE OverloadedStrings          #-}
+{-# LANGUAGE TypeApplications           #-}
 {- |
    Module      : Text.Pandoc.Translations
    Copyright   : Copyright (C) 2017-2024 John MacFarlane
@@ -27,18 +27,19 @@
 import Text.Pandoc.Logging (LogMessage(..))
 import Control.Monad.Except (catchError)
 import qualified Data.Text as T
-import qualified Data.Yaml as Yaml
-import qualified Text.Pandoc.UTF8 as UTF8
-import Data.Yaml (prettyPrintParseException)
+import qualified Data.List.NonEmpty as NE
+import qualified Yamlet as Y
+import Yamlet.Aeson
 import Text.Collate.Lang (Lang(..), renderLang)
 
--- | Parse YAML translations.
-readTranslations :: T.Text -> Either T.Text Translations
-readTranslations s =
-  case Yaml.decodeAllEither' $ UTF8.fromText s of
-       Left err' -> Left $ T.pack $ prettyPrintParseException err'
-       Right (t:_)     -> Right t
-       Right []        -> Left "empty YAML document"
+-- | Parse YAML translations. The file path is used in error messages.
+readTranslations :: FilePath -> T.Text -> Either T.Text Translations
+readTranslations fp s =
+  case Y.decodeAllText @(ViaAeson Translations) s of
+       Left errs -> Left $ T.intercalate "\n" $
+         map (T.pack . Y.prettyError fp) (NE.toList errs)
+       Right (ViaAeson t:_) -> Right t
+       Right []        -> Left $ T.pack fp <> ": empty YAML document"
 
 -- | Select the language to use with 'translateTerm'.
 -- Note that this does not read a translation file;
@@ -68,12 +69,11 @@
          let getTrans [] = return mempty
              getTrans (fp:fps) = do
                result <- catchError (Right <$> (readDataFile fp >>= toTextM fp))
-                             (\_ -> pure (Left ""))
-               case result >>= readTranslations of
+                             (\_ -> pure (Left (T.pack fp)))
+               case result >>= readTranslations fp of
                   Left e
                     | null fps -> do
-                      report $ CouldNotLoadTranslations (renderLang lang)
-                                  (T.pack fp <> ": " <> e)
+                      report $ CouldNotLoadTranslations (renderLang lang) e
                       -- make sure we don't try again...
                       modifyCommonState $ \st ->
                         st{ stTranslations = Nothing }
diff --git a/src/Text/Pandoc/Translations/Types.hs b/src/Text/Pandoc/Translations/Types.hs
--- a/src/Text/Pandoc/Translations/Types.hs
+++ b/src/Text/Pandoc/Translations/Types.hs
@@ -1,4 +1,3 @@
-{-# LANGUAGE CPP                        #-}
 {-# LANGUAGE DeriveGeneric              #-}
 {-# LANGUAGE GeneralizedNewtypeDeriving #-}
 {-# LANGUAGE OverloadedStrings          #-}
diff --git a/src/Text/Pandoc/Version.hs b/src/Text/Pandoc/Version.hs
--- a/src/Text/Pandoc/Version.hs
+++ b/src/Text/Pandoc/Version.hs
@@ -1,4 +1,3 @@
-{-# LANGUAGE CPP                   #-}
 {- |
    Module      : Text.Pandoc.Version
    Copyright   : Copyright (C) 2022-2024 John MacFarlane
diff --git a/src/Text/Pandoc/Writers/ANSI.hs b/src/Text/Pandoc/Writers/ANSI.hs
--- a/src/Text/Pandoc/Writers/ANSI.hs
+++ b/src/Text/Pandoc/Writers/ANSI.hs
@@ -79,9 +79,7 @@
   metadata <- metaToContext opts
                  (blockListToANSI opts)
                  (inlineListToANSI opts) meta
-  let colwidth = if writerWrapText opts == WrapAuto
-                    then Just $ writerColumns opts
-                    else Nothing
+  let colwidth = wrapColumns opts
   let title = titleBlock colwidth metadata
   let blocks' = makeSections (writerNumberSections opts) Nothing blocks
   body <- blockListToANSI opts blocks'
diff --git a/src/Text/Pandoc/Writers/AsciiDoc.hs b/src/Text/Pandoc/Writers/AsciiDoc.hs
--- a/src/Text/Pandoc/Writers/AsciiDoc.hs
+++ b/src/Text/Pandoc/Writers/AsciiDoc.hs
@@ -53,7 +53,6 @@
 import Text.Pandoc.Builder (emptyCell)
 import Text.Pandoc.Shared
 import Text.Pandoc.URI
-import Text.Pandoc.Templates (renderTemplate)
 import Text.Pandoc.Writers.Shared
 import Text.Pandoc.Walk (walk)
 
@@ -111,9 +110,6 @@
 pandocToAsciiDoc opts (Pandoc meta blocks) = do
   let titleblock = not $ null (docTitle meta) && null (docAuthors meta) &&
                          null (docDate meta)
-  let colwidth = if writerWrapText opts == WrapAuto
-                    then Just $ writerColumns opts
-                    else Nothing
   metadata <- metaToContext opts
               (blockListToAsciiDoc opts)
               (fmap chomp . inlineListToAsciiDoc opts)
@@ -126,10 +122,7 @@
                    isJust (writerTemplate opts))
                $ defField "math" (hasMath st && not (legacy st))
                $ defField "titleblock" titleblock metadata
-  return $ render colwidth $
-    case writerTemplate opts of
-       Nothing  -> main
-       Just tpl -> renderTemplate tpl context
+  return $ renderWithTemplate opts context main
 
 data EscContext = Normal | InTable
   deriving (Show, Eq)
diff --git a/src/Text/Pandoc/Writers/BibTeX.hs b/src/Text/Pandoc/Writers/BibTeX.hs
--- a/src/Text/Pandoc/Writers/BibTeX.hs
+++ b/src/Text/Pandoc/Writers/BibTeX.hs
@@ -26,10 +26,10 @@
 import Text.Pandoc.Citeproc.BibTeX as BibTeX
 import Text.Pandoc.Citeproc.MetaValue (metaValueToReference)
 import Text.Pandoc.Writers.Shared (lookupMetaString, defField,
-                                    addVariablesToContext)
-import Text.DocLayout (render, vcat)
+                                    addVariablesToContext,
+                                    renderWithTemplate)
+import Text.DocLayout (vcat)
 import Text.DocTemplates (Context(..))
-import Text.Pandoc.Templates (renderTemplate)
 
 -- | Write BibTeX based on the references metadata from a Pandoc document.
 writeBibTeX :: PandocMonad m => WriterOptions -> Pandoc -> m Text
@@ -50,10 +50,4 @@
   let main = vcat $ map (BibTeX.writeBibtexString opts variant mblang) refs
   let context  = defField "body" main
                  $ addVariablesToContext opts (mempty :: Context Text)
-  let colwidth = if writerWrapText opts == WrapAuto
-                    then Just $ writerColumns opts
-                    else Nothing
-  return $ render colwidth $
-    case writerTemplate opts of
-      Nothing  -> main
-      Just tpl -> renderTemplate tpl context
+  return $ renderWithTemplate opts context main
diff --git a/src/Text/Pandoc/Writers/ConTeXt.hs b/src/Text/Pandoc/Writers/ConTeXt.hs
--- a/src/Text/Pandoc/Writers/ConTeXt.hs
+++ b/src/Text/Pandoc/Writers/ConTeXt.hs
@@ -37,7 +37,6 @@
 import Text.DocLayout
 import Text.Pandoc.Shared
 import Text.Pandoc.URI (isURI)
-import Text.Pandoc.Templates (renderTemplate)
 import Text.Pandoc.Walk (query)
 import Text.Pandoc.Writers.Shared
 import Text.Printf (printf)
@@ -86,9 +85,6 @@
 
 pandocToConTeXt :: PandocMonad m => WriterOptions -> Pandoc -> WM m Text
 pandocToConTeXt options (Pandoc meta blocks) = do
-  let colwidth = if writerWrapText options == WrapAuto
-                    then Just $ writerColumns options
-                    else Nothing
   metadata <- metaToContext options
               blockListToConTeXt
               (fmap chomp . inlineListToConTeXt)
@@ -144,10 +140,7 @@
                         _                     -> id) metadata
   let context' = defField "context-dir" (maybe mempty toContextDir
                                          $ getField "dir" context) context
-  return $ render colwidth $
-    case writerTemplate options of
-       Nothing  -> main
-       Just tpl -> renderTemplate tpl context'
+  return $ renderWithTemplate options context' main
 
 -- change rtl to r2l, ltr to l2r
 toContextDir :: Doc Text -> Doc Text
diff --git a/src/Text/Pandoc/Writers/Djot.hs b/src/Text/Pandoc/Writers/Djot.hs
--- a/src/Text/Pandoc/Writers/Djot.hs
+++ b/src/Text/Pandoc/Writers/Djot.hs
@@ -27,11 +27,11 @@
 import qualified Data.Text as T
 import qualified Data.Map as M
 import qualified Text.Pandoc.UTF8 as UTF8
-import Text.Pandoc.Writers.Shared ( metaToContext, defField, toLegacyTable )
+import Text.Pandoc.Writers.Shared ( metaToContext, defField, toLegacyTable,
+                                    renderWithTemplate )
 import Text.Pandoc.Shared (isTightList, tshow, stringifyInlines,
                            onlySimpleTableCells, makeSections)
 import Text.DocLayout
-import Text.DocTemplates (renderTemplate)
 
 import Control.Monad.State (StateT(..), gets, modify)
 import Control.Monad (zipWithM, when)
@@ -43,9 +43,6 @@
 -- | Convert Pandoc to Djot.
 writeDjot :: PandocMonad m => WriterOptions -> Pandoc -> m Text
 writeDjot opts (Pandoc meta blocks) = do
-  let colwidth = if writerWrapText opts == WrapAuto
-                    then Just $ writerColumns opts
-                    else Nothing
   let ropts = RenderOptions{ preserveSoftBreaks =
                                writerWrapText opts == WrapPreserve }
   metadata <- metaToContext opts
@@ -56,10 +53,7 @@
   main <- renderDjot ropts <$>
             bodyToDjot opts (makeSections False Nothing blocks)
   let context  = defField "body" main metadata
-  return $ render colwidth $
-    case writerTemplate opts of
-       Nothing  -> main
-       Just tpl -> renderTemplate tpl context
+  return $ renderWithTemplate opts context main
 
 data DjotState =
   DjotState
diff --git a/src/Text/Pandoc/Writers/DocBook.hs b/src/Text/Pandoc/Writers/DocBook.hs
--- a/src/Text/Pandoc/Writers/DocBook.hs
+++ b/src/Text/Pandoc/Writers/DocBook.hs
@@ -66,9 +66,7 @@
 authorToDocBook :: PandocMonad m => WriterOptions -> [Inline] -> DB m B.Inlines
 authorToDocBook opts name' = do
   name <- render Nothing <$> inlinesToDocBook opts name'
-  let colwidth = if writerWrapText opts == WrapAuto
-                    then Just $ writerColumns opts
-                    else Nothing
+  let colwidth = wrapColumns opts
   return $ B.rawInline "docbook" $
     render colwidth $ inTags True "personname" [] $
       if T.any (== ',') name
@@ -99,9 +97,7 @@
 writeDocBook :: PandocMonad m => WriterOptions -> Pandoc -> DB m Text
 writeDocBook opts doc = do
   let Pandoc meta blocks = ensureValidXmlIdentifiers doc
-  let colwidth = if writerWrapText opts == WrapAuto
-                    then Just $ writerColumns opts
-                    else Nothing
+  let colwidth = wrapColumns opts
   let startLvl = getStartLvl opts
   let fromBlocks = blocksToDocBook opts .
                    makeSections False (Just startLvl)
@@ -126,11 +122,6 @@
 blocksToDocBook :: PandocMonad m => WriterOptions -> [Block] -> DB m (Doc Text)
 blocksToDocBook opts = fmap vcat . mapM (blockToDocBook opts)
 
--- | Auxiliary function to convert Plain block to Para.
-plainToPara :: Block -> Block
-plainToPara (Plain x) = Para x
-plainToPara x         = x
-
 -- | Convert a list of pairs of terms and definitions into a list of
 -- DocBook varlistentrys.
 deflistItemsToDocBook :: PandocMonad m
@@ -162,8 +153,8 @@
   inTagsIndented "listitem" <$> blocksToDocBook opts (map plainToPara item)
 
 imageToDocBook :: WriterOptions -> Attr -> Text -> Doc Text
-imageToDocBook _ attr src = selfClosingTag "imagedata" $
-  ("fileref", src) : idAndRole attr <> dims
+imageToDocBook opts attr src = selfClosingTag "imagedata" $
+  ("fileref", src) : idAndRole opts attr <> dims
   where
     dims = go Width "width" <> go Height "depth"
     go dir dstr = case dimension dir attr of
@@ -206,7 +197,8 @@
   return $ inTags True tag attribs $ inTagsSimple "title" title' $$ contents
 blockToDocBook opts (Div (ident,classes,_) bs) = do
   version <- ask
-  let identAttribs = [(idName version, ident) | not (T.null ident)]
+  let identAttribs = [(idName version, writerIdentifierPrefix opts <> ident)
+                     | not (T.null ident)]
       admonitions = ["caution","danger","important","note","tip","warning"]
   case classes of
     (l:_) | l `elem` admonitions -> do
@@ -396,7 +388,8 @@
   version <- ask
   ((if T.null ident
        then mempty
-       else selfClosingTag "anchor" [(idName version, ident)]) <>) <$>
+       else selfClosingTag "anchor"
+              [(idName version, writerIdentifierPrefix opts <> ident)]) <>) <$>
     inlinesToDocBook opts ils
 inlineToDocBook _ (Code _ str) =
   return $ inTagsSimple "literal" $ literal (escapeStringForXML str)
@@ -444,10 +437,10 @@
             then let tag = if null txt then "xref" else "link"
                  in  inTags False tag $
                      ("linkend", writerIdentifierPrefix opts <> T.drop 1 src) :
-                     idAndRole attr
+                     idAndRole opts attr
             else if version == DocBook5
-                    then inTags False "link" $ ("xlink:href", src) : idAndRole attr
-                    else inTags False "ulink" $ ("url", src) : idAndRole attr )
+                    then inTags False "link" $ ("xlink:href", src) : idAndRole opts attr
+                    else inTags False "ulink" $ ("url", src) : idAndRole opts attr )
         <$> inlinesToDocBook opts txt
 inlineToDocBook opts (Image attr ils (src, tit)) = return $
   let titleDoc = if T.null tit
@@ -469,10 +462,10 @@
 isMathML MathML = True
 isMathML _      = False
 
-idAndRole :: Attr -> [(Text, Text)]
-idAndRole (id',cls,_) = ident <> role
+idAndRole :: WriterOptions -> Attr -> [(Text, Text)]
+idAndRole opts (id',cls,_) = ident <> role
   where
-    ident = [("id", id') | not (T.null id')]
+    ident = [("id", writerIdentifierPrefix opts <> id') | not (T.null id')]
     role  = [("role", T.unwords cls) | not (null cls)]
 
 -- Used in blockToDocBook for Header (section) to create or extend
diff --git a/src/Text/Pandoc/Writers/Docx.hs b/src/Text/Pandoc/Writers/Docx.hs
--- a/src/Text/Pandoc/Writers/Docx.hs
+++ b/src/Text/Pandoc/Writers/Docx.hs
@@ -501,10 +501,7 @@
 loadArchives opts = do
   username <- P.lookupEnv "USERNAME"
   utctime <- P.getTimestamp
-  oldUserDataDir <- P.getUserDataDir
-  P.setUserDataDir Nothing
   res <- readDefaultDataFile "reference.docx"
-  P.setUserDataDir oldUserDataDir
   let distArchive = toArchive $ BL.fromStrict res
   refArchive <- case writerReferenceDoc opts of
                    Just f  -> do
diff --git a/src/Text/Pandoc/Writers/Docx/OpenXML.hs b/src/Text/Pandoc/Writers/Docx/OpenXML.hs
--- a/src/Text/Pandoc/Writers/Docx/OpenXML.hs
+++ b/src/Text/Pandoc/Writers/Docx/OpenXML.hs
@@ -152,9 +152,9 @@
     , "pPrChange"
     ] [0..])
 
-sortSquashed :: M.Map Text Int -> [Element] -> [Element]
+sortSquashed :: M.Map Text Int -> Set.Set Element -> [Element]
 sortSquashed tagOrder l =
-  sortBy (comparing tagIndex) l
+  sortBy (comparing tagIndex) (Set.toList l)
   where
     tagIndex :: Element -> Int
     tagIndex el =
@@ -162,8 +162,10 @@
       where tag = (qName . elName) el
 
 squashProps :: M.Map Text Int -> EnvProps -> [Element]
-squashProps tagOrder (EnvProps Nothing es) = sortSquashed tagOrder es
-squashProps tagOrder (EnvProps (Just e) es) = sortSquashed tagOrder (e : es)
+squashProps tagOrder (EnvProps Nothing es) =
+  sortSquashed tagOrder es
+squashProps tagOrder (EnvProps (Just e) es) =
+  sortSquashed tagOrder (Set.insert e es)
 
 -- | Certain characters are invalid in XML even if escaped.
 -- See #1992
@@ -545,7 +547,7 @@
                        else "Body Text"
       paraProps <- local (\env -> env{ envParaProperties =
                                         envParaProperties env <>
-                                        EnvProps (Just bodyTextStyle) [] })
+                                        EnvProps (Just bodyTextStyle) mempty })
                       (getParaProps displayMathPara)
       modify $ \s -> s { stFirstPara = False }
       contents <- inlinesToOpenXML opts lst
@@ -623,7 +625,7 @@
     then "Figure"
     else "Captioned Figure"
   paraProps <- local
-    (\env -> env { envParaProperties = EnvProps (Just prop) [] <>
+    (\env -> env { envParaProperties = EnvProps (Just prop) mempty <>
                                        envParaProperties env })
     (getParaProps False)
 
@@ -770,15 +772,29 @@
   let langnode = case mblang of
                    Nothing -> mempty
                    Just l  -> EnvProps Nothing
-                               [mknode "w:lang" [("w:val", l)] ()]
+                               (Set.singleton
+                                (mknode "w:lang" [("w:val", l)] ()))
   let squashed = squashProps rPrTagOrder (props <> langnode)
   return [mknode "w:rPr" [] squashed | (not . null) squashed]
 
 withTextProp :: PandocMonad m => Element -> WS m a -> WS m a
-withTextProp d p =
-  local (\env -> env {envTextProperties = ep <> envTextProperties env}) p
-  where ep = if isStyle d then EnvProps (Just d) [] else EnvProps Nothing [d]
+withTextProp d
+  | isStyle d = local (\env -> env{ envTextProperties = EnvProps (Just d)
+                                     (otherElements (envTextProperties env)) })
+  | isToggle d = local (\env ->
+                          let EnvProps mbsty elts = envTextProperties env
+                          in  env{ envTextProperties = EnvProps mbsty $
+                                    if d `Set.member` elts
+                                       then Set.delete d elts
+                                       else Set.insert d elts })
+  | otherwise = local (\env -> env{ envTextProperties =
+                                    EnvProps Nothing (Set.singleton d) <>
+                                    envTextProperties env })
 
+-- Let emphasis flip-flop, so emph within emph is upright:
+isToggle :: Element -> Bool
+isToggle el = qName (elName el) `elem` ["i", "iCs"]
+
 withTextPropM :: PandocMonad m => WS m Element -> WS m a -> WS m a
 withTextPropM md p = do
   d <- md
@@ -790,14 +806,21 @@
   listLevel <- asks envListLevel
   numid <- asks envListNumId
   numIdUsed <- gets stNumIdUsed
-  -- clear numId after first use to support multiple paragraphs in the same bullet
-  -- baseListId is the code for no list marker
-  let numid' = if numIdUsed then baseListId else numid
   modify $ \st -> st{ stNumIdUsed = True }
-  let listPr = [mknode "w:numPr" []
-                [ mknode "w:ilvl" [("w:val",tshow listLevel)] ()
-                , mknode "w:numId" [("w:val",tshow numid')] () ] | listLevel >= 0 && not displayMathPara]
-  return $ case squashProps pPrTagOrder (EnvProps Nothing listPr <> props) of
+  -- Only the first paragraph of a list item gets numbering.  Subsequent
+  -- paragraphs in the same item are not numbered, but indented to line
+  -- up with the item's text (see the w:ind in mkLvl), so that they are
+  -- not mistaken for items of another list (#9197):
+  let listPr
+        | listLevel < 0 || displayMathPara = []
+        | numIdUsed = [mknode "w:ind"
+                        [ ("w:left", tshow (listLevel * 720 + 720))
+                        , ("w:firstLine", "0") ] ()]
+        | otherwise = [mknode "w:numPr" []
+                        [ mknode "w:ilvl" [("w:val",tshow listLevel)] ()
+                        , mknode "w:numId" [("w:val",tshow numid)] () ]]
+  return $ case squashProps pPrTagOrder
+                  (EnvProps Nothing (Set.fromList listPr) <> props) of
                 [] -> []
                 ps -> [mknode "w:pPr" [] ps]
 
@@ -1040,7 +1063,7 @@
          tprops <- asks envTextProperties
          let r' = fromXLElement r
              mbhl = listToMaybe
-               [ e | e <- otherElements tprops
+               [ e | e <- Set.toList (otherElements tprops)
                     , XML.qName (XML.elName e) == "highlight"
                     , XML.qPrefix (XML.elName e) == Just "w" ]
          return [Elem (maybe r' (`highlightMathRuns` r') mbhl)]
@@ -1276,8 +1299,10 @@
   -- them to stack up.
   let hasBidi = any (\e -> (qName . elName) e == "bidi") (otherElements paraProps)
       hasRtl = any (\e -> (qName . elName) e == "rtl") (otherElements textProps)
-      paraProps' = filter (\e -> (qName . elName) e /= "bidi") (otherElements paraProps)
-      textProps' = filter (\e -> (qName . elName) e /= "rtl") (otherElements textProps)
+      paraProps' = Set.filter (\e -> (qName . elName) e /= "bidi")
+                     (otherElements paraProps)
+      textProps' = Set.filter (\e -> (qName . elName) e /= "rtl")
+                     (otherElements textProps)
       paraStyle = styleElement paraProps
       textStyle = styleElement textProps
   if not isRTL && not hasBidi && not hasRtl
@@ -1287,8 +1312,10 @@
     else if isRTL
     -- if we are going right-to-left, we (re?)add the properties.
     then flip local x $
-         \env -> env { envParaProperties = EnvProps paraStyle $ mknode "w:bidi" [] () : paraProps'
-                     , envTextProperties = EnvProps textStyle $ mknode "w:rtl" [] () : textProps'
+         \env -> env { envParaProperties = EnvProps paraStyle $
+                        Set.insert (mknode "w:bidi" [] ()) paraProps'
+                     , envTextProperties = EnvProps textStyle $
+                        Set.insert (mknode "w:rtl" [] ()) textProps'
                      }
     else flip local x $ \env -> env { envParaProperties = EnvProps paraStyle paraProps'
                                     , envTextProperties = EnvProps textStyle textProps'
diff --git a/src/Text/Pandoc/Writers/Docx/Types.hs b/src/Text/Pandoc/Writers/Docx/Types.hs
--- a/src/Text/Pandoc/Writers/Docx/Types.hs
+++ b/src/Text/Pandoc/Writers/Docx/Types.hs
@@ -69,14 +69,14 @@
 
 
 data EnvProps = EnvProps{ styleElement  :: Maybe Element
-                        , otherElements :: [Element]
+                        , otherElements :: Set.Set Element
                         } deriving (Show)
 
 instance Semigroup EnvProps where
-  EnvProps s es <> EnvProps s' es' = EnvProps (s <|> s') (es ++ es')
+  EnvProps s es <> EnvProps s' es' = EnvProps (s <|> s') (es <> es')
 
 instance Monoid EnvProps where
-  mempty = EnvProps Nothing []
+  mempty = EnvProps Nothing mempty
   mappend = (<>)
 
 data WriterEnv = WriterEnv
@@ -195,7 +195,9 @@
 withParaProp :: PandocMonad m => Element -> WS m a -> WS m a
 withParaProp d p =
   local (\env -> env {envParaProperties = ep <> envParaProperties env}) p
-  where ep = if isStyle d then EnvProps (Just d) [] else EnvProps Nothing [d]
+  where ep = if isStyle d
+                then EnvProps (Just d) mempty
+                else EnvProps Nothing (Set.singleton d)
 
 withParaPropM :: PandocMonad m => WS m Element -> WS m a -> WS m a
 withParaPropM md p = do
diff --git a/src/Text/Pandoc/Writers/EPUB.hs b/src/Text/Pandoc/Writers/EPUB.hs
--- a/src/Text/Pandoc/Writers/EPUB.hs
+++ b/src/Text/Pandoc/Writers/EPUB.hs
@@ -1,4 +1,3 @@
-{-# LANGUAGE CPP                 #-}
 {-# LANGUAGE FlexibleContexts    #-}
 {-# LANGUAGE PatternGuards       #-}
 {-# LANGUAGE OverloadedStrings   #-}
@@ -55,7 +54,7 @@
                            stringify, stringifyInlines, uniqueIdent, tshow)
 import qualified Text.Pandoc.UTF8 as UTF8
 import Text.Pandoc.UUID (getRandomUUID)
-import Text.Pandoc.Walk (walk, walkM)
+import Text.Pandoc.Walk (query, walk, walkM)
 import Text.Pandoc.Writers.HTML (writeHtmlStringForEPUB)
 import Text.Printf (printf)
 import Text.Pandoc.XML.Light
@@ -204,13 +203,14 @@
                        return m{ epubLanguage = localeLang }
           else return m
   let fixDate m =
-       if null (epubDate m)
-          then do
+       -- drop dates we could not normalize (dc:date must not be empty)
+       case filter (not . T.null . dateText) (epubDate m) of
+         [] -> do
             currentTime <- lift P.getTimestamp
             return $ m{ epubDate = [ Date{
                              dateText = showDateTimeISO8601 currentTime
                            , dateEvent = Nothing } ] }
-          else return m
+         ds -> return m{ epubDate = ds }
   let addAuthor m =
        if any (\c -> creatorRole c == Just "aut") $ epubCreator m
           then return m
@@ -1258,8 +1258,10 @@
 
 -- Add identifiers to any headers without them.
 addIdentifiers :: WriterOptions -> [Block] -> [Block]
-addIdentifiers opts bs = evalState (mapM go bs) Set.empty
- where go (Header n (ident,classes,kvs) ils) = do
+addIdentifiers opts bs = evalState (mapM go bs) (Set.fromList (query getId bs))
+ where getId (Header _ (ident,_,_) _) = [ident]
+       getId _ = []
+       go (Header n (ident,classes,kvs) ils) = do
          ids <- get
          let ident' = if T.null ident
                          then uniqueIdent (writerExtensions opts) ils ids
diff --git a/src/Text/Pandoc/Writers/HTML.hs b/src/Text/Pandoc/Writers/HTML.hs
--- a/src/Text/Pandoc/Writers/HTML.hs
+++ b/src/Text/Pandoc/Writers/HTML.hs
@@ -960,8 +960,6 @@
       classes' = case slideVariant of
         NoSlides -> classes
         _ -> filter (\k -> k /= "incremental" && k /= "nonincremental") classes
-  let paraToPlain (Para ils) = Plain ils
-      paraToPlain x          = x
   let bs' = if "csl-entry" `elem` classes'
                then walk paraToPlain bs
                else bs
diff --git a/src/Text/Pandoc/Writers/Haddock.hs b/src/Text/Pandoc/Writers/Haddock.hs
--- a/src/Text/Pandoc/Writers/Haddock.hs
+++ b/src/Text/Pandoc/Writers/Haddock.hs
@@ -16,7 +16,7 @@
 module Text.Pandoc.Writers.Haddock (writeHaddock) where
 import Control.Monad (zipWithM)
 import Control.Monad.State.Strict
-    ( StateT, MonadState(get), modify, evalStateT )
+    ( StateT, MonadState(get), gets, modify, evalStateT )
 import Data.Char (isAlphaNum)
 import Data.Default
 import Data.Text (Text)
@@ -28,7 +28,6 @@
 import Text.DocLayout
 import Text.Pandoc.Shared
 import Text.Pandoc.URI
-import Text.Pandoc.Templates (renderTemplate)
 import Text.Pandoc.Writers.Shared
 
 type Notes = [[Block]]
@@ -46,32 +45,35 @@
 pandocToHaddock :: PandocMonad m
                 => WriterOptions -> Pandoc -> StateT WriterState m Text
 pandocToHaddock opts (Pandoc meta blocks) = do
-  let colwidth = if writerWrapText opts == WrapAuto
-                    then Just $ writerColumns opts
-                    else Nothing
   body <- blockListToHaddock opts blocks
-  st <- get
-  notes' <- notesToHaddock opts (reverse $ stNotes st)
+  notes' <- notesToHaddock opts
   let main = body <> (if isEmpty notes' then empty else blankline <> notes')
   metadata <- metaToContext opts
                (blockListToHaddock opts)
                (fmap chomp . inlineListToHaddock opts)
                meta
   let context  = defField "body" main metadata
-  return $ render colwidth $
-    case writerTemplate opts of
-          Nothing  -> main
-          Just tpl -> renderTemplate tpl context
+  return $ renderWithTemplate opts context main
 
--- | Return haddock representation of notes.
+-- | Return haddock representation of the collected notes. Rendering a
+-- note may add further notes to the state (notes nested inside
+-- notes); keep going until all of them have been rendered.
 notesToHaddock :: PandocMonad m
-               => WriterOptions -> [[Block]] -> StateT WriterState m (Doc Text)
-notesToHaddock opts notes =
-  if null notes
-     then return empty
-     else do
-       contents <- blockToHaddock opts $ OrderedList (1,DefaultStyle,DefaultDelim) notes
-       return $ text "#notes#" <> blankline <> contents
+               => WriterOptions -> StateT WriterState m (Doc Text)
+notesToHaddock opts = do
+  contents <- go 0
+  return $ if null contents
+              then empty
+              else text "#notes#" <> blankline <> vcat contents
+  where
+    go done = do
+      notes <- gets (drop done . reverse . stNotes)
+      if null notes
+        then return []
+        else do
+          contents <- blockToHaddock opts $
+                        OrderedList (done + 1, DefaultStyle, DefaultDelim) notes
+          (contents :) <$> go (done + length notes)
 
 -- | Escape special characters for Haddock.
 escapeString :: Text -> Text
@@ -170,7 +172,7 @@
                          -> StateT WriterState m (Doc Text)
 orderedListItemToHaddock opts marker items = do
   contents <- blockListToHaddock opts items
-  let sps = case T.length marker - writerTabStop opts of
+  let sps = case writerTabStop opts - T.length marker of
                    n | n > 0 -> text $ replicate n ' '
                    _ -> text " "
   let start = literal marker <> sps
diff --git a/src/Text/Pandoc/Writers/ICML.hs b/src/Text/Pandoc/Writers/ICML.hs
--- a/src/Text/Pandoc/Writers/ICML.hs
+++ b/src/Text/Pandoc/Writers/ICML.hs
@@ -138,9 +138,7 @@
 writeICML :: PandocMonad m => WriterOptions -> Pandoc -> m Text
 writeICML opts doc = do
   let Pandoc meta blocks = ensureValidXmlIdentifiers doc
-  let colwidth = if writerWrapText opts == WrapAuto
-                    then Just $ writerColumns opts
-                    else Nothing
+  let colwidth = wrapColumns opts
       renderBlockMeta f s = fst <$> runStateT (f opts [] s) defaultWriterState
       renderInlineMeta f s = fst <$> runStateT (f opts [] "" s) defaultWriterState
   metadata <- metaToContext opts
diff --git a/src/Text/Pandoc/Writers/JATS.hs b/src/Text/Pandoc/Writers/JATS.hs
--- a/src/Text/Pandoc/Writers/JATS.hs
+++ b/src/Text/Pandoc/Writers/JATS.hs
@@ -170,9 +170,7 @@
                              (Header lev (ident,hcls,hkvs) hils : rs) : bs)
       splitBackBlocks b (fs, bs) = (b:fs, bs)
   let (bodyblocks, backblocks) = foldr splitBackBlocks ([],[]) blocks
-  let colwidth = if writerWrapText opts == WrapAuto
-                    then Just $ writerColumns opts
-                    else Nothing
+  let colwidth = wrapColumns opts
   metadata <- metaToContext opts
                  (blocksToJATS opts . makeSections False (Just startLvl))
                  (fmap chomp . inlinesToJATS opts)
@@ -240,11 +238,6 @@
            then inTags True "p" [("specific-use","wrapper")] inner
            else inner
 
--- | Auxiliary function to convert Plain block to Para.
-plainToPara :: Block -> Block
-plainToPara (Plain x) = Para x
-plainToPara x         = x
-
 -- | Convert a list of pairs of terms and definitions into a list of
 -- JATS varlistentrys.
 deflistItemsToJATS :: PandocMonad m
@@ -302,7 +295,7 @@
 codeAttr :: WriterOptions -> Attr -> (Text, [(Text, Text)])
 codeAttr opts (ident,classes,kvs) = (lang, attr)
     where
-       attr = [("id", escapeNCName ident) | not (T.null ident)] ++
+       attr = idAttr opts ident ++
               [("language",lang) | not (T.null lang)] ++
               [(k,v) | (k,v) <- kvs, k `elem` ["code-type",
                 "code-version", "executable",
@@ -310,6 +303,12 @@
                     "platforms", "position", "specific-use"]]
        lang  = languageFor opts classes
 
+-- | The id attribute for an element, with the identifier prefix added.
+idAttr :: WriterOptions -> Text -> [(Text, Text)]
+idAttr opts ident =
+  [("id", writerIdentifierPrefix opts <> escapeNCName ident)
+  | not (T.null ident)]
+
 -- <break/> is only allowed as a direct child of <td> or <title> or
 -- <article-title>
 fixLineBreak :: Inline -> Inline
@@ -319,10 +318,8 @@
 -- | Convert a Pandoc block element to JATS.
 blockToJATS :: PandocMonad m => WriterOptions -> Block -> JATS m (Doc Text)
 blockToJATS opts (Div (id',"section":_,kvs) (Header _lvl (_,_,hkvs) ils : xs)) = do
-  let idAttr = [ ("id", writerIdentifierPrefix opts <> escapeNCName id')
-               | not (T.null id')]
   let otherAttrs = ["sec-type", "specific-use"]
-  let attribs = idAttr ++ [(k,v) | (k,v) <- kvs, k `elem` otherAttrs]
+  let attribs = idAttr opts id' ++ [(k,v) | (k,v) <- kvs, k `elem` otherAttrs]
   title' <- inlinesToJATS opts (map fixLineBreak ils)
   let label = if writerNumberSections opts
                  then
@@ -336,7 +333,7 @@
       inTagsSimple "title" title' $$ contents
 -- Bibliography reference:
 blockToJATS opts (Div (ident,_,_) [Para lst]) | "ref-" `T.isPrefixOf` ident =
-  inTags True "ref" [("id", escapeNCName ident)] .
+  inTags True "ref" (idAttr opts ident) .
   inTagsSimple "mixed-citation" <$>
   inlinesToJATS opts lst
 blockToJATS opts (Div ("refs",_,_) xs) = do
@@ -353,7 +350,7 @@
   return $ inTagsIndented "ref-list" contents
 blockToJATS opts (Div (ident,[cls],kvs) bs) | cls `elem` ["fig", "caption", "table-wrap"] = do
   contents <- blocksToJATS opts bs
-  let attr = [("id", escapeNCName ident) | not (T.null ident)] ++
+  let attr = idAttr opts ident ++
              [("xml:lang",l) | ("lang",l) <- kvs] ++
              [(k,v) | (k,v) <- kvs, k `elem` ["specific-use",
                  "content-type", "orientation", "position"]]
@@ -361,7 +358,7 @@
 blockToJATS opts (Div (ident,_,kvs) bs) = do
   contents <- blocksToJATS opts bs
   -- Attributes that are allowed on both @<p>@ and @<boxed-text>@ elements
-  let generic_attr = [("id", escapeNCName ident) | not (T.null ident)] ++
+  let generic_attr = idAttr opts ident ++
                      [("xml:lang",l) | ("lang",l) <- kvs] ++
                      [(k,v) | (k,v) <- kvs, k `elem` ["specific-use",
                                                       "content-type"]]
@@ -380,10 +377,10 @@
   title' <- inlinesToJATS opts (map fixLineBreak title)
   return $ inTagsSimple "title" title'
 -- Special cases for bare images, which are rendered as graphics
-blockToJATS _opts (Plain [Image attr alt tgt]) =
-  return $ graphic attr alt tgt
-blockToJATS _opts (Para [Image attr alt tgt]) =
-  return $ graphic attr alt tgt
+blockToJATS opts (Plain [Image attr alt tgt]) =
+  return $ graphic opts attr alt tgt
+blockToJATS opts (Para [Image attr alt tgt]) =
+  return $ graphic opts attr alt tgt
 -- No Plain, everything needs to be in a block-level tag
 blockToJATS opts (Plain lst) = blockToJATS opts (Para lst)
 blockToJATS opts (Para lst) =
@@ -476,7 +473,7 @@
         else ("fig"
              , ["fig-type", "orientation", "position", "specific-use"]
              )
-  let xmlattr =  [("id", escapeNCName ident) | not (T.null ident)] ++
+  let xmlattr =  idAttr opts ident ++
                  [(k,v) | (k,v) <- kvs
                         , k `elem` allowedAttributes]
   return $ inTags True tag xmlattr $ capt $$ children
@@ -544,19 +541,20 @@
       let notenum = case notes of
                       (n, _):_ -> n + 1
                       []       -> 1
-      thenote <- inTags True "fn" [("id", "fn" <> tshow notenum)]
+      thenote <- inTags True "fn" (idAttr opts ("fn" <> tshow notenum))
                      . (inTagsSimple "label" (literal $ tshow notenum) <>)
                     <$> wrappedBlocksToJATS (not . isPara) opts
                          (walk demoteHeaderAndRefs contents)
       modify $ \st -> st{ jatsNotes = (notenum, thenote) : notes }
       return $ inTags False "xref" [("ref-type", "fn"),
-                                    ("rid", "fn" <> tshow notenum)]
+                                    ("rid", writerIdentifierPrefix opts <>
+                                             "fn" <> tshow notenum)]
              $ text (show notenum)
 inlineToJATS opts (Cite _ lst) =
   inlinesToJATS opts lst
 inlineToJATS opts (Span (ident,classes,kvs) ils) = do
   contents <- inlinesToJATS opts ils
-  let commonAttr = [("id", escapeNCName ident) | not (T.null ident)] ++
+  let commonAttr = idAttr opts ident ++
                    [("xml:lang",l) | ("lang",l) <- kvs] ++
                    [(k,v) | (k,v) <- kvs,  k `elem` ["alt", "specific-use"]]
   -- A named-content element is a good fit for spans, but requires a
@@ -615,9 +613,9 @@
   return $ inTagsSimple "email" $ literal (escapeStringForXML email)
 inlineToJATS opts (Link (ident,_,kvs) txt (T.uncons -> Just ('#', src), _)) = do
   let attr = mconcat
-             [ [("id", escapeNCName ident) | not (T.null ident)]
+             [ idAttr opts ident
              , [("alt", stringifyInlines txt) | not (null txt)]
-             , [("rid", escapeNCName src)]
+             , [("rid", writerIdentifierPrefix opts <> escapeNCName src)]
              , [(k,v) | (k,v) <- kvs, k `elem` ["ref-type", "specific-use"]]
              , [("ref-type", "bibr") | "ref-" `T.isPrefixOf` src]
              ]
@@ -627,7 +625,7 @@
         contents <- inlinesToJATS opts txt
         return $ inTags False "xref" attr contents
 inlineToJATS opts (Link (ident,_,kvs) txt (src, tit)) = do
-  let attr = [("id", escapeNCName ident) | not (T.null ident)] ++
+  let attr = idAttr opts ident ++
              [("ext-link-type", "uri"),
               ("xlink:href", src)] ++
              [("xlink:title", tit) | not (T.null tit)] ++
@@ -637,23 +635,23 @@
                                               "xlink:type"]]
   contents <- inlinesToJATS opts txt
   return $ inTags False "ext-link" attr contents
-inlineToJATS _ (Image attr alt tgt) = do
-  let elattr = graphicAttr attr alt tgt
+inlineToJATS opts (Image attr alt tgt) = do
+  let elattr = graphicAttr opts attr alt tgt
   return $ case altToJATS alt of
              Nothing -> selfClosingTag "inline-graphic" elattr
              Just altTag -> inTags True "inline-graphic" elattr altTag
 
-graphic :: Attr -> [Inline] -> Target -> (Doc Text)
-graphic attr alt tgt =
-  let elattr = graphicAttr attr alt tgt
+graphic :: WriterOptions -> Attr -> [Inline] -> Target -> (Doc Text)
+graphic opts attr alt tgt =
+  let elattr = graphicAttr opts attr alt tgt
   in case altToJATS alt of
        Nothing -> selfClosingTag "graphic" elattr
        Just altTag -> inTags True "graphic" elattr altTag
 
-graphicAttr :: Attr -> [Inline] -> Target -> [(Text, Text)]
-graphicAttr (ident, _, kvs) _alt (src, tit) =
+graphicAttr :: WriterOptions -> Attr -> [Inline] -> Target -> [(Text, Text)]
+graphicAttr opts (ident, _, kvs) _alt (src, tit) =
   let (maintype, subtype) = imageMimeType src kvs
-  in [("id", escapeNCName ident) | not (T.null ident)] ++
+  in idAttr opts ident ++
      [ ("mimetype", maintype)
      , ("mime-subtype", subtype)
      , ("xlink:href", src)
diff --git a/src/Text/Pandoc/Writers/JATS/References.hs b/src/Text/Pandoc/Writers/JATS/References.hs
--- a/src/Text/Pandoc/Writers/JATS/References.hs
+++ b/src/Text/Pandoc/Writers/JATS/References.hs
@@ -26,7 +26,7 @@
 import Text.DocLayout (Doc, empty, isEmpty, literal, vcat)
 import Text.Pandoc.Class.PandocMonad (PandocMonad)
 import Text.Pandoc.Builder (Inlines)
-import Text.Pandoc.Options (WriterOptions)
+import Text.Pandoc.Options (WriterOptions (..))
 import Text.Pandoc.Shared (tshow)
 import Text.Pandoc.Writers.JATS.Types
 import Text.Pandoc.XML (escapeNCName, escapeStringForXML, inTags)
@@ -43,11 +43,11 @@
                 => WriterOptions
                 -> Reference Inlines
                 -> JATS m (Doc Text)
-referenceToJATS _opts ref = do
+referenceToJATS opts ref = do
   let refType = referenceType ref
   let pubType = [("publication-type", refType) | not (T.null refType)]
   let ident = escapeNCName $ "ref-" <> unItemId (referenceId ref)
-  let wrap = inTags True "ref" [("id", ident)]
+  let wrap = inTags True "ref" [("id", writerIdentifierPrefix opts <> ident)]
            . inTags True "element-citation" pubType
   return . wrap . vcat $
     [ authors
diff --git a/src/Text/Pandoc/Writers/JATS/Table.hs b/src/Text/Pandoc/Writers/JATS/Table.hs
--- a/src/Text/Pandoc/Writers/JATS/Table.hs
+++ b/src/Text/Pandoc/Writers/JATS/Table.hs
@@ -21,7 +21,7 @@
 import Text.DocLayout (Doc, empty, vcat, ($$))
 import Text.Pandoc.Class.PandocMonad (PandocMonad)
 import Text.Pandoc.Definition
-import Text.Pandoc.Options (WriterOptions)
+import Text.Pandoc.Options (WriterOptions (..))
 import Text.Pandoc.Shared (tshow)
 import Text.Pandoc.Writers.JATS.Types
 import Text.Pandoc.XML (escapeNCName, inTags, inTagsIndented, selfClosingTag)
@@ -65,7 +65,7 @@
                      , "frame", "rules", "specific-use", "style", "summary"
                      , "width"
                      ]
-  let attribs = toAttribs attr validAttribs
+  let attribs = toAttribs opts attr validAttribs
   return $ inTags True "table" attribs $ vcat
     [ colSpecListToJATS colspecs
     , head'
@@ -82,7 +82,7 @@
                 -> Ann.TableBody
                 -> JATS m (Doc Text)
 tableBodyToJats opts (Ann.TableBody attr _rowHeadCols inthead rows) = do
-  let attribs = toAttribs attr validTablePartAttribs
+  let attribs = toAttribs opts attr validTablePartAttribs
   intermediateHead <- if null inthead
                       then return mempty
                       else headerRowsToJats opts Thead inthead
@@ -117,7 +117,7 @@
                  Thead -> "thead"
                  Tfoot -> "tfoot"
                  Tbody -> "tbody" -- this would be unexpected
-    let attribs = toAttribs attr validTablePartAttribs
+    let attribs = toAttribs opts attr validTablePartAttribs
     inTags True tag' attribs <$> headerRowsToJats opts tblpart rows
   where
     isEmptyRow (Ann.HeaderRow _attr _rownum cells) = all isEmptyCell cells
@@ -183,7 +183,7 @@
   let validAttribs = [ "align", "char", "charoff", "content-type"
                      , "style", "valign"
                      ]
-  let attr' = toAttribs attr validAttribs
+  let attr' = toAttribs opts attr validAttribs
   let celltype = case tblpart of
                    Thead -> HeaderCell
                    _     -> BodyCell
@@ -220,9 +220,11 @@
   let align = fst colspec
   in tableCellToJats opts celltype align cell
 
-toAttribs :: Attr -> [Text] -> [(Text, Text)]
-toAttribs (ident, _classes, kvs) knownAttribs =
-  (if T.null ident then id else (("id", escapeNCName ident) :)) $
+toAttribs :: WriterOptions -> Attr -> [Text] -> [(Text, Text)]
+toAttribs opts (ident, _classes, kvs) knownAttribs =
+  (if T.null ident
+      then id
+      else (("id", writerIdentifierPrefix opts <> escapeNCName ident) :)) $
   filter ((`elem` knownAttribs) . fst) kvs
 
 tableCellToJats :: PandocMonad m
@@ -255,7 +257,7 @@
   let attribs = maybeCons (alignmentAttrib align')
               . maybeCons (rowspanAttrib rowspan)
               . maybeCons (colspanAttrib colspan)
-              $ toAttribs attr validAttribs
+              $ toAttribs opts attr validAttribs
   inTags False tag' attribs <$> cellContents item
 
 -- | Whether the JATS produced from this block should be wrapped in a
diff --git a/src/Text/Pandoc/Writers/LaTeX.hs b/src/Text/Pandoc/Writers/LaTeX.hs
--- a/src/Text/Pandoc/Writers/LaTeX.hs
+++ b/src/Text/Pandoc/Writers/LaTeX.hs
@@ -40,7 +40,7 @@
 import Data.Text (Text)
 import qualified Data.Text as T
 import Network.URI (unEscapeString)
-import Text.DocTemplates (Context(..), FromContext(lookupContext), Val(..), renderTemplate)
+import Text.DocTemplates (Context(..), FromContext(lookupContext), Val(..))
 import qualified Data.Map as M
 import Text.Collate.Lang (renderLang)
 import Text.Pandoc.Class.PandocMonad (PandocMonad, getPOSIXTime, lookupEnv,
@@ -128,9 +128,6 @@
   let blocks' = if method == Biblatex || method == Natbib
                    then filter (not . isRefsDiv) blocks
                    else blocks
-  let colwidth = if writerWrapText options == WrapAuto
-                    then Just $ writerColumns options
-                    else Nothing
   docLangs <- catMaybes <$>
       mapM (toLang . Just) (nubOrd (query (extract "lang") blocks))
   mblang <- toLang $ case getLang options meta of
@@ -246,6 +243,7 @@
                   defField "documentclass" documentClass $
                   defField "verbatim-in-note" (stVerbInNote st) $
                   defField "tables" (stTable st) $
+                  defField "deferred-notes" (stDeferredNoteNum st > 0) $
                   defField "multirow" (stMultiRow st) $
                   defField "cancel" (stCancel st) $
                   defField "strikeout" (stStrikeout st) $
@@ -326,10 +324,7 @@
         $ defField "latex-dir-rtl"
            ((render Nothing <$> getField "dir" context) ==
                Just ("rtl" :: Text)) context
-  return $ render colwidth $
-    case writerTemplate options of
-       Nothing  -> main
-       Just tpl -> renderTemplate tpl context'
+  return $ renderWithTemplate options context' main
 
 -- Commas in title-meta need to be put in braces; see #10501
 escapeCommas :: Text -> Text
@@ -771,12 +766,12 @@
     modify $ \s -> s{ stInItem = True }
     term' <- withExternalNotes $ inlineListToLaTeX term
     modify $ \s -> s{ stInItem = False }
-    -- put braces around term if it contains an internal link,
-    -- since otherwise we get bad bracket interactions: \item[\hyperref[..]
-    let isInternalLink (Link _ _ (src,_))
+    -- put braces around term if it contains an internal link or an =:
+    let needsBraces (Link _ _ (src,_))
           | Just ('#', _) <- T.uncons src = True
-        isInternalLink _                  = False
-    let term'' = if any isInternalLink term
+        needsBraces (Str t) = T.any (=='=') t
+        needsBraces _ = False
+    let term'' = if any needsBraces term
                     then braces term'
                     else term'
     def'  <- case concat defs of
@@ -1226,6 +1221,7 @@
 inlineToLaTeX (Note contents) = do
   setEmptyLine False
   modify (\s -> s{stInNote = True })
+  numNotesBefore <- gets (length . stNotes)
   contents' <- withExternalNotes $ blockListToLaTeX contents
   modify (\s -> s {stInNote = False })
   let optnl = case reverse contents of
@@ -1244,8 +1240,14 @@
   externalNotes <- gets stExternalNotes
   if externalNotes
      then do
-       modify $ \st -> st{ stNotes = noteContents : stNotes st }
-       return "\\footnotemark{}"
+       -- the marks of notes nested in this one are only set when
+       -- this note's text is typeset, so their texts must come after it
+       notes <- gets stNotes
+       let (nested, rest) = splitAt (length notes - numNotesBefore) notes
+       num <- gets ((+ 1) . stDeferredNoteNum)
+       modify $ \st -> st{ stNotes = nested ++ (num, noteContents) : rest
+                         , stDeferredNoteNum = num }
+       return $ "\\pandocfootnotemark" <> braces (text (show num))
        -- note: a \n before } needed when note ends with a Verbatim environment
        else return $ "\\footnote" <> beamerMark <> braces noteContents
 
diff --git a/src/Text/Pandoc/Writers/LaTeX/Notes.hs b/src/Text/Pandoc/Writers/LaTeX/Notes.hs
--- a/src/Text/Pandoc/Writers/LaTeX/Notes.hs
+++ b/src/Text/Pandoc/Writers/LaTeX/Notes.hs
@@ -1,4 +1,3 @@
-{-# LANGUAGE LambdaCase        #-}
 {-# LANGUAGE OverloadedStrings #-}
 {- |
    Module      : Text.Pandoc.Writers.LaTeX.Notes
@@ -9,26 +8,21 @@
    Stability   : alpha
    Portability : portable
 
-Output tables as LaTeX.
+Output deferred footnote texts as LaTeX.
 -}
 module Text.Pandoc.Writers.LaTeX.Notes
   ( notesToLaTeX
   ) where
 
-import Data.List (intersperse)
-import Text.DocLayout ( Doc, braces, empty, text, vcat, ($$))
+import Text.DocLayout ( Doc, braces, text, vcat )
 import Data.Text (Text)
 
-notesToLaTeX :: [Doc Text] -> Doc Text
-notesToLaTeX = \case
-  [] -> empty
-  ns -> (case length ns of
-            n | n > 1 -> "\\addtocounter" <>
-                         braces "footnote" <>
-                         braces (text $ show $ 1 - n)
-              | otherwise -> empty)
-        $$
-        vcat (intersperse
-               ("\\addtocounter" <> braces "footnote" <> braces "1")
-               $ map (\x -> "\\footnotetext" <> braces x)
-               $ reverse ns)
+-- | Render the texts of notes whose marks were produced with
+-- @\\pandocfootnotemark{n}@. @\\pandocfootnotetext{n}@ restores
+-- the footnote mark and hyperref anchor saved by the corresponding
+-- mark (see the template). Notes are stored in reverse order.
+notesToLaTeX :: [(Int, Doc Text)] -> Doc Text
+notesToLaTeX = vcat . map toNoteText . reverse
+  where
+    toNoteText (num, x) =
+      "\\pandocfootnotetext" <> braces (text (show num)) <> braces x
diff --git a/src/Text/Pandoc/Writers/LaTeX/Table.hs b/src/Text/Pandoc/Writers/LaTeX/Table.hs
--- a/src/Text/Pandoc/Writers/LaTeX/Table.hs
+++ b/src/Text/Pandoc/Writers/LaTeX/Table.hs
@@ -28,7 +28,7 @@
 import Text.DocLayout
   ( Doc, braces, brackets, cr, empty, hcat, hsep, isEmpty, literal, nest
   , text, vcat, ($$))
-import Text.Pandoc.Shared (splitBy, tshow)
+import Text.Pandoc.Shared (deNote, splitBy, tshow)
 import Text.Pandoc.Walk (walk, query)
 import Data.Monoid (Any(..))
 import Text.Pandoc.Writers.LaTeX.Caption (getCaption)
@@ -54,12 +54,14 @@
   -- if the float class is included in table attributes, we generate a floating
   -- table environment; otherwise we use longtable
   let float = "float" `elem` classes
+  let repeatCaption = not float && "repeat-caption" `elem` classes
   let renderTable = do
        let unnumbered = "unnumbered" `elem` classes
-       capt <- case caption of
-                 Caption Nothing []
-                   | unnumbered || T.null ident -> pure mempty
-                 _ -> captionToLaTeX inlnsToLaTeX caption ident
+       (capt, repeatedCapt) <-
+         case caption of
+           Caption Nothing []
+             | unnumbered || T.null ident -> pure (mempty, mempty)
+           _ -> captionToLaTeX inlnsToLaTeX repeatCaption caption ident
        let isSimpleTable =
              all ((== ColWidthDefault) . snd) specs &&
              all (all isSimpleCell)
@@ -76,12 +78,14 @@
        let makeUnnumbered x =
              "{\\def\\LTcaptype{none} % do not increment counter" $$ x $$ "}"
        let makeTable = if float
-                          then tableToLaTeXTable placement
-                          else tableToLaTeXLongtable
+                          then tableToLaTeXTable placement colDesc
+                                 mkHead mkRow capt
+                          else tableToLaTeXLongtable colDesc mkHead mkRow capt
+                                 repeatedCapt
        (if unnumbered || isEmpty capt
           then makeUnnumbered
           else id) <$>
-          makeTable colDesc mkHead mkRow capt thead tbodies tfoot
+          makeTable thead tbodies tfoot
   ($$) <$> withExternalNotes renderTable <*> getAccumulatedNotes
 
 tableToLaTeXTable :: PandocMonad m
@@ -132,28 +136,33 @@
                       -> (Ann.TableHead -> LW m (Doc Text))
                       -> ([Ann.Cell] -> LW m (Doc Text))
                       -> Doc Text
+                      -> Doc Text
                       -> Ann.TableHead
                       -> [Ann.TableBody]
                       -> Ann.TableFoot
                       -> LW m (Doc Text)
-tableToLaTeXLongtable colDesc mkHead mkRow capt thead tbodies tfoot = do
+tableToLaTeXLongtable colDesc mkHead mkRow capt repeatedCapt
+                      thead tbodies tfoot = do
   opts <- gets stOptions
   let hasTopCaption = not (isEmpty capt) &&
                         writerTableCaptionPosition opts == CaptionAbove
   let hasBottomCaption = not (isEmpty capt) &&
                           writerTableCaptionPosition opts == CaptionBelow
-  -- The first head is not repeated on the following pages. If we were to just
-  -- use a single head, without a separate first head, then the caption would be
-  -- repeated on all pages that contain a part of the table. We avoid this by
-  -- making the caption part of the first head. The downside is that we must
-  -- duplicate the header rows for this.
+  -- The first head is not repeated on the following pages. Keep the numbered
+  -- caption in that head. Add the unnumbered repeated caption to the regular
+  -- head only when requested. The downside is that we must duplicate the
+  -- header rows.
   head' <- do
     case (hasTopCaption, isEmptyHead thead) of
       (False, True) -> return "\\toprule\\noalign{}"
       (False, False)  -> mkHead thead
       (True, True)  -> return (capt <> "\\tabularnewline"
                                 $$ "\\toprule\\noalign{}"
-                                $$ "\\endfirsthead")
+                                $$ "\\endfirsthead"
+                                $$ (if isEmpty repeatedCapt
+                                       then mempty
+                                       else repeatedCapt <> "\\tabularnewline"
+                                            $$ "\\toprule\\noalign{}"))
       (True, False)   -> do
         -- avoid duplicate notes in head and firsthead:
         firsthead <- mkHead thead
@@ -163,6 +172,9 @@
         return $ capt <> "\\tabularnewline"
                  $$ firsthead
                  $$ "\\endfirsthead"
+                 $$ (if isEmpty repeatedCapt
+                        then mempty
+                        else repeatedCapt <> "\\tabularnewline")
                  $$ repeated
   rows' <- mapM mkRow $ mconcat (map bodyRows tbodies)
   lastfoot <- mapM mkRow $ footRows tfoot
@@ -173,6 +185,9 @@
               $$ (if hasBottomCaption
                      then "\\tabularnewline" $$ capt
                      else mempty)
+  let repeatedFoot = "\\bottomrule\\noalign{}"
+                     $$ "\\tabularnewline"
+                     $$ repeatedCapt
   modify $ \s -> s{ stTable = True }
   beamer <- gets stBeamer
   return $
@@ -188,9 +203,12 @@
              then [ vcat rows'
                   , foot'
                   ]
-             else [ foot'
+             else (if hasBottomCaption && not (isEmpty repeatedCapt)
+                      then [ repeatedFoot, "\\endfoot" ]
+                      else []) <>
+                  [ foot'
                   , "\\endlastfoot"
-                  ,  vcat rows'
+                  , vcat rows'
                   ])
     $$ "\\end{longtable}"
 
@@ -257,16 +275,25 @@
 
 captionToLaTeX :: PandocMonad m
                => ([Inline] -> LW m (Doc Text))
+               -> Bool     -- ^ repeat caption on subsequent pages
                -> Caption
                -> Text     -- ^ table identifier (label)
-               -> LW m (Doc Text)
-captionToLaTeX inlnsToLaTeX caption ident = do
+               -> LW m (Doc Text, Doc Text)
+captionToLaTeX inlnsToLaTeX repeatCaption caption ident = do
   (captionText, captForLot) <- getCaption inlnsToLaTeX caption
+  repeatedCaptionText <-
+    if repeatCaption
+       then fst <$> getCaption inlnsToLaTeX (walk deNote caption)
+       else pure empty
   label <- labelFor ident
-  return $ if isEmpty captionText && isEmpty label
-              then empty
-              else "\\caption" <> captForLot <>
-                     braces captionText <> label
+  let capt = if isEmpty captionText && isEmpty label
+                then empty
+                else "\\caption" <> captForLot <>
+                       braces captionText <> label
+  let repeatedCapt = if isEmpty repeatedCaptionText
+                        then empty
+                        else "\\caption[]" <> braces repeatedCaptionText
+  return (capt, repeatedCapt)
 
 type BlocksWriter m = [Block] -> LW m (Doc Text)
 
diff --git a/src/Text/Pandoc/Writers/LaTeX/Types.hs b/src/Text/Pandoc/Writers/LaTeX/Types.hs
--- a/src/Text/Pandoc/Writers/LaTeX/Types.hs
+++ b/src/Text/Pandoc/Writers/LaTeX/Types.hs
@@ -29,7 +29,8 @@
   , stInItem        :: Bool          -- ^ true if in \item[..]
   , stInFigure      :: Bool          -- ^ true if in figure environment
   , stInCite        :: Bool          -- ^ true if in a Cite
-  , stNotes         :: [Doc Text]    -- ^ notes in a minipage
+  , stNotes         :: [(Int, Doc Text)] -- ^ deferred notes (id, text)
+  , stDeferredNoteNum :: Int         -- ^ number of deferred notes so far
   , stOLLevel       :: Int           -- ^ level of ordered list nesting
   , stOptions       :: WriterOptions -- ^ writer options, so they don't have to
                                      --   be parameter
@@ -76,6 +77,7 @@
   , stInFigure = False
   , stInCite = False
   , stNotes = []
+  , stDeferredNoteNum = 0
   , stOLLevel = 1
   , stOptions = options
   , stVerbInNote = False
diff --git a/src/Text/Pandoc/Writers/Man.hs b/src/Text/Pandoc/Writers/Man.hs
--- a/src/Text/Pandoc/Writers/Man.hs
+++ b/src/Text/Pandoc/Writers/Man.hs
@@ -31,7 +31,6 @@
 import Text.DocLayout
 import Text.Pandoc.Shared
 import Text.Pandoc.URI
-import Text.Pandoc.Templates (renderTemplate)
 import Text.Pandoc.Writers.Math
 import Text.Pandoc.Writers.Shared
 import Text.Pandoc.Writers.Roff
@@ -48,9 +47,6 @@
 -- | Return roff man representation of document.
 pandocToMan :: PandocMonad m => WriterOptions -> Pandoc -> StateT WriterState m Text
 pandocToMan opts (Pandoc meta blocks) = do
-  let colwidth = if writerWrapText opts == WrapAuto
-                    then Just $ writerColumns opts
-                    else Nothing
   titleText <- inlineListToMan opts $ docTitle meta
   let title' = render Nothing titleText
   let setFieldsFromTitle =
@@ -80,10 +76,7 @@
               $ setFieldsFromTitle
               $ defField "has-tables" hasTables
                 metadata
-  return $ render colwidth $
-    case writerTemplate opts of
-       Nothing  -> main
-       Just tpl -> renderTemplate tpl context
+  return $ renderWithTemplate opts context main
 
 escString :: WriterOptions -> Text -> Text
 escString opts = escapeString True (if writerPreferAscii opts
diff --git a/src/Text/Pandoc/Writers/Markdown.hs b/src/Text/Pandoc/Writers/Markdown.hs
--- a/src/Text/Pandoc/Writers/Markdown.hs
+++ b/src/Text/Pandoc/Writers/Markdown.hs
@@ -43,7 +43,6 @@
 import Text.DocLayout
 import Text.Pandoc.Shared
 import Text.Pandoc.Writers.Shared
-import Text.Pandoc.Templates (renderTemplate)
 import Text.DocTemplates (Val(..), Context(..), FromContext(..))
 import Text.Pandoc.Walk
 import Text.Pandoc.Writers.HTML (writeHtml5String)
@@ -222,9 +221,6 @@
 -- | Return markdown representation of document.
 pandocToMarkdown :: PandocMonad m => WriterOptions -> Pandoc -> MD m Text
 pandocToMarkdown opts (Pandoc meta blocks) = do
-  let colwidth = if writerWrapText opts == WrapAuto
-                    then Just $ writerColumns opts
-                    else Nothing
   variant <- asks envVariant
   metadata <- metaToContext'
                (blockListToMarkdown opts)
@@ -272,10 +268,7 @@
                      then id
                      else defField "titleblock" titleblock)
                $ addVariablesToContext opts metadata
-  return $ render colwidth $
-    case writerTemplate opts of
-       Nothing  -> main
-       Just tpl -> renderTemplate tpl context
+  return $ renderWithTemplate opts context main
 
 -- | Return markdown representation of reference key table.
 refsToMarkdown :: PandocMonad m => WriterOptions -> Refs -> MD m (Doc Text)
@@ -295,13 +288,22 @@
             (literal (linkDestination src) <> tit')
             <+> linkAttributes opts attr
 
--- | Return markdown representation of notes.
-notesToMarkdown :: PandocMonad m => WriterOptions -> [[Block]] -> MD m (Doc Text)
-notesToMarkdown opts notes = do
-  n <- gets stNoteNum
-  notes' <- zipWithM (noteToMarkdown opts) [n..] notes
-  modify $ \st -> st { stNoteNum = stNoteNum st + length notes }
-  return $ vsep notes'
+-- | Return markdown representation of the collected notes, clearing
+-- them from the state. Rendering a note may add further notes to the
+-- state (notes nested inside notes); keep going until all of them
+-- have been rendered.
+notesToMarkdown :: PandocMonad m => WriterOptions -> MD m (Doc Text)
+notesToMarkdown opts = vsep <$> go
+  where
+    go = do
+      notes <- gets (reverse . stNotes)
+      if null notes
+        then return []
+        else do
+          n <- gets stNoteNum
+          modify $ \st -> st { stNotes = [], stNoteNum = n + length notes }
+          docs <- zipWithM (noteToMarkdown opts) [n..] notes
+          (docs ++) <$> go
 
 -- | Return markdown representation of a note.
 noteToMarkdown :: PandocMonad m => WriterOptions -> Int -> [Block] -> MD m (Doc Text)
@@ -347,8 +349,7 @@
 
 notesAndRefs :: PandocMonad m => WriterOptions -> MD m (Doc Text)
 notesAndRefs opts = do
-  notes' <- gets stNotes >>= notesToMarkdown opts . reverse
-  modify $ \s -> s { stNotes = [] }
+  notes' <- notesToMarkdown opts
   refs' <- gets stRefs >>= refsToMarkdown opts . reverse
   modify $ \s -> s { stPrevRefs = stPrevRefs s ++ stRefs s
                    , stRefs = []}
@@ -621,7 +622,10 @@
                    let (_,cls,_) = attribs
                     in case getLangFromClasses opts cls of
                               Just l -> " " <> literal l
-                              Nothing -> empty
+                              Nothing -> -- see #11987
+                                case cls of
+                                  l:_ -> literal l
+                                  [] -> empty
 blockToMarkdown' opts (BlockQuote blocks) = do
   variant <- asks envVariant
   -- if we're writing literate haskell, put a space before the bird tracks
@@ -689,9 +693,7 @@
          isEnabled Ext_multiline_tables opts -> do
            tbl <- mkTable (pandocTable opts True)
            return $ nest 2 (tbl $$ caption''') $$ blankline
-       | isEnabled Ext_grid_tables opts &&
-          (hasColRowSpans || writerColumns opts >= 8 * numcols
-                          || hasFooter) -> do
+       | isEnabled Ext_grid_tables opts -> do
            tbl <- gridTable opts blockListToMarkdown
                      specs thead tbody tfoot
            return $ (tbl $$ caption''') $$ blankline
diff --git a/src/Text/Pandoc/Writers/Ms.hs b/src/Text/Pandoc/Writers/Ms.hs
--- a/src/Text/Pandoc/Writers/Ms.hs
+++ b/src/Text/Pandoc/Writers/Ms.hs
@@ -44,7 +44,6 @@
 import Text.DocLayout hiding (Color)
 import Text.DocTemplates (lookupContext)
 import Text.Pandoc.Shared
-import Text.Pandoc.Templates (renderTemplate)
 import Text.Pandoc.Writers.Math
 import Text.Pandoc.Writers.Shared
 import Text.Pandoc.Writers.Roff
@@ -62,9 +61,6 @@
 -- | Return roff ms representation of document.
 pandocToMs :: PandocMonad m => WriterOptions -> Pandoc -> MS m Text
 pandocToMs opts (Pandoc meta blocks) = do
-  let colwidth = if writerWrapText opts == WrapAuto
-                    then Just $ writerColumns opts
-                    else Nothing
   title <- chomp <$> inlineListToMs' opts (lookupMetaInlines "title" meta)
   metadata <- metaToContext opts
               (blockListToMs opts)
@@ -91,10 +87,7 @@
               $ defField "author-meta" (T.intercalate "; " authorsMeta)
               $ defField "highlighting-macros" highlightingMacros
               $ resetField "title" title metadata
-  return $ render colwidth $
-    case writerTemplate opts of
-       Nothing  -> main
-       Just tpl -> renderTemplate tpl context
+  return $ renderWithTemplate opts context main
 
 escapeStr :: WriterOptions -> Text -> Text
 escapeStr opts =
diff --git a/src/Text/Pandoc/Writers/Muse.hs b/src/Text/Pandoc/Writers/Muse.hs
--- a/src/Text/Pandoc/Writers/Muse.hs
+++ b/src/Text/Pandoc/Writers/Muse.hs
@@ -47,7 +47,6 @@
 import Text.DocLayout
 import Text.Pandoc.Shared
 import Text.Pandoc.URI
-import Text.Pandoc.Templates (renderTemplate)
 import Text.Pandoc.Writers.Math
 import Text.Pandoc.Writers.Shared
 
@@ -108,9 +107,6 @@
              -> Muse m Text
 pandocToMuse (Pandoc meta blocks) = do
   opts <- asks envOptions
-  let colwidth = if writerWrapText opts == WrapAuto
-                    then Just $ writerColumns opts
-                    else Nothing
   metadata <- metaToContext opts
                blockListToMuse
                (fmap chomp . inlineListToMuse)
@@ -119,10 +115,7 @@
   notes <- currentNotesToMuse
   let main = body $+$ notes
   let context = defField "body" main metadata
-  return $ render colwidth $
-    case writerTemplate opts of
-       Nothing  -> main
-       Just tpl -> renderTemplate tpl context
+  return $ renderWithTemplate opts context main
 
 -- | Helper function for flatBlockListToMuse
 -- | Render all blocks and insert blank lines between the first two
diff --git a/src/Text/Pandoc/Writers/ODT.hs b/src/Text/Pandoc/Writers/ODT.hs
--- a/src/Text/Pandoc/Writers/ODT.hs
+++ b/src/Text/Pandoc/Writers/ODT.hs
@@ -305,10 +305,21 @@
   lang <- toLang (getLang opts meta)
   refArchive <-
        case writerReferenceDoc opts of
-             Just f -> lift $ toArchive . B.fromStrict . fst <$>
+             Just f -> do
+               arch <- lift $ toArchiveOrFail . B.fromStrict . fst <$>
                                 (P.fetchItem (T.pack f))
-             Nothing -> lift $ toArchive . B.fromStrict <$>
+               case arch of
+                 Left err -> throwError $ PandocParseError $
+                   "Could not parse reference-doc " <>
+                     tshow f <> ": " <> T.pack err
+                 Right x -> pure x
+             Nothing -> do
+               arch <- lift $ toArchiveOrFail . B.fromStrict <$>
                                 readDataFile "reference.odt"
+               case arch of
+                 Left err -> throwError $ PandocParseError $
+                   "Could not parse reference.odt: " <> T.pack err
+                 Right x -> pure x
   -- handle formulas and pictures
   -- picEntriesRef <- P.newIORef ([] :: [Entry])
   let refTextWidth = referenceTextWidthPt opts refArchive
diff --git a/src/Text/Pandoc/Writers/OPML.hs b/src/Text/Pandoc/Writers/OPML.hs
--- a/src/Text/Pandoc/Writers/OPML.hs
+++ b/src/Text/Pandoc/Writers/OPML.hs
@@ -1,5 +1,4 @@
 {-# LANGUAGE OverloadedStrings #-}
-{-# LANGUAGE CPP               #-}
 {- |
    Module      : Text.Pandoc.Writers.OPML
    Copyright   : Copyright (C) 2013-2024 John MacFarlane
@@ -30,9 +29,7 @@
 -- | Convert Pandoc document to string in OPML format.
 writeOPML :: PandocMonad m => WriterOptions -> Pandoc -> m Text
 writeOPML opts (Pandoc meta blocks) = do
-  let colwidth = if writerWrapText opts == WrapAuto
-                    then Just $ writerColumns opts
-                    else Nothing
+  let colwidth = wrapColumns opts
       meta' = B.setMeta "date" (B.str $ convertDate $ docDate meta) meta
   metadata <- metaToContext opts
               (fmap literal . writeMarkdown' opts . Pandoc nullMeta)
diff --git a/src/Text/Pandoc/Writers/OpenDocument.hs b/src/Text/Pandoc/Writers/OpenDocument.hs
--- a/src/Text/Pandoc/Writers/OpenDocument.hs
+++ b/src/Text/Pandoc/Writers/OpenDocument.hs
@@ -16,7 +16,8 @@
 module Text.Pandoc.Writers.OpenDocument ( writeOpenDocument ) where
 import Control.Monad (unless, liftM, when)
 import Control.Monad.State.Strict ( StateT(..), modify, gets, lift )
-import Data.Char (chr, isDigit)
+import Data.Char (chr, isDigit, isLetter, isMark, ord)
+import Numeric (showHex)
 import Data.List (sortOn, sortBy)
 import qualified Data.List as L
 import qualified Data.Map as Map
@@ -32,8 +33,7 @@
 import Text.Pandoc.Logging
 import Text.Pandoc.Options
 import Text.DocLayout hiding (link)
-import Text.Pandoc.Shared (linesToPara, tshow, blocksToInlines)
-import Text.Pandoc.Templates (renderTemplate)
+import Text.Pandoc.Shared (linesToPara, plainToPara, tshow, blocksToInlines)
 import qualified Text.Pandoc.Translations as Term (Term(Figure, Table))
 import Text.Pandoc.Walk
 import Text.Pandoc.Writers.Math
@@ -44,11 +44,6 @@
 import Text.Pandoc.Highlighting (highlight)
 import Skylighting (FormatOptions(..), SourceLine, Token)
 
--- | Auxiliary function to convert Plain block to Para.
-plainToPara :: Block -> Block
-plainToPara (Plain x) = Para x
-plainToPara x         = x
-
 -- Names of predefined styles in the reference.odt; see data/odt/styles.xml.
 defaultBulletListStyleName, defaultNumberedListStyleName :: Text
 defaultBulletListStyleName   = "List_20_1"
@@ -302,9 +297,6 @@
 writeOpenDocument :: PandocMonad m => WriterOptions -> Pandoc -> m Text
 writeOpenDocument opts (Pandoc meta blocks) = do
   setupTranslations meta
-  let colwidth = if writerWrapText opts == WrapAuto
-                    then Just $ writerColumns opts
-                    else Nothing
   -- The abstract is the one template field that takes block-level
   -- content, so it is rendered separately; everything else in the
   -- metadata goes in a context where only inlines are allowed.
@@ -358,10 +350,7 @@
                     then id
                     else defField "abstract" abstract)
               $ metadata
-  return $ render colwidth $
-    case writerTemplate opts of
-       Nothing  -> body
-       Just tpl -> renderTemplate tpl context
+  return $ renderWithTemplate opts context body
 
 withParagraphStyle :: PandocMonad m
                    => WriterOptions -> Text -> [Block] -> OD m (Doc Text)
@@ -562,7 +551,7 @@
         let (ident,_,kvs) = attr
             i = withDirFromAttr attr $ withLangFromAttr attr $
                 case lookup "custom-style" kvs of
-                  Just sty -> withParagraphStyle o sty s
+                  Just sty -> withParagraphStyle o (encodeStyleName sty) s
                   _        -> blocksToOpenDocument o s
             mkBookmarkedDiv = inTags False "text:section" [("text:name", ident)]
         if T.null ident
@@ -844,7 +833,7 @@
         let (ident,_,kvs) = attr
             i = maybe id (\sty ->
                            fmap (inTags False "text:span"
-                                  [ ("text:style-name", sty) ]))
+                                  [ ("text:style-name", encodeStyleName sty) ]))
                   (lookup "custom-style" kvs) .
                  withLangFromAttr attr $ inlinesToOpenDocument o xs
             mkBookmarkedSpan b =
@@ -1024,6 +1013,21 @@
                         ("fo:text-align", "right")]
       Just LTR -> [("style:writing-mode", "lr-tb"),
                         ("fo:text-align", "left")]
+
+-- | Encode a style name as LibreOffice does: characters not allowed
+-- in an XML name are replaced by their code point in hex between
+-- underscores, so that, e.g., @Text body@ becomes @Text_20_body@.
+encodeStyleName :: Text -> Text
+encodeStyleName t = case T.uncons t of
+  Nothing      -> t
+  Just (c, cs) -> enc isStartChar c <> T.concatMap (enc isNameChar) cs
+  where
+    enc ok c
+      | ok c      = T.singleton c
+      | otherwise = "_" <> T.pack (showHex (ord c) "") <> "_"
+    isStartChar c = isLetter c || c == '_'
+    isNameChar c  = isStartChar c || isDigit c || isMark c
+                    || c == '-' || c == '.'
 
 -- | Adjust a named paragraph style for the current writing direction.
 -- When a direction is active, an automatic style derived from the
diff --git a/src/Text/Pandoc/Writers/Org.hs b/src/Text/Pandoc/Writers/Org.hs
--- a/src/Text/Pandoc/Writers/Org.hs
+++ b/src/Text/Pandoc/Writers/Org.hs
@@ -33,7 +33,6 @@
 import Text.Pandoc.Options
 import Text.Pandoc.Shared
 import Text.Pandoc.URI
-import Text.Pandoc.Templates (renderTemplate)
 import Text.Pandoc.Citeproc.Locator (parseLocator, LocatorMap(..), LocatorInfo(..))
 import Text.Pandoc.Walk (query)
 import Text.Pandoc.Writers.Shared
@@ -60,9 +59,6 @@
 pandocToOrg :: PandocMonad m => Pandoc -> Org m Text
 pandocToOrg (Pandoc meta blocks) = do
   opts <- gets stOptions
-  let colwidth = if writerWrapText opts == WrapAuto
-                    then Just $ writerColumns opts
-                    else Nothing
   metadata <- metaToContext opts
                blockListToOrg
                (fmap chomp . inlineListToOrg)
@@ -85,10 +81,7 @@
               . defField "option-special-strings"
                          (isEnabled Ext_special_strings opts)
               $ metadata
-  return $ render colwidth $
-    case writerTemplate opts of
-       Nothing  -> main
-       Just tpl -> renderTemplate tpl context
+  return $ renderWithTemplate opts context main
 
 -- | Return Org representation of the collected notes. Rendering a
 -- note may add further notes to the state (notes nested inside
diff --git a/src/Text/Pandoc/Writers/Powerpoint/Output.hs b/src/Text/Pandoc/Writers/Powerpoint/Output.hs
--- a/src/Text/Pandoc/Writers/Powerpoint/Output.hs
+++ b/src/Text/Pandoc/Writers/Powerpoint/Output.hs
@@ -596,10 +596,21 @@
   distArchive <- toArchive . BL.fromStrict <$>
                         readDefaultDataFile "reference.pptx"
   refArchive <- case writerReferenceDoc opts of
-                     Just f  -> toArchive . BL.fromStrict . fst
-                                  <$> P.fetchItem (T.pack f)
-                     Nothing -> toArchive . BL.fromStrict <$>
-                        readDataFile "reference.pptx"
+                   Just f  -> do
+                     arch <- toArchiveOrFail . BL.fromStrict . fst
+                                 <$> P.fetchItem (T.pack f)
+                     case arch of
+                       Left err -> throwError $ PandocParseError $
+                         "Could not parse reference-doc " <>
+                           tshow f <> ": " <> T.pack err
+                       Right x -> pure x
+                   Nothing -> do
+                     arch <- toArchiveOrFail . BL.fromStrict <$>
+                                 readDataFile "reference.pptx"
+                     case arch of
+                       Left err -> throwError $ PandocParseError $
+                         "Could not parse reference.pptx: " <> T.pack err
+                       Right x -> pure x
 
   let (referenceLayouts, defaultReferenceLayouts) =
         (getLayoutsFromArchive refArchive, getLayoutsFromArchive distArchive)
@@ -2295,6 +2306,8 @@
           , sldNumShape
           ]
         ]
+      -- required by Keynote, see #11935
+      , mknode "p:clrMapOvr" [] $ mknode "a:masterClrMapping" [] ()
       ]
 
 -----------------------------------------------------------------------
@@ -2768,6 +2781,7 @@
     : ( [mknode "dc:subject" [] $ fromMaybe "" $ dcSubject docProps | isJust (dcSubject docProps)])
     <> ( [mknode "dc:description" [] $ fromMaybe "" $ dcDescription docProps | isJust (dcDescription docProps)])
     <> ( [mknode "cp:category" [] $ fromMaybe "" $ cpCategory docProps | isJust (cpCategory docProps)])
+    <> ( [mknode "dc:language" [] $ fromMaybe "" $ dcLanguage docProps | isJust (dcLanguage docProps)])
     <> (\x -> [ mknode "dcterms:created" [("xsi:type","dcterms:W3CDTF")] x
               , mknode "dcterms:modified" [("xsi:type","dcterms:W3CDTF")] x
               ]) (T.pack $ formatTime defaultTimeLocale "%FT%XZ" utctime)
diff --git a/src/Text/Pandoc/Writers/Powerpoint/Presentation.hs b/src/Text/Pandoc/Writers/Powerpoint/Presentation.hs
--- a/src/Text/Pandoc/Writers/Powerpoint/Presentation.hs
+++ b/src/Text/Pandoc/Writers/Powerpoint/Presentation.hs
@@ -188,6 +188,7 @@
                          , dcKeywords :: Maybe [T.Text]
                          , dcDescription :: Maybe T.Text
                          , cpCategory :: Maybe T.Text
+                         , dcLanguage :: Maybe T.Text
                          , dcDate :: Maybe T.Text
                          , customProperties :: Maybe [(T.Text, T.Text)]
                          } deriving (Show, Eq)
@@ -1189,6 +1190,7 @@
             , dcKeywords = keywords
             , dcDescription = description
             , cpCategory = Shared.stringify <$> lookupMeta "category" meta
+            , dcLanguage = Shared.stringify <$> lookupMeta "lang" meta
             , dcDate =
               let t = Shared.stringifyInlines (docDate meta)
               in if T.null t
diff --git a/src/Text/Pandoc/Writers/RST.hs b/src/Text/Pandoc/Writers/RST.hs
--- a/src/Text/Pandoc/Writers/RST.hs
+++ b/src/Text/Pandoc/Writers/RST.hs
@@ -35,7 +35,6 @@
 import Text.DocLayout
 import Text.Pandoc.Shared
 import Text.Pandoc.URI
-import Text.Pandoc.Templates (renderTemplate)
 import Text.Pandoc.Writers.Shared
 import Text.Pandoc.Walk
 import Safe (lastMay, headMay)
@@ -68,9 +67,6 @@
 pandocToRST :: PandocMonad m => Pandoc -> RST m Text
 pandocToRST (Pandoc meta blocks) = do
   opts <- gets stOptions
-  let colwidth = if writerWrapText opts == WrapAuto
-                    then Just $ writerColumns opts
-                    else Nothing
   let subtit = lookupMetaInlines "subtitle" meta
   title <- titleToRST (docTitle meta) subtit
   metadata <- metaToContext opts
@@ -80,7 +76,7 @@
   body <- blockListToRST' True $ case writerTemplate opts of
                                       Just _  -> normalizeHeadings 1 blocks
                                       Nothing -> blocks
-  notes <- gets (reverse . stNotes) >>= notesToRST
+  notes <- notesToRST
   -- note that the notes may contain refs, so we do them first
   refs <- gets (reverse . stLinks) >>= refsToRST
   pics <- gets (reverse . stImages) >>= pictRefsToRST
@@ -95,10 +91,7 @@
               $ defField "titleblock" (render Nothing title :: Text)
               $ defField "math" hasMath
               $ defField "rawtex" rawTeX metadata
-  return $ render colwidth $
-    case writerTemplate opts of
-       Nothing  -> main
-       Just tpl -> renderTemplate tpl context
+  return $ renderWithTemplate opts context main
   where
     normalizeHeadings lev (Header l a i:bs) =
       Header lev a i:normalizeHeadings (lev+1) cont ++ normalizeHeadings lev bs'
@@ -126,10 +119,19 @@
                    else label'
   return $ nowrap $ ".. _" <> label'' <> ": " <> literal src
 
--- | Return RST representation of notes.
-notesToRST :: PandocMonad m => [[Block]] -> RST m (Doc Text)
-notesToRST notes =
-   vsep <$> zipWithM noteToRST [1..] notes
+-- | Return RST representation of the collected notes. Rendering a
+-- note may add further notes to the state (notes nested inside
+-- notes); keep going until all of them have been rendered.
+notesToRST :: PandocMonad m => RST m (Doc Text)
+notesToRST = vsep <$> go 0
+  where
+    go done = do
+      notes <- gets (drop done . reverse . stNotes)
+      if null notes
+        then return []
+        else do
+          docs <- zipWithM noteToRST [done + 1 ..] notes
+          (docs ++) <$> go (done + length notes)
 
 -- | Return RST representation of a note.
 noteToRST :: PandocMonad m => Int -> [Block] -> RST m (Doc Text)
diff --git a/src/Text/Pandoc/Writers/Shared.hs b/src/Text/Pandoc/Writers/Shared.hs
--- a/src/Text/Pandoc/Writers/Shared.hs
+++ b/src/Text/Pandoc/Writers/Shared.hs
@@ -55,6 +55,8 @@
                      , insertCurrentSpansAtColumn
                      , takePreviousSpansAtColumn
                      , decrementTrailingRowSpans
+                     , wrapColumns
+                     , renderWithTemplate
                      )
 where
 import Safe (lastMay, maximumMay)
@@ -83,7 +85,7 @@
 import qualified Text.Pandoc.UTF8 as UTF8
 import Text.Pandoc.XML (escapeStringForXML, rdfaAttributes, html5Attributes)
 import Text.DocTemplates (Context(..), Val(..), TemplateTarget,
-                          ToContext(..), FromContext(..))
+                          ToContext(..), FromContext(..), renderTemplate)
 import Text.Pandoc.Chunks (tocToList, toTOCTree)
 import Text.Collate.Lang (Lang (..))
 import Text.Pandoc.Class (PandocMonad, toLang)
@@ -110,6 +112,24 @@
     Nothing -> return mempty
     Just _  -> addVariablesToContext opts <$>
                 metaToContext' blockWriter inlineWriter meta
+
+-- | The line length to use in rendering: 'writerColumns' if
+-- 'writerWrapText' is 'WrapAuto', otherwise 'Nothing' (no wrapping).
+wrapColumns :: WriterOptions -> Maybe Int
+wrapColumns opts =
+  if writerWrapText opts == WrapAuto
+     then Just $ writerColumns opts
+     else Nothing
+
+-- | Render a document body, inserting it into 'writerTemplate'
+-- (with the given context) if there is a template, and wrapping
+-- lines according to 'wrapColumns'.
+renderWithTemplate :: WriterOptions -> Context Text -> Doc Text -> Text
+renderWithTemplate opts context main =
+  render (wrapColumns opts) $
+    case writerTemplate opts of
+       Nothing  -> main
+       Just tpl -> renderTemplate tpl context
 
 -- | Like 'metaToContext, but does not include variables and is
 -- not sensitive to 'writerTemplate'.
diff --git a/src/Text/Pandoc/Writers/TEI.hs b/src/Text/Pandoc/Writers/TEI.hs
--- a/src/Text/Pandoc/Writers/TEI.hs
+++ b/src/Text/Pandoc/Writers/TEI.hs
@@ -23,7 +23,6 @@
 import Text.DocLayout
 import Text.Pandoc.Shared
 import Text.Pandoc.URI
-import Text.Pandoc.Templates (renderTemplate)
 import Text.Pandoc.Writers.Shared
 import Text.Pandoc.XML
 
@@ -31,9 +30,6 @@
 writeTEI :: PandocMonad m => WriterOptions -> Pandoc -> m Text
 writeTEI opts doc = do
   let Pandoc meta blocks = ensureValidXmlIdentifiers doc
-  let colwidth = if writerWrapText opts == WrapAuto
-                    then Just $ writerColumns opts
-                    else Nothing
   let startLvl = case writerTopLevelDivision opts of
                    TopLevelPart    -> -1
                    TopLevelChapter -> 0
@@ -49,20 +45,12 @@
               $ defField "mathml" (case writerMathMethod opts of
                                           MathML -> True
                                           _      -> False) metadata
-  return $ render colwidth $
-    case writerTemplate opts of
-       Nothing  -> main
-       Just tpl -> renderTemplate tpl context
+  return $ renderWithTemplate opts context main
 
 -- | Convert a list of Pandoc blocks to TEI.
 blocksToTEI :: PandocMonad m => WriterOptions -> [Block] -> m (Doc Text)
 blocksToTEI opts bs = vcat <$> mapM (blockToTEI opts) bs
 
--- | Auxiliary function to convert Plain block to Para.
-plainToPara :: Block -> Block
-plainToPara (Plain x) = Para x
-plainToPara x         = x
-
 -- | Convert a list of pairs of terms and definitions into a TEI
 -- list with labels and items.
 deflistItemsToTEI :: PandocMonad m
@@ -275,8 +263,12 @@
               linktext <- inlinesToTEI opts txt
               return $ linktext <+> char '(' <> emailLink <> char ')'
   | otherwise =
-      inTags False "ref" (("target", src) : idFromAttr opts attr)
+      inTags False "ref" (("target", src') : idFromAttr opts attr)
                  <$> inlinesToTEI opts txt
+  where
+    src' = case T.stripPrefix "#" src of
+             Just ident -> "#" <> writerIdentifierPrefix opts <> ident
+             Nothing    -> src
 inlineToTEI opts (Image attr description (src, tit)) = do
   let titleDoc = if T.null tit
                    then empty
diff --git a/src/Text/Pandoc/Writers/Texinfo.hs b/src/Text/Pandoc/Writers/Texinfo.hs
--- a/src/Text/Pandoc/Writers/Texinfo.hs
+++ b/src/Text/Pandoc/Writers/Texinfo.hs
@@ -36,7 +36,6 @@
 import Text.DocLayout
 import Text.Pandoc.Shared
 import Text.Pandoc.URI
-import Text.Pandoc.Templates (renderTemplate)
 import Text.Pandoc.Writers.Shared
 import Text.Printf (printf)
 
@@ -105,9 +104,6 @@
   blocks <- walkM addNodeText blocks'
   let titlePage = not $ all null
                       $ docTitle meta : docDate meta : docAuthors meta
-  let colwidth = if writerWrapText options == WrapAuto
-                    then Just $ writerColumns options
-                    else Nothing
   metadata <- metaToContext options
               blockListToTexinfo
               (fmap chomp .inlineListToTexinfo)
@@ -118,10 +114,7 @@
               $ defField "toc" (writerTableOfContents options)
               $ defField "titlepage" titlePage
               $ defField "strikeout" (stStrikeout st) metadata
-  return $ render colwidth $
-    case writerTemplate options of
-       Nothing  -> body
-       Just tpl -> renderTemplate tpl context
+  return $ renderWithTemplate options context body
 
 -- | Escape things as needed for Texinfo.
 stringToTexinfo :: PandocMonad m => Text -> TI m Text
diff --git a/src/Text/Pandoc/Writers/Typst.hs b/src/Text/Pandoc/Writers/Typst.hs
--- a/src/Text/Pandoc/Writers/Typst.hs
+++ b/src/Text/Pandoc/Writers/Typst.hs
@@ -32,7 +32,8 @@
 import Control.Monad.State ( StateT, evalStateT, gets, modify )
 import Text.Pandoc.Writers.Shared ( lookupMetaInlines, lookupMetaString,
                                     metaToContext, defField, resetField,
-                                    setupTranslations )
+                                    setupTranslations, getLang,
+                                    renderWithTemplate )
 import Text.Pandoc.Shared (isTightList, orderedListMarkers, tshow,
                            stringifyInlines)
 import Text.Pandoc.Highlighting (highlight, formatTypstBlock, formatTypstInline,
@@ -43,7 +44,6 @@
 import Text.Pandoc.Writers.Math (convertMath)
 import qualified Text.TeXMath as TM
 import Text.DocLayout
-import Text.DocTemplates (renderTemplate)
 import Text.Pandoc.Extensions (Extension(..))
 import Text.Pandoc.Logging (LogMessage(..))
 import qualified Text.Pandoc.UTF8 as UTF8
@@ -85,9 +85,6 @@
 pandocToTypst :: PandocMonad m
               => WriterOptions -> Pandoc -> TW m Text
 pandocToTypst options (Pandoc meta blocks) = do
-  let colwidth = if writerWrapText options == WrapAuto
-                    then Just $ writerColumns options
-                    else Nothing
   setupTranslations meta
   metadata <- metaToContext options
               blocksToTypst
@@ -113,9 +110,9 @@
                        . defField "nocite-ids" (filter (/= "*") nociteIds)
                        . defField "full-bibliography" ("*" `elem` nociteIds)
                     else id)
-              $ (case lookupMetaString "lang" meta of
-                    "" -> id
-                    lang ->
+              $ (case getLang options meta of
+                    Nothing -> id
+                    Just lang ->
                       case parseLang lang of
                         Left _ -> id
                         Right l ->
@@ -144,10 +141,7 @@
                     then defField "section-numbering" ("1.1.1.1.1" :: Text)
                     else id)
               metadata
-  return $ render colwidth $
-    case writerTemplate options of
-       Nothing  -> main
-       Just tpl -> renderTemplate tpl context
+  return $ renderWithTemplate options context main
 
 pickTypstAttrs :: [(Text, Text)] -> ([(Text, Text)],[(Text, Text)])
 pickTypstAttrs = foldr go ([],[])
@@ -220,7 +214,7 @@
     RawBlock fmt str ->
       case fmt of
         Format "typst" -> return $ literal str
-        _ -> return mempty
+        _ -> mempty <$ report (BlockNotRendered block)
     CodeBlock (ident,cls,kvs) code -> do
       let go :: Char -> (Int, Int) -> (Int, Int)
           go '`' (longest, current) =
@@ -522,7 +516,7 @@
     RawInline fmt str ->
       case fmt of
         Format "typst" -> return $ literal str
-        _ -> return mempty
+        _ -> mempty <$ report (InlineNotRendered inline)
     Strikeout inlines -> textstyle "#strike" inlines
     Emph inlines -> textstyle "#emph" inlines
     Underline inlines -> textstyle "#underline" inlines
@@ -659,6 +653,8 @@
     go (lastc, t') c
       | needsEscape c = (c, t' <> escapeChar c)
       | c == '-', lastc == '-', smart = (c, t' <> T.pack ['\\',c])
+      | c == '?', lastc == '-', smart = (c, t' <> T.pack ['\\',c])
+      | c == '.', lastc == '.', smart = (c, t' <> T.pack ['\\',c])
       | c == '/', lastc == '/' = (c, t' <> T.pack ['\\',c])
       | otherwise = (c, T.snoc t' c)
     escapeChar c
diff --git a/test/Tests/Data.hs b/test/Tests/Data.hs
new file mode 100644
--- /dev/null
+++ b/test/Tests/Data.hs
@@ -0,0 +1,198 @@
+{-# LANGUAGE CPP #-}
+{-# LANGUAGE OverloadedStrings #-}
+{-# LANGUAGE TupleSections #-}
+{- |
+   Module      : Tests.Data
+   Copyright   : © 2026 John MacFarlane
+   License     : GNU GPL, version 2 or above
+
+   Maintainer  : John MacFarlane <jgm@berkeley.edu>
+   Stability   : alpha
+   Portability : portable
+
+Tests for data file lookup, including lookup in @PANDOC_DATA_DIRS@.
+-}
+module Tests.Data (tests) where
+
+import Codec.Archive.Zip (Archive, filesInArchive,
+#ifdef EMBED_DATA_FILES
+                          findEntryByPath, fromEntry,
+#endif
+                          toArchive)
+import qualified Data.ByteString as B
+import qualified Data.ByteString.Lazy as BL
+import Data.List (intercalate)
+import qualified Data.Text as T
+import System.FilePath ((</>), searchPathSeparator)
+import System.Info (os)
+import Test.Tasty
+import Test.Tasty.HUnit
+import Text.Pandoc.Class (PandocPure, FileInfo(..), FileTree,
+                          findFileWithDataFallback, getDataDirs,
+                          getPandocDataDirs, insertInFileTree,
+                          modifyPureState, PureState(..), runIOorExplode,
+                          runPure, setUserDataDir)
+import Text.Pandoc.Data (readDataFile, readDefaultDataFile)
+import Data.Time.Clock.POSIX (posixSecondsToUTCTime)
+
+-- | An absolute path that is valid on the current platform.
+absPath :: FilePath -> FilePath
+absPath d = if os == "mingw32" then "C:\\" </> d else "/" </> d
+
+userDir, dirA, dirB :: FilePath
+userDir = absPath "user"
+dirA = absPath "dirA"
+dirB = absPath "dirB"
+
+pandocDataDirs :: [FilePath] -> T.Text
+pandocDataDirs = T.pack . intercalate [searchPathSeparator]
+
+-- | Run a 'PandocPure' action with the given user data directory,
+-- value of @PANDOC_DATA_DIRS@, and files.
+runWith :: Maybe FilePath -> Maybe T.Text -> FileTree -> [(FilePath, B.ByteString)]
+        -> PandocPure a -> Either String a
+runWith mbUserDir mbDataDirs defaultFiles files action =
+  either (Left . show) Right $ runPure $ do
+    modifyPureState $ \st ->
+      st{ stEnv = maybe [] (\x -> [("PANDOC_DATA_DIRS", x)]) mbDataDirs
+        , stFiles = foldr (\(fp, bs) -> insertInFileTree fp (fileInfo bs))
+                          defaultFiles files }
+    setUserDataDir mbUserDir
+    action
+
+fileInfo :: B.ByteString -> FileInfo
+fileInfo bs = FileInfo{ infoFileMTime = posixSecondsToUTCTime 0
+                      , infoFileContents = bs }
+
+-- | Default data files that are needed by the tests, placed where
+-- 'PandocPure' looks for them if data files are not embedded.
+getDefaultFiles :: IO (FileTree, B.ByteString, Archive)
+getDefaultFiles = runIOorExplode $ do
+  abbrevs <- readDefaultDataFile "abbreviations"
+  refdocx <- toArchive . BL.fromStrict <$>
+               readDefaultDataFile "reference.docx"
+  parts <- mapM (\p -> (p,) <$> readDefaultDataFile ("docx" </> p))
+                (filesInArchive refdocx)
+  let tree = foldr (\(fp, bs) -> insertInFileTree ("data" </> fp) (fileInfo bs))
+                   mempty
+                   (("abbreviations", abbrevs) :
+                     [("docx" </> p, bs) | (p, bs) <- parts])
+  return (tree, abbrevs, refdocx)
+
+#ifdef EMBED_DATA_FILES
+-- | Contents of a file in a docx archive.
+docxPart :: FilePath -> B.ByteString -> Maybe BL.ByteString
+docxPart p = fmap fromEntry . findEntryByPath p . toArchive . BL.fromStrict
+#endif
+
+tests :: [TestTree]
+tests =
+  [ testGroup "getPandocDataDirs"
+    [ testCase "PANDOC_DATA_DIRS unset" $
+        runWith Nothing Nothing mempty [] getPandocDataDirs @?= Right []
+    , testCase "ignoring relative and empty entries" $
+        runWith Nothing (Just (pandocDataDirs [dirA, "relative", "", dirB]))
+          mempty [] getPandocDataDirs
+          @?= Right [dirA, dirB]
+    ]
+  , testGroup "getDataDirs"
+    [ testCase "user data dir comes first" $
+        runWith (Just userDir) (Just (pandocDataDirs [dirA, dirB])) mempty []
+          (getDataDirs "templates/default.html5")
+          @?= Right [userDir, dirA, dirB]
+    , testCase "no user data dir" $
+        runWith Nothing (Just (pandocDataDirs [dirA])) mempty []
+          (getDataDirs "abbreviations")
+          @?= Right [dirA]
+    , testCase "absolute path" $
+        runWith (Just userDir) (Just (pandocDataDirs [dirA])) mempty []
+          (getDataDirs (absPath "abbreviations"))
+          @?= Right []
+    , testCase "path relative to parent directory" $
+        runWith (Just userDir) (Just (pandocDataDirs [dirA])) mempty []
+          (getDataDirs (".." </> "abbreviations"))
+          @?= Right []
+    ]
+  , withResource getDefaultFiles (const (return ())) $ \getDefaults ->
+    testGroup "readDataFile"
+    [ testCase "user data dir takes precedence" $ do
+        (defs, _, _) <- getDefaults
+        runWith (Just userDir) (Just (pandocDataDirs [dirA])) defs
+          [ (userDir </> "abbreviations", "user")
+          , (dirA </> "abbreviations", "dirA") ]
+          (readDataFile "abbreviations")
+          @?= Right "user"
+    , testCase "earlier PANDOC_DATA_DIRS entries take precedence" $ do
+        (defs, _, _) <- getDefaults
+        runWith (Just userDir) (Just (pandocDataDirs [dirA, dirB])) defs
+          [ (dirA </> "abbreviations", "dirA")
+          , (dirB </> "abbreviations", "dirB") ]
+          (readDataFile "abbreviations")
+          @?= Right "dirA"
+    , testCase "later PANDOC_DATA_DIRS entries are used" $ do
+        (defs, _, _) <- getDefaults
+        runWith Nothing (Just (pandocDataDirs [dirA, dirB])) defs
+          [ (dirB </> "abbreviations", "dirB") ]
+          (readDataFile "abbreviations")
+          @?= Right "dirB"
+#ifdef EMBED_DATA_FILES
+    , testCase "falls back to default data files" $ do
+        (defs, abbrevs, _) <- getDefaults
+        runWith (Just userDir) (Just (pandocDataDirs [dirA])) defs []
+          (readDataFile "abbreviations")
+          @?= Right abbrevs
+    , testCase "readDefaultDataFile ignores data dirs" $ do
+        (defs, abbrevs, _) <- getDefaults
+        runWith (Just userDir) (Just (pandocDataDirs [dirA])) defs
+          [ (userDir </> "abbreviations", "user")
+          , (dirA </> "abbreviations", "dirA") ]
+          (readDefaultDataFile "abbreviations")
+          @?= Right abbrevs
+    , testCase "reference.docx from PANDOC_DATA_DIRS" $ do
+        (defs, _, _) <- getDefaults
+        runWith Nothing (Just (pandocDataDirs [dirA])) defs
+          [ (dirA </> "reference.docx", "dirA") ]
+          (readDataFile "reference.docx")
+          @?= Right "dirA"
+    , testCase "reference.docx component from PANDOC_DATA_DIRS" $ do
+        (defs, _, _) <- getDefaults
+        let styles = "word" </> "styles.xml"
+        runWith Nothing (Just (pandocDataDirs [dirA])) defs
+          [ (dirA </> "docx" </> styles, "dirA") ]
+          (docxPart styles <$> readDataFile "reference.docx")
+          @?= Right (Just "dirA")
+    , testCase "readDefaultDataFile ignores reference.docx components" $ do
+        (defs, _, refdocx) <- getDefaults
+        let styles = "word" </> "styles.xml"
+        let expected = fromEntry <$> findEntryByPath styles refdocx
+        runWith (Just userDir) (Just (pandocDataDirs [dirA])) defs
+          [ (userDir </> "docx" </> styles, "user")
+          , (dirA </> "docx" </> styles, "dirA") ]
+          (docxPart styles <$> readDefaultDataFile "reference.docx")
+          @?= Right expected
+#endif
+    ]
+  , testGroup "findFileWithDataFallback"
+    [ testCase "file in working directory takes precedence" $
+        runWith (Just userDir) (Just (pandocDataDirs [dirA])) mempty
+          [ ("f.lua", "")
+          , (dirA </> "filters" </> "f.lua", "") ]
+          (findFileWithDataFallback "filters" "f.lua")
+          @?= Right (Just "f.lua")
+    , testCase "user data dir takes precedence" $
+        runWith (Just userDir) (Just (pandocDataDirs [dirA])) mempty
+          [ (userDir </> "filters" </> "f.lua", "")
+          , (dirA </> "filters" </> "f.lua", "") ]
+          (findFileWithDataFallback "filters" "f.lua")
+          @?= Right (Just (userDir </> "filters" </> "f.lua"))
+    , testCase "file in PANDOC_DATA_DIRS" $
+        runWith (Just userDir) (Just (pandocDataDirs [dirA, dirB])) mempty
+          [ (dirB </> "filters" </> "f.lua", "") ]
+          (findFileWithDataFallback "filters" "f.lua")
+          @?= Right (Just (dirB </> "filters" </> "f.lua"))
+    , testCase "file not found" $
+        runWith (Just userDir) (Just (pandocDataDirs [dirA])) mempty []
+          (findFileWithDataFallback "filters" "f.lua")
+          @?= Right Nothing
+    ]
+  ]
diff --git a/test/Tests/Readers/Docx.hs b/test/Tests/Readers/Docx.hs
--- a/test/Tests/Readers/Docx.hs
+++ b/test/Tests/Readers/Docx.hs
@@ -136,6 +136,18 @@
             "docx/empty_field.docx"
             "docx/empty_field.native"
           , testCompare
+            "field without <w:instrText> does not corrupt later lists"
+            "docx/field_no_instrText.docx"
+            "docx/field_no_instrText.native"
+          , testCompare
+            "field with <w:instrText> in tracked change does not corrupt later lists"
+            "docx/field_tracked_instrText.docx"
+            "docx/field_tracked_instrText.native"
+          , testCompare
+            "field without <w:instrText> in a code block keeps its text"
+            "docx/field_no_instrText_codeblock.docx"
+            "docx/field_no_instrText_codeblock.native"
+          , testCompare
             "pageref hyperlinks in <w:instrText> tag"
             "docx/pageref.docx"
             "docx/pageref.native"
@@ -208,6 +220,10 @@
             "docx/nested_smart_tags.docx"
             "docx/nested_smart_tags.native"
           , testCompare
+            "inline customXml elements"
+            "docx/custom_xml.docx"
+            "docx/custom_xml.native"
+          , testCompare
             "remove anchor spans with nothing pointing to them"
             "docx/unused_anchors.docx"
             "docx/unused_anchors.native"
@@ -459,6 +475,14 @@
             "spaces at the edges of changes (reject)"
             "docx/track_changes_edge_spaces.docx"
             "docx/track_changes_edge_spaces_reject.native"
+          , testCompareWithOpts def{readerTrackChanges=AcceptChanges}
+            "paragraph marks in notes stay in their notes (accept)"
+            "docx/track_changes_paragraph_mark_in_note.docx"
+            "docx/track_changes_paragraph_mark_in_note_accept.native"
+          , testCompareWithOpts def{readerTrackChanges=RejectChanges}
+            "paragraph marks in notes stay in their notes (reject)"
+            "docx/track_changes_paragraph_mark_in_note.docx"
+            "docx/track_changes_paragraph_mark_in_note_reject.native"
           , testCompareWithOpts def{readerTrackChanges=AcceptChanges}
             "comments (accept -- no comments)"
             "docx/comments.docx"
diff --git a/test/Tests/Readers/ODT.hs b/test/Tests/Readers/ODT.hs
--- a/test/Tests/Readers/ODT.hs
+++ b/test/Tests/Readers/ODT.hs
@@ -31,7 +31,19 @@
 tests = testsComparingToMarkdown ++ testsComparingToNative ++
         [ testGroup "fodt" (fodtTestsComparingToMarkdown ++
                             fodtTestsComparingToNative ++
-                            fodtTestsComparingToOwnNative) ]
+                            fodtTestsComparingToOwnNative)
+        , testGroup "styles extension"
+          [ unsafePerformIO $ liftM (test id "enabled")
+              (compareFODTToNative stylesopts "odt/fodt/styles.fodt"
+                                              "odt/fodt-native/styles.native")
+          , unsafePerformIO $ liftM (test id "disabled")
+              (compareFODTToNative defopts "odt/fodt/styles.fodt"
+                                           "odt/fodt-native/styles-off.native")
+          ]
+        ]
+  where
+    stylesopts = defopts{ readerExtensions = enableExtension Ext_styles
+                                               (readerExtensions defopts) }
 
 testsComparingToMarkdown :: [TestTree]
 testsComparingToMarkdown    = map nameToTest namesOfTestsComparingToMarkdown
@@ -259,6 +271,7 @@
                                   , "inlinedCode"
                                   , "listContinueNumbering"
                                   , "listContinueNumbering2"
+                                  , "listContinueNumbering3"
                                   , "orderedListMixed"
                                   , "orderedListRoman"
                                   , "orderedListSimple"
diff --git a/test/Tests/Readers/Pptx.hs b/test/Tests/Readers/Pptx.hs
--- a/test/Tests/Readers/Pptx.hs
+++ b/test/Tests/Readers/Pptx.hs
@@ -41,8 +41,62 @@
 tests :: [TestTree]
 tests = [ testGroup "basic"
           [ testCompare
+            "charts"
+            "pptx-reader/charts.pptx"
+            "pptx-reader/charts.native"
+          , testCompare
+            "run formatting and hyperlinks"
+            "pptx-reader/formatting.pptx"
+            "pptx-reader/formatting.native"
+          , testCompare
+            "group shapes"
+            "pptx-reader/groups.pptx"
+            "pptx-reader/groups.native"
+          , testCompare
+            "slide number placeholders"
+            "pptx-reader/slide-numbers.pptx"
+            "pptx-reader/slide-numbers.native"
+          , testCompare
             "text extraction"
             "pptx-reader/basic.pptx"
             "pptx-reader/basic.native"
+          , testCompare
+            "text runs and line breaks"
+            "pptx-reader/runs.pptx"
+            "pptx-reader/runs.native"
+          ]
+        , testGroup "slides"
+          [ testCompare
+            "hidden slides"
+            "pptx-reader/hidden.pptx"
+            "pptx-reader/hidden.native"
+          ]
+        , testGroup "tables"
+          [ testCompare
+            "merged cells"
+            "pptx-reader/table-spans.pptx"
+            "pptx-reader/table-spans.native"
+          ]
+        , testGroup "markup compatibility"
+          [ testCompare
+            "equations and alternate content"
+            "pptx-reader/equations.pptx"
+            "pptx-reader/equations.native"
+          ]
+        , testGroup "lists"
+          [ testCompare
+            "inherited bullets, nesting and numbering"
+            "pptx-reader/lists.pptx"
+            "pptx-reader/lists.native"
+          , testCompare
+            "lists written by the pptx writer"
+            "pptx-reader/lists-writer.pptx"
+            "pptx-reader/lists-writer.native"
+          ]
+        , testGroup "notes"
+          [ testCompare
+            "speaker notes"
+            "pptx-reader/notes.pptx"
+            "pptx-reader/notes.native"
           ]
         ]
diff --git a/test/Tests/Readers/RST.hs b/test/Tests/Readers/RST.hs
--- a/test/Tests/Readers/RST.hs
+++ b/test/Tests/Readers/RST.hs
@@ -217,6 +217,19 @@
           , "bare URI parsing disabled inside emphasis (#4561)" =:
             "*http://location*" =?>
             para (emph (text "http://location"))
+          , "bare URI and email address in angle brackets" =:
+            "See <https://example.com> or <jane-doe@example.com>." =?>
+            para ("See <" <> link "https://example.com" "" "https://example.com" <>
+                  "> or <" <>
+                  link "mailto:jane-doe@example.com" "" "jane-doe@example.com" <>
+                  ">.")
+          , "inline markup after a colon, a slash or a quote" =:
+            "key:*a* path/*b* \"*c*\"" =?>
+            para ("key:" <> emph "a" <> " path/" <> emph "b" <> " \"" <>
+                  emph "c" <> "\"")
+          , "quoted start-strings are not inline markup" =:
+            "(*) and (*), [*] and [*], \"*\" or \"x*\"" =?>
+            para (text "(*) and (*), [*] and [*], \"*\" or \"x*\"")
           , "include newlines" =:
             "**before\nafter**" =?>
             para (strong (text "before\nafter"))
diff --git a/test/Tests/Readers/Xlsx.hs b/test/Tests/Readers/Xlsx.hs
--- a/test/Tests/Readers/Xlsx.hs
+++ b/test/Tests/Readers/Xlsx.hs
@@ -41,8 +41,48 @@
 tests :: [TestTree]
 tests = [ testGroup "basic"
           [ testCompare
+            "cell fonts"
+            "xlsx-reader/cell-fonts.xlsx"
+            "xlsx-reader/cell-fonts.native"
+          , testCompare
+            "inline and rich-text strings"
+            "xlsx-reader/strings.xlsx"
+            "xlsx-reader/strings.native"
+          , testCompare
             "sheet extraction"
             "xlsx-reader/basic.xlsx"
             "xlsx-reader/basic.native"
+          , testCompare
+            "package-absolute relationship targets"
+            "xlsx-reader/absolute-targets.xlsx"
+            "xlsx-reader/absolute-targets.native"
+          ]
+        , testGroup "values"
+          [ testCompare
+            "numbers, booleans and errors"
+            "xlsx-reader/numbers.xlsx"
+            "xlsx-reader/numbers.native"
+          ]
+        , testGroup "dates"
+          [ testCompare
+            "date and time formats"
+            "xlsx-reader/dates.xlsx"
+            "xlsx-reader/dates.native"
+          , testCompare
+            "1904 date system"
+            "xlsx-reader/dates-1904.xlsx"
+            "xlsx-reader/dates-1904.native"
+          ]
+        , testGroup "merged cells"
+          [ testCompare
+            "merged ranges as spans"
+            "xlsx-reader/merged.xlsx"
+            "xlsx-reader/merged.native"
+          ]
+        , testGroup "charts"
+          [ testCompare
+            "charts on a sheet and on a chart sheet"
+            "xlsx-reader/charts.xlsx"
+            "xlsx-reader/charts.native"
           ]
         ]
diff --git a/test/command/1023.md b/test/command/1023.md
--- a/test/command/1023.md
+++ b/test/command/1023.md
@@ -100,7 +100,7 @@
   >{\raggedright\arraybackslash}p{(\linewidth - 6\tabcolsep) * \real{0.2078}}@{}}
 \toprule\noalign{}
 \begin{minipage}[b]{\linewidth}\centering
-Name\footnotemark{}
+Name\pandocfootnotemark{1}
 \end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright
 Capital
 \end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright
@@ -113,7 +113,7 @@
 \midrule\noalign{}
 Denmark & Copenhagen & 5,809,502 & 43,094 \\
 Finland & Helsinki & 5,537,364 & 338,145 \\
-Iceland\footnotemark{} & Reykjavik & 343,518 & 103,000 \\
+Iceland\pandocfootnotemark{2} & Reykjavik & 343,518 & 103,000 \\
 Norway & Oslo & 5,372,191 & 323,802 \\
 Sweden & Stockholm & 10,313,447 & 450,295 \\
 \midrule\noalign{}
@@ -121,9 +121,7 @@
 \bottomrule\noalign{}
 \end{tabular}
 \end{table}
-\addtocounter{footnote}{-1}
-\footnotetext{In English.}
-\addtocounter{footnote}{1}
-\footnotetext{Brrr.}
+\pandocfootnotetext{1}{In English.}
+\pandocfootnotetext{2}{Brrr.}
 
 ```
diff --git a/test/command/11088.md b/test/command/11088.md
new file mode 100644
--- /dev/null
+++ b/test/command/11088.md
@@ -0,0 +1,10 @@
+```
+% pandoc -f latex -t native 2>&1
+\makeatletter
+\def\small{\@setfontsize\small\@ixpt{10}}
+\makeatother
+\small test
+^D
+Loop encountered in expanding macro small
+=> 91
+```
diff --git a/test/command/11113.docx b/test/command/11113.docx
Binary files a/test/command/11113.docx and b/test/command/11113.docx differ
diff --git a/test/command/11689.docx b/test/command/11689.docx
Binary files a/test/command/11689.docx and b/test/command/11689.docx differ
diff --git a/test/command/11833.docx b/test/command/11833.docx
Binary files a/test/command/11833.docx and b/test/command/11833.docx differ
diff --git a/test/command/11852.md b/test/command/11852.md
new file mode 100644
--- /dev/null
+++ b/test/command/11852.md
@@ -0,0 +1,33 @@
+```
+% pandoc -f html -t native
+<p>a<a href="#fn1" class="footnote-ref" id="fnref1" role="doc-noteref"><sup>1</sup></a></p>
+<section id="footnotes" class="footnotes" role="doc-endnotes"><hr /><ol>
+<li id="fn1"><p>note</p><ol><li>one</li><li>two</li></ol>
+<a href="#fnref1" class="footnote-back" role="doc-backlink">x</a></li></ol></section>
+^D
+[ Para
+    [ Str "a"
+    , Note
+        [ Para [ Str "note" ]
+        , OrderedList
+            ( 1 , DefaultStyle , DefaultDelim )
+            [ [ Plain [ Str "one" ] ] , [ Plain [ Str "two" ] ] ]
+        ]
+    ]
+]
+```
+
+```
+% pandoc -f html -t native
+<p>a<a href="#fn1" class="footnote-ref" id="fnref1" role="doc-noteref"><sup>1</sup></a></p>
+<section id="footnotes" class="footnotes" role="doc-endnotes"><hr /><ol>
+<li id="fn1"><p>one</p><hr /><p>two</p>
+<a href="#fnref1" class="footnote-back" role="doc-backlink">x</a></li></ol></section>
+^D
+[ Para
+    [ Str "a"
+    , Note
+        [ Para [ Str "one" ] , HorizontalRule , Para [ Str "two" ] ]
+    ]
+]
+```
diff --git a/test/command/11936.md b/test/command/11936.md
new file mode 100644
--- /dev/null
+++ b/test/command/11936.md
@@ -0,0 +1,139 @@
+Footnotes in tables are deferred. Each `\pandocfootnotetext` must
+be matched to its `\pandocfootnotemark`, and the text of a nested
+note must come after the text containing its mark.
+
+```
+% pandoc -f native -t latex
+[ Table
+    ( "" , [] , [] )
+    (Caption Nothing [])
+    [ ( AlignDefault , ColWidthDefault )
+    , ( AlignDefault , ColWidthDefault )
+    ]
+    (TableHead
+       ( "" , [] , [] )
+       [ Row
+           ( "" , [] , [] )
+           [ Cell
+               ( "" , [] , [] )
+               AlignDefault
+               (RowSpan 1)
+               (ColSpan 1)
+               [ Plain [ Str "A" ] ]
+           , Cell
+               ( "" , [] , [] )
+               AlignDefault
+               (RowSpan 1)
+               (ColSpan 1)
+               [ Plain [ Str "B" ] ]
+           ]
+       ])
+    [ TableBody
+        ( "" , [] , [] )
+        (RowHeadColumns 0)
+        []
+        [ Row
+            ( "" , [] , [] )
+            [ Cell
+                ( "" , [] , [] )
+                AlignDefault
+                (RowSpan 1)
+                (ColSpan 1)
+                [ Plain
+                    [ Str "x"
+                    , Note
+                        [ Para
+                            [ Str "outer"
+                            , Space
+                            , Note [ Para [ Str "inner note" ] ]
+                            ]
+                        ]
+                    ]
+                ]
+            , Cell
+                ( "" , [] , [] )
+                AlignDefault
+                (RowSpan 1)
+                (ColSpan 1)
+                [ Plain [ Str "y" , Note [ Para [ Str "second" ] ] ] ]
+            ]
+        ]
+    ]
+    (TableFoot ( "" , [] , [] ) [])
+]
+^D
+{\def\LTcaptype{none} % do not increment counter
+\begin{longtable}[]{@{}ll@{}}
+\toprule\noalign{}
+A & B \\
+\midrule\noalign{}
+\endhead
+\bottomrule\noalign{}
+\endlastfoot
+x\pandocfootnotemark{2} & y\pandocfootnotemark{3} \\
+\end{longtable}
+}
+\pandocfootnotetext{2}{outer \pandocfootnotemark{1}}
+\pandocfootnotetext{1}{inner note}
+\pandocfootnotetext{3}{second}
+```
+
+The LaTeX reader handles this output, ignoring the definitions of
+the macros from the template:
+
+```
+% pandoc -f latex -t markdown
+\makeatletter
+\protected\def\pandocfootnotemark#1{\footnotemark{}%
+  \expandafter\xdef\csname pandoc@fn@#1\endcsname{%
+    \noexpand\pandoc@fnrestore
+    {\unexpanded\expandafter{\@thefnmark}}%
+    {\ifdefined\Hy@footnote@currentHref
+       \unexpanded\expandafter{\Hy@footnote@currentHref}\fi}}}
+\def\pandoc@fnrestore#1#2{%
+  \gdef\@thefnmark{#1}%
+  \ifdefined\Hy@footnote@currentHref\gdef\Hy@footnote@currentHref{#2}\fi}
+\newcommand\pandocfootnotetext[1]{%
+  \csname pandoc@fn@#1\endcsname\@footnotetext}
+\makeatother
+
+\begin{tabular}{ll}
+x\pandocfootnotemark{2} & y\pandocfootnotemark{3} \\
+\end{tabular}
+\pandocfootnotetext{2}{outer \pandocfootnotemark{1}}
+\pandocfootnotetext{1}{inner note}
+\pandocfootnotetext{3}{second}
+^D
+  ------- -------
+  x[^1]   y[^2]
+  ------- -------
+
+[^1]: outer [^3]
+
+[^2]: second
+
+[^3]: inner note
+```
+
+It also handles adjustments to the footnote counter with
+`\footnotemark` and `\footnotetext`, as in output from
+earlier versions of pandoc:
+
+```
+% pandoc -f latex -t markdown
+\begin{tabular}{ll}
+x\footnotemark{} & y\footnotemark{} \\
+\end{tabular}
+\addtocounter{footnote}{-1}
+\footnotetext{first}
+\addtocounter{footnote}{1}
+\footnotetext{second}
+^D
+  ------- -------
+  x[^1]   y[^2]
+  ------- -------
+
+[^1]: first
+
+[^2]: second
+```
diff --git a/test/command/11944.docx b/test/command/11944.docx
new file mode 100644
Binary files /dev/null and b/test/command/11944.docx differ
diff --git a/test/command/11944.md b/test/command/11944.md
new file mode 100644
--- /dev/null
+++ b/test/command/11944.md
@@ -0,0 +1,14 @@
+A `w:fldSimple` keeps its result text; a REF field with `\h` becomes a
+link to the bookmark it refers to. A caption whose label is not `Figure`
+or `Table` keeps its label and number.
+
+```
+% pandoc command/11944.docx -t html
+^D
+<p>See figure <a href="#_Ref1">1</a>.</p>
+<figure>
+<img src="media/image1.png" style="width:1.09702in;height:1.09702in" />
+<figcaption><p><span id="_Ref1" class="anchor"></span>Figur 1 Blue
+square.</p></figcaption>
+</figure>
+```
diff --git a/test/command/11945.md b/test/command/11945.md
new file mode 100644
--- /dev/null
+++ b/test/command/11945.md
@@ -0,0 +1,34 @@
+A table with more columns than `columns / 8` is still written as a grid
+table, rather than falling back to raw HTML.
+
+```
+% pandoc -f html -t markdown-simple_tables-multiline_tables-pipe_tables
+<table>
+<tr><th>H1</th><th>H2</th><th>H3</th><th>H4</th><th>H5</th><th>H6</th><th>H7</th><th>H8</th><th>H9</th><th>H10</th></tr>
+<tr><td>c1</td><td>c2</td><td>c3</td><td>c4</td><td>c5</td><td>c6</td><td>c7</td><td>c8</td><td>c9</td><td>c10</td></tr>
+</table>
+^D
++----+----+----+----+----+----+----+----+----+-----+
+| H1 | H2 | H3 | H4 | H5 | H6 | H7 | H8 | H9 | H10 |
++====+====+====+====+====+====+====+====+====+=====+
+| c1 | c2 | c3 | c4 | c5 | c6 | c7 | c8 | c9 | c10 |
++----+----+----+----+----+----+----+----+----+-----+
+```
+
+This includes a table with block content in a cell, which has no other
+markdown representation.
+
+```
+% pandoc -f html -t markdown
+<table>
+<tr><th>H1</th><th>H2</th><th>H3</th><th>H4</th><th>H5</th><th>H6</th><th>H7</th><th>H8</th><th>H9</th><th>H10</th></tr>
+<tr><td><ul><li>a</li><li>b</li></ul></td><td>c2</td><td>c3</td><td>c4</td><td>c5</td><td>c6</td><td>c7</td><td>c8</td><td>c9</td><td>c10</td></tr>
+</table>
+^D
++------+------+------+------+------+------+------+------+------+------+
+| H1   | H2   | H3   | H4   | H5   | H6   | H7   | H8   | H9   | H10  |
++======+======+======+======+======+======+======+======+======+======+
+| - a  | c2   | c3   | c4   | c5   | c6   | c7   | c8   | c9   | c10  |
+| - b  |      |      |      |      |      |      |      |      |      |
++------+------+------+------+------+------+------+------+------+------+
+```
diff --git a/test/command/11954.md b/test/command/11954.md
new file mode 100644
--- /dev/null
+++ b/test/command/11954.md
@@ -0,0 +1,12 @@
+```
+% pandoc -t latex
+key = value
+:   Definition
+^D
+\begin{description}
+\tightlist
+\item[{key = value}]
+Definition
+\end{description}
+
+```
diff --git a/test/command/11961.md b/test/command/11961.md
new file mode 100644
--- /dev/null
+++ b/test/command/11961.md
@@ -0,0 +1,8 @@
+```
+% pandoc -f html -t docx -o - | pandoc -f docx -t html
+<p><em>Emph <em>in emph <em>flip</em> flops</em></em> and more</p>
+^D
+<p><em>Emph</em> in emph <em>flip</em> flops and more</p>
+
+```
+
diff --git a/test/command/11979.md b/test/command/11979.md
new file mode 100644
--- /dev/null
+++ b/test/command/11979.md
@@ -0,0 +1,6 @@
+```
+% pandoc -f native -t typst
+[Str "-?", Space, Str "...", Space, Str "a-b."]
+^D
+\-\? \.\.\. a-b.
+```
diff --git a/test/command/11981.md b/test/command/11981.md
new file mode 100644
--- /dev/null
+++ b/test/command/11981.md
@@ -0,0 +1,14 @@
+```
+% pandoc -f native -t rtf | pandoc -f rtf -t native
+[ Para [ Str "abc\8217def" ]
+, Para [ Str "\8220abc\8221" , Space , Str "\8216abc\8217" ]
+, Para [ Str "abc\8217def" ]
+, Para [ Str "abc\8212def" ]
+]
+^D
+[ Para [ Str "abc\8217def" ]
+, Para [ Str "\8220abc\8221" , Space , Str "\8216abc\8217" ]
+, Para [ Str "abc\8217def" ]
+, Para [ Str "abc\8212def" ]
+]
+```
diff --git a/test/command/11987.md b/test/command/11987.md
new file mode 100644
--- /dev/null
+++ b/test/command/11987.md
@@ -0,0 +1,9 @@
+If no class matches a language, we just use the first one.
+````
+% pandoc -f native -t markdown
+[ CodeBlock ( "" , [ "text" ] , [] ) "x" ]
+^D
+``` text
+x
+```
+````
diff --git a/test/command/11988.docx b/test/command/11988.docx
new file mode 100644
Binary files /dev/null and b/test/command/11988.docx differ
diff --git a/test/command/11988.md b/test/command/11988.md
new file mode 100644
--- /dev/null
+++ b/test/command/11988.md
@@ -0,0 +1,25 @@
+Every underline type except `none` is read as underlined text, not
+only `single`.
+
+```
+% pandoc command/11988.docx -t native
+^D
+[ Para
+    [ Underline
+        [ Str "single"
+        , Space
+        , Str "double"
+        , Space
+        , Str "thick"
+        , Space
+        , Str "dotted"
+        , Space
+        , Str "wave"
+        , Space
+        , Str "words"
+        ]
+    , Space
+    , Str "none"
+    ]
+]
+```
diff --git a/test/command/11989.docx b/test/command/11989.docx
new file mode 100644
Binary files /dev/null and b/test/command/11989.docx differ
diff --git a/test/command/11989.md b/test/command/11989.md
new file mode 100644
--- /dev/null
+++ b/test/command/11989.md
@@ -0,0 +1,19 @@
+A `w:gridCol` need not have a width (`w:w`). Such a column is kept,
+and since its width is missing, every column gets the default width.
+
+```
+% pandoc command/11989.docx -t html
+^D
+<table>
+<tbody>
+<tr>
+<td>a</td>
+<td>b</td>
+</tr>
+<tr>
+<td>c</td>
+<td>d</td>
+</tr>
+</tbody>
+</table>
+```
diff --git a/test/command/11991.docx b/test/command/11991.docx
new file mode 100644
Binary files /dev/null and b/test/command/11991.docx differ
diff --git a/test/command/11991.md b/test/command/11991.md
new file mode 100644
--- /dev/null
+++ b/test/command/11991.md
@@ -0,0 +1,37 @@
+Notes and comments are read with the namespace prefixes declared in
+their own parts (word/footnotes.xml, word/endnotes.xml,
+word/comments.xml). Here word/document.xml declares only `w`; the
+footnote's hyperlink uses `r`, and the equations in the endnote and
+the comment use `m`.
+
+```
+% pandoc command/11991.docx -t native --track-changes=all
+^D
+[ Para
+    [ Span
+        ( ""
+        , [ "comment-start" ]
+        , [ ( "comment-id" , "0" )
+          , ( "author" , "A" )
+          , ( "date" , "2026-01-01T00:00:00Z" )
+          ]
+        )
+        [ Str "Math:" , Space , Math InlineMath "x" ]
+    , Str "Text"
+    , Span
+        ( "" , [ "comment-end" ] , [ ( "comment-id" , "0" ) ] ) []
+    , Note
+        [ Para
+            [ Str "See"
+            , Space
+            , Link
+                ( "" , [] , [] )
+                [ Str "example" ]
+                ( "https://example.com/" , "" )
+            ]
+        ]
+    , Note
+        [ Para [ Str "Math:" , Space , Math InlineMath "x" ] ]
+    ]
+]
+```
diff --git a/test/command/12001.md b/test/command/12001.md
new file mode 100644
--- /dev/null
+++ b/test/command/12001.md
@@ -0,0 +1,68 @@
+```
+% pandoc -f markdown+rebase_relative_paths -t native command/12001/note/doc.md command/12001/next/doc.md command/12001/grid/doc.md command/12001/next/doc.md
+^D
+[ Para
+    [ Str "Text"
+    , Note
+        [ Para
+            [ Image
+                ( "" , [] , [] )
+                [ Str "C" ]
+                ( "command/12001/note/img/note.png" , "" )
+            , Space
+            , Link
+                ( "" , [] , [] )
+                [ Str "doc" ]
+                ( "command/12001/note/files/doc.pdf" , "" )
+            ]
+        ]
+    ]
+, Para
+    [ Str "Next"
+    , Space
+    , Image
+        ( "" , [] , [] )
+        [ Str "N" ]
+        ( "command/12001/next/img/next.png" , "" )
+    ]
+, Table
+    ( "" , [] , [] )
+    (Caption Nothing [])
+    [ ( AlignDefault , ColWidth 0.3194444444444444 ) ]
+    (TableHead ( "" , [] , [] ) [])
+    [ TableBody
+        ( "" , [] , [] )
+        (RowHeadColumns 0)
+        []
+        [ Row
+            ( "" , [] , [] )
+            [ Cell
+                ( "" , [] , [] )
+                AlignDefault
+                (RowSpan 1)
+                (ColSpan 1)
+                [ Figure
+                    ( "" , [] , [] )
+                    (Caption Nothing [ Plain [ Str "C" ] ])
+                    [ Plain
+                        [ Image
+                            ( "" , [] , [] )
+                            [ Str "C" ]
+                            ( "command/12001/grid/img/grid.png" , "" )
+                        ]
+                    ]
+                ]
+            ]
+        ]
+    ]
+    (TableFoot ( "" , [] , [] ) [])
+, Para
+    [ Str "Next"
+    , Space
+    , Image
+        ( "" , [] , [] )
+        [ Str "N" ]
+        ( "command/12001/next/img/next.png" , "" )
+    ]
+]
+```
diff --git a/test/command/12001/grid/doc.md b/test/command/12001/grid/doc.md
new file mode 100644
--- /dev/null
+++ b/test/command/12001/grid/doc.md
@@ -0,0 +1,3 @@
++----------------------+
+| ![C](img/grid.png)   |
++----------------------+
diff --git a/test/command/12001/next/doc.md b/test/command/12001/next/doc.md
new file mode 100644
--- /dev/null
+++ b/test/command/12001/next/doc.md
@@ -0,0 +1,1 @@
+Next ![N](img/next.png)
diff --git a/test/command/12001/note/doc.md b/test/command/12001/note/doc.md
new file mode 100644
--- /dev/null
+++ b/test/command/12001/note/doc.md
@@ -0,0 +1,3 @@
+Text[^1]
+
+[^1]: ![C](img/note.png) [doc](files/doc.pdf)
diff --git a/test/command/12051.md b/test/command/12051.md
new file mode 100644
--- /dev/null
+++ b/test/command/12051.md
@@ -0,0 +1,10 @@
+```
+% pandoc -f markdown -t native
+\itshape
+hello\
+world
+^D
+[ Para
+    [ RawInline (Format "tex") "\\itshape\nhello\\\nworld" ]
+]
+```
diff --git a/test/command/12060.md b/test/command/12060.md
new file mode 100644
--- /dev/null
+++ b/test/command/12060.md
@@ -0,0 +1,12 @@
+Custom style names are encoded as LibreOffice does:
+
+```
+% pandoc -t opendocument
+::: {custom-style="My Style"}
+[Text here]{custom-style="Char (1)"} and [more]{custom-style="Quote_20_Text"}
+:::
+^D
+<text:p text:style-name="My_20_Style"><text:span text:style-name="Char_20__28_1_29_">Text
+here</text:span> and
+<text:span text:style-name="Quote_20_Text">more</text:span></text:p>
+```
diff --git a/test/command/12063.md b/test/command/12063.md
new file mode 100644
--- /dev/null
+++ b/test/command/12063.md
@@ -0,0 +1,14 @@
+```
+% pandoc -f rst -t gfm
+======== ====================
+Suffix   Meaning
+======== ====================
+-set     Set a list of items
+-append  Append single item
+======== ====================
+^D
+| Suffix  | Meaning             |
+|---------|---------------------|
+| -set    | Set a list of items |
+| -append | Append single item  |
+```
diff --git a/test/command/12071.md b/test/command/12071.md
new file mode 100644
--- /dev/null
+++ b/test/command/12071.md
@@ -0,0 +1,11 @@
+```
+% pandoc -f rst -t native
+::
+
+        foo
+    bar
+
+        baz
+^D
+[ CodeBlock ( "" , [] , [] ) "    foo\nbar\n\n    baz" ]
+```
diff --git a/test/command/2378.md b/test/command/2378.md
--- a/test/command/2378.md
+++ b/test/command/2378.md
@@ -14,7 +14,7 @@
 \begin{longtable}[]{@{}ll@{}}
 \caption{a table}\tabularnewline
 \toprule\noalign{}
-x & y\footnotemark{} \\
+x & y\pandocfootnotemark{1} \\
 \midrule\noalign{}
 \endfirsthead
 \toprule\noalign{}
@@ -25,5 +25,5 @@
 \endlastfoot
 1 & 2 \\
 \end{longtable}
-\footnotetext{a footnote}
+\pandocfootnotetext{1}{a footnote}
 ```
diff --git a/test/command/2623.odt b/test/command/2623.odt
Binary files a/test/command/2623.odt and b/test/command/2623.odt differ
diff --git a/test/command/4558.md b/test/command/4558.md
new file mode 100644
--- /dev/null
+++ b/test/command/4558.md
@@ -0,0 +1,69 @@
+```
+% pandoc -f html -t latex
+<table class="repeat-caption">
+  <caption>Repeated caption.</caption>
+  <thead><tr><th>one</th><th>two</th></tr></thead>
+  <tbody><tr><td>1</td><td>2</td></tr></tbody>
+</table>
+^D
+\begin{longtable}[]{@{}ll@{}}
+\caption{Repeated caption.}\tabularnewline
+\toprule\noalign{}
+one & two \\
+\midrule\noalign{}
+\endfirsthead
+\caption[]{Repeated caption.}\tabularnewline
+\toprule\noalign{}
+one & two \\
+\midrule\noalign{}
+\endhead
+\bottomrule\noalign{}
+\endlastfoot
+1 & 2 \\
+\end{longtable}
+```
+
+```
+% pandoc -f html -t latex
+<table class="repeat-caption">
+  <caption>Repeated caption.</caption>
+  <tbody><tr><td>one</td><td>two</td></tr></tbody>
+</table>
+^D
+\begin{longtable}[]{@{}ll@{}}
+\caption{Repeated caption.}\tabularnewline
+\toprule\noalign{}
+\endfirsthead
+\caption[]{Repeated caption.}\tabularnewline
+\toprule\noalign{}
+\endhead
+\bottomrule\noalign{}
+\endlastfoot
+one & two \\
+\end{longtable}
+```
+
+```
+% pandoc -f html -t latex --table-caption-position=below
+<table class="repeat-caption">
+  <caption>Repeated caption.</caption>
+  <thead><tr><th>one</th><th>two</th></tr></thead>
+  <tbody><tr><td>1</td><td>2</td></tr></tbody>
+</table>
+^D
+\begin{longtable}[]{@{}ll@{}}
+\toprule\noalign{}
+one & two \\
+\midrule\noalign{}
+\endhead
+\bottomrule\noalign{}
+\tabularnewline
+\caption[]{Repeated caption.}
+\endfoot
+\bottomrule\noalign{}
+\tabularnewline
+\caption{Repeated caption.}
+\endlastfoot
+1 & 2 \\
+\end{longtable}
+```
diff --git a/test/command/4819.md b/test/command/4819.md
--- a/test/command/4819.md
+++ b/test/command/4819.md
@@ -49,7 +49,9 @@
 ...
 ^D
 Pandoc
-  Meta { unMeta = fromList [ ( "foo" , MetaBool False ) ] }
+  Meta
+    { unMeta = fromList [ ( "foo" , MetaInlines [ Str "no" ] ) ]
+    }
   []
 ```
 
diff --git a/test/command/5367.md b/test/command/5367.md
--- a/test/command/5367.md
+++ b/test/command/5367.md
@@ -22,10 +22,11 @@
 
 \begin{longtable}[]{@{}
   >{\centering\arraybackslash}p{(\linewidth - 0\tabcolsep) * \real{0.1667}}@{}}
-\caption[Sample table.]{Sample table.\footnotemark{}}\tabularnewline
+\caption[Sample table.]{Sample
+table.\pandocfootnotemark{1}}\tabularnewline
 \toprule\noalign{}
 \begin{minipage}[b]{\linewidth}\centering
-Fruit\footnotemark{}
+Fruit\pandocfootnotemark{2}
 \end{minipage} \\
 \midrule\noalign{}
 \endfirsthead
@@ -37,14 +38,11 @@
 \endhead
 \bottomrule\noalign{}
 \endlastfoot
-Bans\footnotemark{} \\
+Bans\pandocfootnotemark{3} \\
 \end{longtable}
-\addtocounter{footnote}{-2}
-\footnotetext{caption footnote}
-\addtocounter{footnote}{1}
-\footnotetext{header footnote}
-\addtocounter{footnote}{1}
-\footnotetext{table cell footnote}
+\pandocfootnotetext{1}{caption footnote}
+\pandocfootnotetext{2}{header footnote}
+\pandocfootnotetext{3}{table cell footnote}
 
 dolly\footnote{doc footnote}
 ```
diff --git a/test/command/5476.md b/test/command/5476.md
--- a/test/command/5476.md
+++ b/test/command/5476.md
@@ -5,8 +5,8 @@
 \begin{figure}
 \centering
 \pandocbounded{\includegraphics[keepaspectratio,alt={moon}]{test/lalune.jpg}}
-\caption[moon]{moon\footnotemark{}}
+\caption[moon]{moon\pandocfootnotemark{1}}
 \end{figure}
-\footnotetext{the moon}
+\pandocfootnotetext{1}{the moon}
 ```
 
diff --git a/test/command/5753.md b/test/command/5753.md
--- a/test/command/5753.md
+++ b/test/command/5753.md
@@ -11,8 +11,8 @@
 end
 ^D
 [ Para
-    [ Math DisplayMath "q_3\n+ 4"
-    , Math DisplayMath "- 5 +\nq_5"
+    [ Math DisplayMath "q_3\n + 4"
+    , Math DisplayMath "- 5 +\n  q_5"
     ]
 , Para [ Str "end" ]
 ]
diff --git a/test/command/7691.docx b/test/command/7691.docx
Binary files a/test/command/7691.docx and b/test/command/7691.docx differ
diff --git a/test/command/7744.md b/test/command/7744.md
new file mode 100644
--- /dev/null
+++ b/test/command/7744.md
@@ -0,0 +1,62 @@
+ANSI escape sequences are stripped from code in output cells
+unless the output is ipynb (#5633).  This used to take time
+quadratic in the length of the output (#7744).
+
+```
+% pandoc -f ipynb -t native
+{
+ "cells": [
+  {
+   "cell_type": "code",
+   "execution_count": 1,
+   "metadata": {},
+   "outputs": [
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "\u001b[1;31mError\u001b[0m: café 日本\n",
+      "[0m and \u001b(B are kept\n",
+      "\u001b[32m\u001b[1mok\u001b[0m\u001b[0m\n",
+      "\u001b[2K\n",
+      "loading model\n",
+      "\u001b[31 \u001b[0m tail\n",
+      "\u001b[1\u001b(Bm end\n"
+     ]
+    },
+    {
+     "name": "stderr",
+     "output_type": "stream",
+     "text": [
+      "cut \u001b[31 at the end"
+     ]
+    }
+   ],
+   "source": [
+    "print(x)"
+   ]
+  }
+ ],
+ "metadata": {},
+ "nbformat": 4,
+ "nbformat_minor": 5
+}
+^D
+[ Div
+    ( ""
+    , [ "cell" , "code" ]
+    , [ ( "execution_count" , "1" ) ]
+    )
+    [ CodeBlock ( "" , [ "python" ] , [] ) "print(x)"
+    , Div
+        ( "" , [ "output" , "stream" , "stdout" ] , [] )
+        [ CodeBlock
+            ( "" , [] , [] )
+            "Error: caf\233 \26085\26412\n[0m and \ESC(B are kept\nok\nodel\n tail\n end\n"
+        ]
+    , Div
+        ( "" , [ "output" , "stream" , "stderr" ] , [] )
+        [ CodeBlock ( "" , [] , [] ) "cut " ]
+    ]
+]
+```
diff --git a/test/command/8240.md b/test/command/8240.md
--- a/test/command/8240.md
+++ b/test/command/8240.md
@@ -7,8 +7,8 @@
 ^D
 \begin{description}
 \tightlist
-\item[Header\footnotemark{}:]
+\item[Header\pandocfootnotemark{1}:]
 Some other text.
 \end{description}
-\footnotetext{A footnote.}
+\pandocfootnotetext{1}{A footnote.}
 ```
diff --git a/test/command/9002.docx b/test/command/9002.docx
Binary files a/test/command/9002.docx and b/test/command/9002.docx differ
diff --git a/test/command/9183.docx b/test/command/9183.docx
new file mode 100644
Binary files /dev/null and b/test/command/9183.docx differ
diff --git a/test/command/9183.md b/test/command/9183.md
new file mode 100644
--- /dev/null
+++ b/test/command/9183.md
@@ -0,0 +1,10 @@
+Adjacent "Source Code" paragraphs become one code block with `+styles`,
+as they do without it:
+```
+% pandoc -f docx+styles -t native command/9183.docx
+^D
+[ Div
+    ( "" , [] , [ ( "custom-style" , "Source Code" ) ] )
+    [ CodeBlock ( "" , [] , [] ) "x = 1\ny = x + 1" ]
+]
+```
diff --git a/test/command/9197.md b/test/command/9197.md
new file mode 100644
--- /dev/null
+++ b/test/command/9197.md
@@ -0,0 +1,33 @@
+Paragraphs after the first in a list item should not be turned
+into items of a separate list, and should round-trip:
+
+```
+% pandoc -f native -t docx -o - | pandoc -f docx -t native
+[ BulletList
+    [ [ Para [ Str "one" ]
+      , Para [ Str "sub" ]
+      , BulletList
+          [ [ Para [ Str "nested" ]
+            , Para [ Str "nested" , Space , Str "sub" ]
+            ]
+          ]
+      , Para [ Str "back" ]
+      ]
+    , [ Para [ Str "two" ] ]
+    ]
+]
+^D
+[ BulletList
+    [ [ Para [ Str "one" ]
+      , Para [ Str "sub" ]
+      , BulletList
+          [ [ Para [ Str "nested" ]
+            , Para [ Str "nested" , Space , Str "sub" ]
+            ]
+          ]
+      , Para [ Str "back" ]
+      ]
+    , [ Para [ Str "two" ] ]
+    ]
+]
+```
diff --git a/test/command/9222.docx b/test/command/9222.docx
new file mode 100644
Binary files /dev/null and b/test/command/9222.docx differ
diff --git a/test/command/9222.md b/test/command/9222.md
new file mode 100644
--- /dev/null
+++ b/test/command/9222.md
@@ -0,0 +1,10 @@
+A list whose abstract numbering only has a `w:numStyleLink` takes its
+levels from the abstract numbering with the matching `w:styleLink`:
+```
+% pandoc -f docx -t native command/9222.docx
+^D
+[ OrderedList
+    ( 1 , Decimal , Period )
+    [ [ Plain [ Str "one" ] ] , [ Plain [ Str "two" ] ] ]
+]
+```
diff --git a/test/command/9358.docx b/test/command/9358.docx
Binary files a/test/command/9358.docx and b/test/command/9358.docx differ
diff --git a/test/command/9391.docx b/test/command/9391.docx
Binary files a/test/command/9391.docx and b/test/command/9391.docx differ
diff --git a/test/command/9603.docx b/test/command/9603.docx
Binary files a/test/command/9603.docx and b/test/command/9603.docx differ
diff --git a/test/command/epub-invalid-date.md b/test/command/epub-invalid-date.md
new file mode 100644
--- /dev/null
+++ b/test/command/epub-invalid-date.md
@@ -0,0 +1,15 @@
+Dates that cannot be normalized are skipped, so that `dc:date`
+is not empty.
+
+```
+% pandoc -t epub3 -o - | pandoc -f epub -t plain -s
+---
+title: T
+date: [10 septembre 2026, 2026-09-10]
+---
+^D
+T
+2026-09-10
+
+T
+```
diff --git a/test/command/epub-title-header-id.md b/test/command/epub-title-header-id.md
new file mode 100644
--- /dev/null
+++ b/test/command/epub-title-header-id.md
@@ -0,0 +1,22 @@
+The identifier of the title header added before initial content
+must not clash with an existing one, even inside a div.
+
+```
+% pandoc -t epub3 --metadata title=Intro -o - | pandoc -f epub -t html
+See [Intro](#intro).
+
+::: box
+# Intro
+:::
+^D
+<p><span id="title_page.xhtml"></span></p>
+<p><span id="ch001.xhtml"></span></p>
+<section id="ch001.xhtml_intro-1" class="unnumbered level1">
+<h1 class="unnumbered">Intro</h1>
+<p>See <a href="#ch002.xhtml_intro">Intro</a>.</p>
+</section>
+<p><span id="ch002.xhtml"></span></p>
+<section id="ch002.xhtml_intro" class="level1 box">
+<h1>Intro</h1>
+</section>
+```
diff --git a/test/command/nested-notes.md b/test/command/nested-notes.md
new file mode 100644
--- /dev/null
+++ b/test/command/nested-notes.md
@@ -0,0 +1,43 @@
+```
+% pandoc -f native -t markdown
+[Para [Str "a", Note [Para [Str "outer", Note [Para [Str "inner"]]]], Str "b", Note [Para [Str "second"]]]]
+^D
+a[^1]b[^2]
+
+[^1]: outer[^3]
+
+[^2]: second
+
+[^3]: inner
+```
+
+```
+% pandoc -f native -t rst
+[Para [Str "a", Note [Para [Str "outer", Note [Para [Str "inner"]]]], Str "b", Note [Para [Str "second"]]]]
+^D
+a [1]_b [2]_
+
+.. [1]
+   outer [3]_
+
+.. [2]
+   second
+
+.. [3]
+   inner
+```
+
+```
+% pandoc -f native -t haddock
+[Para [Str "a", Note [Para [Str "outer", Note [Para [Str "inner"]]]], Str "b", Note [Para [Str "second"]]]]
+^D
+a<#notes [1]>b<#notes [2]>
+
+#notes#
+
+1.  outer<#notes [3]>
+
+2.  second
+
+3.  inner
+```
diff --git a/test/command/pandoc-citeproc-119.md b/test/command/pandoc-citeproc-119.md
--- a/test/command/pandoc-citeproc-119.md
+++ b/test/command/pandoc-citeproc-119.md
@@ -24,7 +24,7 @@
 
 ::: {#ref-averroes/hannes .csl-entry}
 Averroes. (1892). *Des Averroës Abhandlung: "Über die Möglichkeit der
-Conjunktion" oder "Über den materiellen Intellekt"*. (L. Hannes, Ed. &
+Conjunktion" oder "Über den materiellen Intellekt."* (L. Hannes, Ed. &
 Trans.). Halle an der Saale: C. A. Kaemmerer.
 :::
 
diff --git a/test/command/pandoc-citeproc-57.md b/test/command/pandoc-citeproc-57.md
--- a/test/command/pandoc-citeproc-57.md
+++ b/test/command/pandoc-citeproc-57.md
@@ -30,7 +30,7 @@
 :::: {#refs .references .csl-bib-body .hanging-indent entry-spacing="0"}
 ::: {#ref-Faraday-forthcoming .csl-entry}
 Faraday, Carry. Forthcoming. "Protean Photography." In *Seven Trips
-Beyond the Asteroid Belt*, edited by James Oring. Cape Canaveral, FL:
+beyond the Asteroid Belt*, edited by James Oring. Cape Canaveral, FL:
 Launch Press.
 :::
 ::::
diff --git a/test/docx/0_level_headers.docx b/test/docx/0_level_headers.docx
Binary files a/test/docx/0_level_headers.docx and b/test/docx/0_level_headers.docx differ
diff --git a/test/docx/adjacent_codeblocks.docx b/test/docx/adjacent_codeblocks.docx
Binary files a/test/docx/adjacent_codeblocks.docx and b/test/docx/adjacent_codeblocks.docx differ
diff --git a/test/docx/already_auto_ident.docx b/test/docx/already_auto_ident.docx
Binary files a/test/docx/already_auto_ident.docx and b/test/docx/already_auto_ident.docx differ
diff --git a/test/docx/alternate_document_path.docx b/test/docx/alternate_document_path.docx
Binary files a/test/docx/alternate_document_path.docx and b/test/docx/alternate_document_path.docx differ
diff --git a/test/docx/anchor_header_after_anchor.docx b/test/docx/anchor_header_after_anchor.docx
Binary files a/test/docx/anchor_header_after_anchor.docx and b/test/docx/anchor_header_after_anchor.docx differ
diff --git a/test/docx/block_quotes.docx b/test/docx/block_quotes.docx
Binary files a/test/docx/block_quotes.docx and b/test/docx/block_quotes.docx differ
diff --git a/test/docx/char_styles.docx b/test/docx/char_styles.docx
Binary files a/test/docx/char_styles.docx and b/test/docx/char_styles.docx differ
diff --git a/test/docx/codeblock.docx b/test/docx/codeblock.docx
Binary files a/test/docx/codeblock.docx and b/test/docx/codeblock.docx differ
diff --git a/test/docx/comments.docx b/test/docx/comments.docx
Binary files a/test/docx/comments.docx and b/test/docx/comments.docx differ
diff --git a/test/docx/comments_warning.docx b/test/docx/comments_warning.docx
Binary files a/test/docx/comments_warning.docx and b/test/docx/comments_warning.docx differ
diff --git a/test/docx/compact-style-removal.docx b/test/docx/compact-style-removal.docx
Binary files a/test/docx/compact-style-removal.docx and b/test/docx/compact-style-removal.docx differ
diff --git a/test/docx/cross_reference.docx b/test/docx/cross_reference.docx
Binary files a/test/docx/cross_reference.docx and b/test/docx/cross_reference.docx differ
diff --git a/test/docx/custom_xml.docx b/test/docx/custom_xml.docx
new file mode 100644
Binary files /dev/null and b/test/docx/custom_xml.docx differ
diff --git a/test/docx/custom_xml.native b/test/docx/custom_xml.native
new file mode 100644
--- /dev/null
+++ b/test/docx/custom_xml.native
@@ -0,0 +1,36 @@
+[ Para
+    [ Str "This"
+    , Space
+    , Str "is"
+    , Space
+    , Str "some"
+    , Space
+    , Str "sample"
+    , Space
+    , Str "content"
+    , Space
+    , Str "that"
+    , Space
+    , Str "will"
+    , Space
+    , Str "be"
+    , Space
+    , Str "wrapped"
+    , Space
+    , Str "inside"
+    , Space
+    , Str "a"
+    , Space
+    , Str "customXml"
+    , Space
+    , Str "element"
+    , Space
+    , Str "in"
+    , Space
+    , Str "the"
+    , Space
+    , Str "OpenXML"
+    , Space
+    , Str "structure."
+    ]
+]
diff --git a/test/docx/deep_normalize.docx b/test/docx/deep_normalize.docx
Binary files a/test/docx/deep_normalize.docx and b/test/docx/deep_normalize.docx differ
diff --git a/test/docx/definition_list.docx b/test/docx/definition_list.docx
Binary files a/test/docx/definition_list.docx and b/test/docx/definition_list.docx differ
diff --git a/test/docx/diagram.docx b/test/docx/diagram.docx
Binary files a/test/docx/diagram.docx and b/test/docx/diagram.docx differ
diff --git a/test/docx/double_strikeout.docx b/test/docx/double_strikeout.docx
Binary files a/test/docx/double_strikeout.docx and b/test/docx/double_strikeout.docx differ
diff --git a/test/docx/drop_cap.docx b/test/docx/drop_cap.docx
Binary files a/test/docx/drop_cap.docx and b/test/docx/drop_cap.docx differ
diff --git a/test/docx/dummy_item_after_list_item.docx b/test/docx/dummy_item_after_list_item.docx
Binary files a/test/docx/dummy_item_after_list_item.docx and b/test/docx/dummy_item_after_list_item.docx differ
diff --git a/test/docx/dummy_item_after_paragraph.docx b/test/docx/dummy_item_after_paragraph.docx
Binary files a/test/docx/dummy_item_after_paragraph.docx and b/test/docx/dummy_item_after_paragraph.docx differ
diff --git a/test/docx/empty_field.docx b/test/docx/empty_field.docx
Binary files a/test/docx/empty_field.docx and b/test/docx/empty_field.docx differ
diff --git a/test/docx/enumerated_headings.docx b/test/docx/enumerated_headings.docx
Binary files a/test/docx/enumerated_headings.docx and b/test/docx/enumerated_headings.docx differ
diff --git a/test/docx/field_no_instrText.docx b/test/docx/field_no_instrText.docx
new file mode 100644
Binary files /dev/null and b/test/docx/field_no_instrText.docx differ
diff --git a/test/docx/field_no_instrText.native b/test/docx/field_no_instrText.native
new file mode 100644
--- /dev/null
+++ b/test/docx/field_no_instrText.native
@@ -0,0 +1,24 @@
+[ Para
+    [ Str "Error!"
+    , Space
+    , Str "Reference"
+    , Space
+    , Str "source"
+    , Space
+    , Str "not"
+    , Space
+    , Str "found."
+    ]
+, Para
+    [ Link
+        ( "" , [] , [] )
+        [ Str "Target" , Space , Str "B" ]
+        ( "#_Ref2" , "" )
+    ]
+, BulletList
+    [ [ Para [ Str "Item" , Space , Str "one" ] ]
+    , [ Para [ Str "Item" , Space , Str "two" ] ]
+    ]
+, Para
+    [ Str "After" , Space , Str "the" , Space , Str "list." ]
+]
diff --git a/test/docx/field_no_instrText_codeblock.docx b/test/docx/field_no_instrText_codeblock.docx
new file mode 100644
Binary files /dev/null and b/test/docx/field_no_instrText_codeblock.docx differ
diff --git a/test/docx/field_no_instrText_codeblock.native b/test/docx/field_no_instrText_codeblock.native
new file mode 100644
--- /dev/null
+++ b/test/docx/field_no_instrText_codeblock.native
@@ -0,0 +1,1 @@
+[ CodeBlock ( "" , [] , [] ) "int x;" ]
diff --git a/test/docx/field_tracked_instrText.docx b/test/docx/field_tracked_instrText.docx
new file mode 100644
Binary files /dev/null and b/test/docx/field_tracked_instrText.docx differ
diff --git a/test/docx/field_tracked_instrText.native b/test/docx/field_tracked_instrText.native
new file mode 100644
--- /dev/null
+++ b/test/docx/field_tracked_instrText.native
@@ -0,0 +1,14 @@
+[ Para [ Str "Target" , Space , Str "A" ]
+, Para
+    [ Link
+        ( "" , [] , [] )
+        [ Str "Target" , Space , Str "B" ]
+        ( "#_Ref2" , "" )
+    ]
+, BulletList
+    [ [ Para [ Str "Item" , Space , Str "one" ] ]
+    , [ Para [ Str "Item" , Space , Str "two" ] ]
+    ]
+, Para
+    [ Str "After" , Space , Str "the" , Space , Str "list." ]
+]
diff --git a/test/docx/german_styled_lists.docx b/test/docx/german_styled_lists.docx
Binary files a/test/docx/german_styled_lists.docx and b/test/docx/german_styled_lists.docx differ
diff --git a/test/docx/golden/lists.docx b/test/docx/golden/lists.docx
Binary files a/test/docx/golden/lists.docx and b/test/docx/golden/lists.docx differ
diff --git a/test/docx/golden/lists_div_bullets.docx b/test/docx/golden/lists_div_bullets.docx
Binary files a/test/docx/golden/lists_div_bullets.docx and b/test/docx/golden/lists_div_bullets.docx differ
diff --git a/test/docx/golden/task_list.docx b/test/docx/golden/task_list.docx
Binary files a/test/docx/golden/task_list.docx and b/test/docx/golden/task_list.docx differ
diff --git a/test/docx/hanging_indent.docx b/test/docx/hanging_indent.docx
Binary files a/test/docx/hanging_indent.docx and b/test/docx/hanging_indent.docx differ
diff --git a/test/docx/headers.docx b/test/docx/headers.docx
Binary files a/test/docx/headers.docx and b/test/docx/headers.docx differ
diff --git a/test/docx/i18n_blocks.docx b/test/docx/i18n_blocks.docx
Binary files a/test/docx/i18n_blocks.docx and b/test/docx/i18n_blocks.docx differ
diff --git a/test/docx/image.docx b/test/docx/image.docx
Binary files a/test/docx/image.docx and b/test/docx/image.docx differ
diff --git a/test/docx/image_vml.docx b/test/docx/image_vml.docx
Binary files a/test/docx/image_vml.docx and b/test/docx/image_vml.docx differ
diff --git a/test/docx/image_vml_as_object.docx b/test/docx/image_vml_as_object.docx
Binary files a/test/docx/image_vml_as_object.docx and b/test/docx/image_vml_as_object.docx differ
diff --git a/test/docx/image_with_textbox_caption.docx b/test/docx/image_with_textbox_caption.docx
Binary files a/test/docx/image_with_textbox_caption.docx and b/test/docx/image_with_textbox_caption.docx differ
diff --git a/test/docx/inline_code.docx b/test/docx/inline_code.docx
Binary files a/test/docx/inline_code.docx and b/test/docx/inline_code.docx differ
diff --git a/test/docx/inline_formatting.docx b/test/docx/inline_formatting.docx
Binary files a/test/docx/inline_formatting.docx and b/test/docx/inline_formatting.docx differ
diff --git a/test/docx/instrText_hyperlink.docx b/test/docx/instrText_hyperlink.docx
Binary files a/test/docx/instrText_hyperlink.docx and b/test/docx/instrText_hyperlink.docx differ
diff --git a/test/docx/link_in_notes.docx b/test/docx/link_in_notes.docx
Binary files a/test/docx/link_in_notes.docx and b/test/docx/link_in_notes.docx differ
diff --git a/test/docx/link_tooltips.docx b/test/docx/link_tooltips.docx
Binary files a/test/docx/link_tooltips.docx and b/test/docx/link_tooltips.docx differ
diff --git a/test/docx/links.docx b/test/docx/links.docx
Binary files a/test/docx/links.docx and b/test/docx/links.docx differ
diff --git a/test/docx/lists-compact.docx b/test/docx/lists-compact.docx
Binary files a/test/docx/lists-compact.docx and b/test/docx/lists-compact.docx differ
diff --git a/test/docx/lists.docx b/test/docx/lists.docx
Binary files a/test/docx/lists.docx and b/test/docx/lists.docx differ
diff --git a/test/docx/lists_continuing.docx b/test/docx/lists_continuing.docx
Binary files a/test/docx/lists_continuing.docx and b/test/docx/lists_continuing.docx differ
diff --git a/test/docx/lists_level_override.docx b/test/docx/lists_level_override.docx
Binary files a/test/docx/lists_level_override.docx and b/test/docx/lists_level_override.docx differ
diff --git a/test/docx/lists_level_override.native b/test/docx/lists_level_override.native
--- a/test/docx/lists_level_override.native
+++ b/test/docx/lists_level_override.native
@@ -77,93 +77,91 @@
             , Space
             , Str "Documentation"
             ]
+        , Para
+            [ Strong
+                [ Str "Goal:"
+                , Space
+                , Str "Baseline"
+                , Space
+                , Str "and"
+                , Space
+                , Str "ongoing"
+                , Space
+                , Str "metrics"
+                , Space
+                , Str "tracking"
+                , Space
+                , Str "doc"
+                , Space
+                , Str "usefulness"
+                , Space
+                , Str "and"
+                , Space
+                , Str "completeness."
+                ]
+            ]
+        , Para [ Str "\160" ]
         ]
       ]
-  , BlockQuote
-      [ Para
-          [ Strong
-              [ Str "Goal:"
-              , Space
-              , Str "Baseline"
-              , Space
-              , Str "and"
-              , Space
-              , Str "ongoing"
-              , Space
-              , Str "metrics"
-              , Space
-              , Str "tracking"
-              , Space
-              , Str "doc"
-              , Space
-              , Str "usefulness"
-              , Space
-              , Str "and"
-              , Space
-              , Str "completeness."
-              ]
-          ]
-      , Para [ Str "\160" ]
-      ]
   , OrderedList
       ( 2 , Decimal , Period )
-      [ [ Para [ Str "Content" , Space , Str "Migration" ] ] ]
-  , BlockQuote
-      [ Para
-          [ Str "Goal:"
-          , Space
-          , Str "Content"
-          , Space
-          , Str "is"
-          , Space
-          , Str "accessible"
-          , Space
-          , Str "to"
-          , Space
-          , Str "new"
-          , Space
-          , Str "employees"
-          , Space
-          , Str "and"
-          , Space
-          , Str "is"
-          , Space
-          , Str "better"
-          , Space
-          , Str "organized/archived."
-          ]
-      , Para [ Str "\160" ]
+      [ [ Para [ Str "Content" , Space , Str "Migration" ]
+        , Para
+            [ Str "Goal:"
+            , Space
+            , Str "Content"
+            , Space
+            , Str "is"
+            , Space
+            , Str "accessible"
+            , Space
+            , Str "to"
+            , Space
+            , Str "new"
+            , Space
+            , Str "employees"
+            , Space
+            , Str "and"
+            , Space
+            , Str "is"
+            , Space
+            , Str "better"
+            , Space
+            , Str "organized/archived."
+            ]
+        , Para [ Str "\160" ]
+        ]
       ]
   , OrderedList
       ( 3 , Decimal , Period )
-      [ [ Para [ Str "Wiki" , Space , Str "(xl)" ] ] ]
-  , BlockQuote
-      [ Para
-          [ Strong
-              [ Str "Goal:"
-              , Space
-              , Str "Useful"
-              , Space
-              , Str "documentation"
-              , Space
-              , Str "that"
-              , Space
-              , Str "is"
-              , Space
-              , Str "archived,"
-              , Space
-              , Str "searchable"
-              , Space
-              , Str "and"
-              , Space
-              , Str "easy"
-              , Space
-              , Str "to"
-              , Space
-              , Str "create"
-              ]
-          ]
-      , Para [ Str "\160\160" ]
+      [ [ Para [ Str "Wiki" , Space , Str "(xl)" ]
+        , Para
+            [ Strong
+                [ Str "Goal:"
+                , Space
+                , Str "Useful"
+                , Space
+                , Str "documentation"
+                , Space
+                , Str "that"
+                , Space
+                , Str "is"
+                , Space
+                , Str "archived,"
+                , Space
+                , Str "searchable"
+                , Space
+                , Str "and"
+                , Space
+                , Str "easy"
+                , Space
+                , Str "to"
+                , Space
+                , Str "create"
+                ]
+            ]
+        , Para [ Str "\160\160" ]
+        ]
       ]
   , OrderedList
       ( 4 , Decimal , Period )
@@ -178,89 +176,87 @@
             , Space
             , Str "(XLCRBot)."
             ]
+        , Para
+            [ Strong
+                [ Str "Goal:"
+                , Space
+                , Str "Feedback"
+                , Space
+                , Str "on"
+                , Space
+                , Str "basic"
+                , Space
+                , Str "violations"
+                , Space
+                , Str "in"
+                , Space
+                , Str "seconds"
+                , Space
+                , Str "or"
+                , Space
+                , Str "minutes"
+                , Space
+                , Str "at"
+                , Space
+                , Str "most"
+                , Space
+                , Str "in"
+                , Space
+                , Str "either"
+                , Space
+                , Str "VS"
+                , Space
+                , Str "or"
+                , Space
+                , Str "Codeflow."
+                ]
+            ]
         ]
       ]
-  , BlockQuote
-      [ Para
-          [ Strong
-              [ Str "Goal:"
-              , Space
-              , Str "Feedback"
-              , Space
-              , Str "on"
-              , Space
-              , Str "basic"
-              , Space
-              , Str "violations"
-              , Space
-              , Str "in"
-              , Space
-              , Str "seconds"
-              , Space
-              , Str "or"
-              , Space
-              , Str "minutes"
-              , Space
-              , Str "at"
-              , Space
-              , Str "most"
-              , Space
-              , Str "in"
-              , Space
-              , Str "either"
-              , Space
-              , Str "VS"
-              , Space
-              , Str "or"
-              , Space
-              , Str "Codeflow."
-              ]
-          ]
-      ]
   , OrderedList
       ( 5 , Decimal , Period )
-      [ [ Para [ Str "Code" , Space , Str "documentation" ] ] ]
-  , BlockQuote
-      [ Para
-          [ Strong
-              [ Str "Goal:"
-              , Space
-              , Str "Useful,"
-              , Space
-              , Str "consistent,"
-              , Space
-              , Str "tool"
-              , Space
-              , Str "supported"
-              , Space
-              , Str "comments"
-              ]
-          ]
+      [ [ Para [ Str "Code" , Space , Str "documentation" ]
+        , Para
+            [ Strong
+                [ Str "Goal:"
+                , Space
+                , Str "Useful,"
+                , Space
+                , Str "consistent,"
+                , Space
+                , Str "tool"
+                , Space
+                , Str "supported"
+                , Space
+                , Str "comments"
+                ]
+            ]
+        ]
       ]
   , Para [ Strong [ Str "\160" ] , Str "\160" ]
   , OrderedList
       ( 6 , Decimal , Period )
-      [ [ Para [ Str "Education" , Space , Str "efforts" ] ] ]
-  , BlockQuote
-      [ Para
-          [ Strong
-              [ Str "Goal:"
-              , Space
-              , Str "Broad,"
-              , Space
-              , Str "discoverable"
-              , Space
-              , Str "channels"
-              , Space
-              , Str "for"
-              , Space
-              , Str "updates"
-              , Space
-              , Str "and"
-              , Space
-              , Str "news"
-              ]
-          ]
+      [ [ Para [ Str "Education" , Space , Str "efforts" ]
+        , Para
+            [ Strong
+                [ Str "Goal:"
+                , Space
+                , Str "Broad,"
+                , Space
+                , Str "discoverable"
+                , Space
+                , Str "channels"
+                , Space
+                , Str "for"
+                , Space
+                , Str "updates"
+                , Space
+                , Str "and"
+                , Space
+                , Str "news"
+                ]
+            ]
+        ]
       ]
   , Para [ Strong [ Str "\160" ] ]
   ]
diff --git a/test/docx/lists_restart_8367.docx b/test/docx/lists_restart_8367.docx
Binary files a/test/docx/lists_restart_8367.docx and b/test/docx/lists_restart_8367.docx differ
diff --git a/test/docx/lists_restarting.docx b/test/docx/lists_restarting.docx
Binary files a/test/docx/lists_restarting.docx and b/test/docx/lists_restarting.docx differ
diff --git a/test/docx/lists_sublist_reset.docx b/test/docx/lists_sublist_reset.docx
Binary files a/test/docx/lists_sublist_reset.docx and b/test/docx/lists_sublist_reset.docx differ
diff --git a/test/docx/mendeley_citations.docx b/test/docx/mendeley_citations.docx
Binary files a/test/docx/mendeley_citations.docx and b/test/docx/mendeley_citations.docx differ
diff --git a/test/docx/metadata.docx b/test/docx/metadata.docx
Binary files a/test/docx/metadata.docx and b/test/docx/metadata.docx differ
diff --git a/test/docx/metadata_after_normal.docx b/test/docx/metadata_after_normal.docx
Binary files a/test/docx/metadata_after_normal.docx and b/test/docx/metadata_after_normal.docx differ
diff --git a/test/docx/nested_anchors_in_header.docx b/test/docx/nested_anchors_in_header.docx
Binary files a/test/docx/nested_anchors_in_header.docx and b/test/docx/nested_anchors_in_header.docx differ
diff --git a/test/docx/nested_instrText.docx b/test/docx/nested_instrText.docx
Binary files a/test/docx/nested_instrText.docx and b/test/docx/nested_instrText.docx differ
diff --git a/test/docx/nested_sdt.docx b/test/docx/nested_sdt.docx
Binary files a/test/docx/nested_sdt.docx and b/test/docx/nested_sdt.docx differ
diff --git a/test/docx/nested_smart_tags.docx b/test/docx/nested_smart_tags.docx
Binary files a/test/docx/nested_smart_tags.docx and b/test/docx/nested_smart_tags.docx differ
diff --git a/test/docx/normalize.docx b/test/docx/normalize.docx
Binary files a/test/docx/normalize.docx and b/test/docx/normalize.docx differ
diff --git a/test/docx/notes.docx b/test/docx/notes.docx
Binary files a/test/docx/notes.docx and b/test/docx/notes.docx differ
diff --git a/test/docx/numbered_header.docx b/test/docx/numbered_header.docx
Binary files a/test/docx/numbered_header.docx and b/test/docx/numbered_header.docx differ
diff --git a/test/docx/overlapping_targets.docx b/test/docx/overlapping_targets.docx
Binary files a/test/docx/overlapping_targets.docx and b/test/docx/overlapping_targets.docx differ
diff --git a/test/docx/pageref.docx b/test/docx/pageref.docx
Binary files a/test/docx/pageref.docx and b/test/docx/pageref.docx differ
diff --git a/test/docx/paragraph_insertion_deletion.docx b/test/docx/paragraph_insertion_deletion.docx
Binary files a/test/docx/paragraph_insertion_deletion.docx and b/test/docx/paragraph_insertion_deletion.docx differ
diff --git a/test/docx/relative_indentation_blockquotes.docx b/test/docx/relative_indentation_blockquotes.docx
Binary files a/test/docx/relative_indentation_blockquotes.docx and b/test/docx/relative_indentation_blockquotes.docx differ
diff --git a/test/docx/sdt_elements.docx b/test/docx/sdt_elements.docx
Binary files a/test/docx/sdt_elements.docx and b/test/docx/sdt_elements.docx differ
diff --git a/test/docx/sdt_elements.native b/test/docx/sdt_elements.native
--- a/test/docx/sdt_elements.native
+++ b/test/docx/sdt_elements.native
@@ -3,7 +3,7 @@
   [ Table
       ( "" , [] , [] )
       (Caption Nothing [])
-      [ ( AlignCenter , ColWidth 0.16167023554603854 )
+      [ ( AlignDefault , ColWidth 0.16167023554603854 )
       , ( AlignDefault , ColWidth 0.16167023554603854 )
       , ( AlignDefault , ColWidth 0.40920770877944324 )
       ]
diff --git a/test/docx/sdt_in_footnote.docx b/test/docx/sdt_in_footnote.docx
Binary files a/test/docx/sdt_in_footnote.docx and b/test/docx/sdt_in_footnote.docx differ
diff --git a/test/docx/special_punctuation.docx b/test/docx/special_punctuation.docx
Binary files a/test/docx/special_punctuation.docx and b/test/docx/special_punctuation.docx differ
diff --git a/test/docx/table_captions_no_field.docx b/test/docx/table_captions_no_field.docx
Binary files a/test/docx/table_captions_no_field.docx and b/test/docx/table_captions_no_field.docx differ
diff --git a/test/docx/table_captions_with_field.docx b/test/docx/table_captions_with_field.docx
Binary files a/test/docx/table_captions_with_field.docx and b/test/docx/table_captions_with_field.docx differ
diff --git a/test/docx/table_gridbefore.docx b/test/docx/table_gridbefore.docx
Binary files a/test/docx/table_gridbefore.docx and b/test/docx/table_gridbefore.docx differ
diff --git a/test/docx/table_header_rowspan.docx b/test/docx/table_header_rowspan.docx
Binary files a/test/docx/table_header_rowspan.docx and b/test/docx/table_header_rowspan.docx differ
diff --git a/test/docx/table_header_rowspan.native b/test/docx/table_header_rowspan.native
--- a/test/docx/table_header_rowspan.native
+++ b/test/docx/table_header_rowspan.native
@@ -3,7 +3,7 @@
   [ Table
       ( "" , [] , [] )
       (Caption Nothing [])
-      [ ( AlignDefault , ColWidth 0.30701754385964913 )
+      [ ( AlignLeft , ColWidth 0.30701754385964913 )
       , ( AlignDefault , ColWidth 0.13645224171539963 )
       , ( AlignDefault , ColWidth 0.10009746588693959 )
       , ( AlignDefault , ColWidth 9.707602339181289e-2 )
diff --git a/test/docx/table_one_header_row.docx b/test/docx/table_one_header_row.docx
Binary files a/test/docx/table_one_header_row.docx and b/test/docx/table_one_header_row.docx differ
diff --git a/test/docx/table_one_row.docx b/test/docx/table_one_row.docx
Binary files a/test/docx/table_one_row.docx and b/test/docx/table_one_row.docx differ
diff --git a/test/docx/table_variable_width.docx b/test/docx/table_variable_width.docx
Binary files a/test/docx/table_variable_width.docx and b/test/docx/table_variable_width.docx differ
diff --git a/test/docx/table_with_list_cell.docx b/test/docx/table_with_list_cell.docx
Binary files a/test/docx/table_with_list_cell.docx and b/test/docx/table_with_list_cell.docx differ
diff --git a/test/docx/tables.docx b/test/docx/tables.docx
Binary files a/test/docx/tables.docx and b/test/docx/tables.docx differ
diff --git a/test/docx/tabs.docx b/test/docx/tabs.docx
Binary files a/test/docx/tabs.docx and b/test/docx/tabs.docx differ
diff --git a/test/docx/task_list.docx b/test/docx/task_list.docx
Binary files a/test/docx/task_list.docx and b/test/docx/task_list.docx differ
diff --git a/test/docx/text_in_shape_format.docx b/test/docx/text_in_shape_format.docx
Binary files a/test/docx/text_in_shape_format.docx and b/test/docx/text_in_shape_format.docx differ
diff --git a/test/docx/textbox_image.docx b/test/docx/textbox_image.docx
Binary files a/test/docx/textbox_image.docx and b/test/docx/textbox_image.docx differ
diff --git a/test/docx/textbox_image_duplicate_encoding.docx b/test/docx/textbox_image_duplicate_encoding.docx
Binary files a/test/docx/textbox_image_duplicate_encoding.docx and b/test/docx/textbox_image_duplicate_encoding.docx differ
diff --git a/test/docx/track_changes_deletion.docx b/test/docx/track_changes_deletion.docx
Binary files a/test/docx/track_changes_deletion.docx and b/test/docx/track_changes_deletion.docx differ
diff --git a/test/docx/track_changes_edge_spaces.docx b/test/docx/track_changes_edge_spaces.docx
Binary files a/test/docx/track_changes_edge_spaces.docx and b/test/docx/track_changes_edge_spaces.docx differ
diff --git a/test/docx/track_changes_insertion.docx b/test/docx/track_changes_insertion.docx
Binary files a/test/docx/track_changes_insertion.docx and b/test/docx/track_changes_insertion.docx differ
diff --git a/test/docx/track_changes_move.docx b/test/docx/track_changes_move.docx
Binary files a/test/docx/track_changes_move.docx and b/test/docx/track_changes_move.docx differ
diff --git a/test/docx/track_changes_paragraph_mark_in_note.docx b/test/docx/track_changes_paragraph_mark_in_note.docx
new file mode 100644
Binary files /dev/null and b/test/docx/track_changes_paragraph_mark_in_note.docx differ
diff --git a/test/docx/track_changes_paragraph_mark_in_note_accept.native b/test/docx/track_changes_paragraph_mark_in_note_accept.native
new file mode 100644
--- /dev/null
+++ b/test/docx/track_changes_paragraph_mark_in_note_accept.native
@@ -0,0 +1,58 @@
+[ Para
+    [ Str "A"
+    , Space
+    , Str "note"
+    , Space
+    , Str "whose"
+    , Space
+    , Str "paragraph"
+    , Space
+    , Str "mark"
+    , Space
+    , Str "is"
+    , Space
+    , Str "deleted"
+    , Note [ Para [ Str "First" , Space , Str "note." ] ]
+    , Str "."
+    ]
+, Para
+    [ Str "A"
+    , Space
+    , Str "note"
+    , Space
+    , Str "whose"
+    , Space
+    , Str "paragraph"
+    , Space
+    , Str "mark"
+    , Space
+    , Str "is"
+    , Space
+    , Str "inserted"
+    , Note [ Para [ Str "Second" , Space , Str "note." ] ]
+    , Str "."
+    ]
+, Para
+    [ Str "A"
+    , Space
+    , Str "paragraph"
+    , Space
+    , Str "whose"
+    , Space
+    , Str "mark"
+    , Space
+    , Str "is"
+    , Space
+    , Str "deleted."
+    , Space
+    , Str "The"
+    , Space
+    , Str "paragraph"
+    , Space
+    , Str "it"
+    , Space
+    , Str "joins"
+    , Note [ Para [ Str "Third" , Space , Str "note." ] ]
+    , Str "."
+    ]
+]
diff --git a/test/docx/track_changes_paragraph_mark_in_note_reject.native b/test/docx/track_changes_paragraph_mark_in_note_reject.native
new file mode 100644
--- /dev/null
+++ b/test/docx/track_changes_paragraph_mark_in_note_reject.native
@@ -0,0 +1,59 @@
+[ Para
+    [ Str "A"
+    , Space
+    , Str "note"
+    , Space
+    , Str "whose"
+    , Space
+    , Str "paragraph"
+    , Space
+    , Str "mark"
+    , Space
+    , Str "is"
+    , Space
+    , Str "deleted"
+    , Note [ Para [ Str "First" , Space , Str "note." ] ]
+    , Str "."
+    ]
+, Para
+    [ Str "A"
+    , Space
+    , Str "note"
+    , Space
+    , Str "whose"
+    , Space
+    , Str "paragraph"
+    , Space
+    , Str "mark"
+    , Space
+    , Str "is"
+    , Space
+    , Str "inserted"
+    , Note [ Para [ Str "Second" , Space , Str "note." ] ]
+    , Str "."
+    ]
+, Para
+    [ Str "A"
+    , Space
+    , Str "paragraph"
+    , Space
+    , Str "whose"
+    , Space
+    , Str "mark"
+    , Space
+    , Str "is"
+    , Space
+    , Str "deleted."
+    ]
+, Para
+    [ Str "The"
+    , Space
+    , Str "paragraph"
+    , Space
+    , Str "it"
+    , Space
+    , Str "joins"
+    , Note [ Para [ Str "Third" , Space , Str "note." ] ]
+    , Str "."
+    ]
+]
diff --git a/test/docx/track_changes_scrubbed_metadata.docx b/test/docx/track_changes_scrubbed_metadata.docx
Binary files a/test/docx/track_changes_scrubbed_metadata.docx and b/test/docx/track_changes_scrubbed_metadata.docx differ
diff --git a/test/docx/trailing_spaces_in_formatting.docx b/test/docx/trailing_spaces_in_formatting.docx
Binary files a/test/docx/trailing_spaces_in_formatting.docx and b/test/docx/trailing_spaces_in_formatting.docx differ
diff --git a/test/docx/trim_last_inline.docx b/test/docx/trim_last_inline.docx
Binary files a/test/docx/trim_last_inline.docx and b/test/docx/trim_last_inline.docx differ
diff --git a/test/docx/unicode.docx b/test/docx/unicode.docx
Binary files a/test/docx/unicode.docx and b/test/docx/unicode.docx differ
diff --git a/test/docx/unused_anchors.docx b/test/docx/unused_anchors.docx
Binary files a/test/docx/unused_anchors.docx and b/test/docx/unused_anchors.docx differ
diff --git a/test/docx/verbatim_subsuper.docx b/test/docx/verbatim_subsuper.docx
Binary files a/test/docx/verbatim_subsuper.docx and b/test/docx/verbatim_subsuper.docx differ
diff --git a/test/docx/zotero_citations.docx b/test/docx/zotero_citations.docx
Binary files a/test/docx/zotero_citations.docx and b/test/docx/zotero_citations.docx differ
diff --git a/test/odt/fodt-native/styles-off.native b/test/odt/fodt-native/styles-off.native
new file mode 100644
--- /dev/null
+++ b/test/odt/fodt-native/styles-off.native
@@ -0,0 +1,88 @@
+[ Header
+    1
+    ( "plain-heading" , [] , [] )
+    [ Str "Plain" , Space , Str "Heading" ]
+, Header
+    1
+    ( "custom-title" , [] , [] )
+    [ Str "Custom" , Space , Str "Title" ]
+, Para [ Str "Standard" , Space , Str "paragraph." ]
+, Para [ Str "Body" , Space , Str "text." ]
+, Para
+    [ Strong
+        [ Str "Bold" , Space , Str "body" , Space , Str "text." ]
+    ]
+, Para
+    [ Emph
+        [ Str "A"
+        , Space
+        , Str "Bird"
+        , Space
+        , Str "came"
+        , Space
+        , Str "down"
+        , Space
+        , Str "the"
+        , Space
+        , Str "Walk"
+        ]
+    ]
+, Para
+    [ Str "Some"
+    , Space
+    , Str "keyword,"
+    , Space
+    , Emph [ Str "emphatic" ]
+    , Str ","
+    , Space
+    , Strong [ Str "bold" ]
+    , Space
+    , Str "and"
+    , Space
+    , Code ( "" , [] , [] ) "code"
+    , Space
+    , Str "text."
+    ]
+, Para
+    [ Str "An"
+    , Space
+    , Emph [ Str "emphasized" ]
+    , Space
+    , Str "word."
+    ]
+, CodeBlock ( "" , [] , [] ) "code line 1\ncode line 2"
+, OrderedList
+    ( 1 , DefaultStyle , DefaultDelim )
+    [ [ Plain [ Str "item" , Space , Str "one" ] ]
+    , [ Plain [ Str "item" , Space , Str "two" ] ]
+    ]
+, Table
+    ( "" , [] , [] )
+    (Caption Nothing [])
+    [ ( AlignDefault , ColWidthDefault )
+    , ( AlignDefault , ColWidthDefault )
+    ]
+    (TableHead ( "" , [] , [] ) [])
+    [ TableBody
+        ( "" , [] , [] )
+        (RowHeadColumns 0)
+        []
+        [ Row
+            ( "" , [] , [] )
+            [ Cell
+                ( "" , [] , [] )
+                AlignDefault
+                (RowSpan 1)
+                (ColSpan 1)
+                [ Plain [ Str "cell" ] ]
+            , Cell
+                ( "" , [] , [] )
+                AlignDefault
+                (RowSpan 1)
+                (ColSpan 1)
+                [ Plain [ Emph [ Str "poem" ] ] ]
+            ]
+        ]
+    ]
+    (TableFoot ( "" , [] , [] ) [])
+]
diff --git a/test/odt/fodt-native/styles.native b/test/odt/fodt-native/styles.native
new file mode 100644
--- /dev/null
+++ b/test/odt/fodt-native/styles.native
@@ -0,0 +1,117 @@
+[ Header
+    1
+    ( "plain-heading" , [] , [] )
+    [ Str "Plain" , Space , Str "Heading" ]
+, Header
+    1
+    ( "custom-title"
+    , []
+    , [ ( "custom-style" , "Chapter Title" ) ]
+    )
+    [ Str "Custom" , Space , Str "Title" ]
+, Para [ Str "Standard" , Space , Str "paragraph." ]
+, Div
+    ( "" , [] , [ ( "custom-style" , "Text body" ) ] )
+    [ Para [ Str "Body" , Space , Str "text." ] ]
+, Div
+    ( "" , [] , [ ( "custom-style" , "Text body" ) ] )
+    [ Para
+        [ Strong
+            [ Str "Bold" , Space , Str "body" , Space , Str "text." ]
+        ]
+    ]
+, Div
+    ( "" , [] , [ ( "custom-style" , "Poetry" ) ] )
+    [ Para
+        [ Str "A"
+        , Space
+        , Str "Bird"
+        , Space
+        , Str "came"
+        , Space
+        , Str "down"
+        , Space
+        , Str "the"
+        , Space
+        , Str "Walk"
+        ]
+    ]
+, Para
+    [ Str "Some"
+    , Space
+    , Span
+        ( "" , [] , [ ( "custom-style" , "Keyword" ) ] )
+        [ Str "keyword" ]
+    , Str ","
+    , Space
+    , Span
+        ( "" , [] , [ ( "custom-style" , "Emphatic(x)" ) ] )
+        [ Str "emphatic" ]
+    , Str ","
+    , Space
+    , Strong [ Str "bold" ]
+    , Space
+    , Str "and"
+    , Space
+    , Code ( "" , [] , [] ) "code"
+    , Space
+    , Str "text."
+    ]
+, Div
+    ( "" , [] , [ ( "custom-style" , "Undefined Style" ) ] )
+    [ Para
+        [ Str "An"
+        , Space
+        , Emph [ Str "emphasized" ]
+        , Space
+        , Str "word."
+        ]
+    ]
+, Div
+    ( "" , [] , [ ( "custom-style" , "Preformatted Text" ) ] )
+    [ CodeBlock ( "" , [] , [] ) "code line 1\ncode line 2" ]
+, OrderedList
+    ( 1 , DefaultStyle , DefaultDelim )
+    [ [ Plain [ Str "item" , Space , Str "one" ] ]
+    , [ Plain
+          [ Str "item"
+          , Space
+          , Span
+              ( "" , [] , [ ( "custom-style" , "Keyword" ) ] )
+              [ Str "two" ]
+          ]
+      ]
+    ]
+, Table
+    ( "" , [] , [] )
+    (Caption Nothing [])
+    [ ( AlignDefault , ColWidthDefault )
+    , ( AlignDefault , ColWidthDefault )
+    ]
+    (TableHead ( "" , [] , [] ) [])
+    [ TableBody
+        ( "" , [] , [] )
+        (RowHeadColumns 0)
+        []
+        [ Row
+            ( "" , [] , [] )
+            [ Cell
+                ( "" , [] , [] )
+                AlignDefault
+                (RowSpan 1)
+                (ColSpan 1)
+                [ Plain [ Str "cell" ] ]
+            , Cell
+                ( "" , [] , [] )
+                AlignDefault
+                (RowSpan 1)
+                (ColSpan 1)
+                [ Div
+                    ( "" , [] , [ ( "custom-style" , "Poetry" ) ] )
+                    [ Para [ Str "poem" ] ]
+                ]
+            ]
+        ]
+    ]
+    (TableFoot ( "" , [] , [] ) [])
+]
diff --git a/test/odt/fodt/styles.fodt b/test/odt/fodt/styles.fodt
new file mode 100644
--- /dev/null
+++ b/test/odt/fodt/styles.fodt
@@ -0,0 +1,64 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<office:document xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" office:version="1.3" office:mimetype="application/vnd.oasis.opendocument.text">
+ <office:styles>
+  <style:style style:name="Standard" style:family="paragraph" style:class="text"/>
+  <style:style style:name="Heading" style:family="paragraph" style:parent-style-name="Standard"/>
+  <style:style style:name="Heading_20_1" style:display-name="Heading 1" style:family="paragraph" style:parent-style-name="Heading"/>
+  <style:style style:name="Chapter_20_Title" style:display-name="Chapter Title" style:family="paragraph" style:parent-style-name="Heading"/>
+  <style:style style:name="Text_20_body" style:display-name="Text body" style:family="paragraph" style:parent-style-name="Standard"/>
+  <style:style style:name="Poetry" style:family="paragraph" style:parent-style-name="Standard">
+   <style:text-properties fo:font-style="italic"/>
+  </style:style>
+  <style:style style:name="Preformatted_20_Text" style:display-name="Preformatted Text" style:family="paragraph" style:parent-style-name="Standard"/>
+  <style:style style:name="Table_20_Contents" style:display-name="Table Contents" style:family="paragraph" style:parent-style-name="Standard"/>
+  <style:style style:name="Keyword" style:family="text"/>
+  <style:style style:name="Emphatic_28_x_29_" style:family="text">
+   <style:text-properties fo:font-style="italic"/>
+  </style:style>
+  <style:style style:name="Source_20_Text" style:display-name="Source Text" style:family="text"/>
+  <style:style style:name="Emphasis" style:family="text">
+   <style:text-properties fo:font-style="italic"/>
+  </style:style>
+ </office:styles>
+ <office:automatic-styles>
+  <style:style style:name="P1" style:family="paragraph" style:parent-style-name="Text_20_body">
+   <style:text-properties fo:font-weight="bold"/>
+  </style:style>
+  <style:style style:name="T1" style:family="text" style:parent-style-name="Keyword"/>
+  <style:style style:name="T2" style:family="text">
+   <style:text-properties fo:font-weight="bold"/>
+  </style:style>
+ </office:automatic-styles>
+ <office:body>
+  <office:text>
+   <text:h text:style-name="Heading_20_1" text:outline-level="1">Plain Heading</text:h>
+   <text:h text:style-name="Chapter_20_Title" text:outline-level="1">Custom Title</text:h>
+   <text:p text:style-name="Standard">Standard paragraph.</text:p>
+   <text:p text:style-name="Text_20_body">Body text.</text:p>
+   <text:p text:style-name="P1">Bold body text.</text:p>
+   <text:p text:style-name="Poetry">A Bird came down the Walk</text:p>
+   <text:p text:style-name="Standard">Some <text:span text:style-name="T1">keyword</text:span>, <text:span text:style-name="Emphatic_28_x_29_">emphatic</text:span>, <text:span text:style-name="T2">bold</text:span> and <text:span text:style-name="Source_20_Text">code</text:span> text.</text:p>
+   <text:p text:style-name="Undefined_20_Style">An <text:span text:style-name="Emphasis">emphasized</text:span> word.</text:p>
+   <text:p text:style-name="Preformatted_20_Text">code line 1</text:p>
+   <text:p text:style-name="Preformatted_20_Text">code line 2</text:p>
+   <text:list>
+    <text:list-item>
+     <text:p text:style-name="Text_20_body">item one</text:p>
+    </text:list-item>
+    <text:list-item>
+     <text:p text:style-name="Text_20_body">item <text:span text:style-name="Keyword">two</text:span></text:p>
+    </text:list-item>
+   </text:list>
+   <table:table>
+    <table:table-row>
+     <table:table-cell>
+      <text:p text:style-name="Table_20_Contents">cell</text:p>
+     </table:table-cell>
+     <table:table-cell>
+      <text:p text:style-name="Poetry">poem</text:p>
+     </table:table-cell>
+    </table:table-row>
+   </table:table>
+  </office:text>
+ </office:body>
+</office:document>
diff --git a/test/odt/native/listContinueNumbering3.native b/test/odt/native/listContinueNumbering3.native
new file mode 100644
--- /dev/null
+++ b/test/odt/native/listContinueNumbering3.native
@@ -0,0 +1,814 @@
+[ Para
+    [ Str "An" , Space , Str "example" , Space , Str "list" ]
+, Para []
+, OrderedList
+    ( 1 , Decimal , Period )
+    [ [ Plain
+          [ Str "This"
+          , Space
+          , Str "is"
+          , Space
+          , Str "a"
+          , Space
+          , Str "list,"
+          ]
+      ]
+    , [ Para [ Str "With" , Space , Str "numbers" ]
+      , OrderedList
+          ( 1 , LowerAlpha , Period )
+          [ [ Plain
+                [ Str "A"
+                , Space
+                , Str "sublist"
+                , Space
+                , Str "from"
+                , Space
+                , Str "word,"
+                , Space
+                , Str "starts"
+                , Space
+                , Str "with"
+                ]
+            ]
+          , [ Para [ Str "Alphabetic" , Space , Str "characters" ]
+            , OrderedList
+                ( 1 , LowerRoman , Period )
+                [ [ Plain
+                      [ Str "A"
+                      , Space
+                      , Str "sub-sub-list"
+                      , Space
+                      , Str "will"
+                      , Space
+                      , Str "be"
+                      ]
+                  ]
+                , [ Para
+                      [ Str "With"
+                      , Space
+                      , Str "lowercase"
+                      , Space
+                      , Str "roman"
+                      ]
+                  , OrderedList
+                      ( 1 , Decimal , Period )
+                      [ [ Plain
+                            [ Str "And"
+                            , Space
+                            , Str "here"
+                            , Space
+                            , Str "we"
+                            , Space
+                            , Str "are"
+                            , Space
+                            , Str "back"
+                            , Space
+                            , Str "with"
+                            , Space
+                            , Str "numbers"
+                            ]
+                        ]
+                      , [ Para
+                            [ Str "And"
+                            , Space
+                            , Str "another"
+                            , Space
+                            , Str "number"
+                            ]
+                        , OrderedList
+                            ( 1 , LowerAlpha , Period )
+                            [ [ Plain
+                                  [ Str "And"
+                                  , Space
+                                  , Str "back"
+                                  , Space
+                                  , Str "to"
+                                  , Space
+                                  , Str "lowercase"
+                                  , Space
+                                  , Str "alphabetical"
+                                  ]
+                              ]
+                            ]
+                        ]
+                      ]
+                  ]
+                ]
+            ]
+          ]
+      ]
+    , [ Plain
+          [ Str "BACK"
+          , Space
+          , Str "TO"
+          , Space
+          , Str "ORIGINAL"
+          , Space
+          , Str "LEVEL"
+          ]
+      ]
+    ]
+, Para []
+, Para
+    [ Str "Wow"
+    , Space
+    , Str "that"
+    , Space
+    , Str "was"
+    , Space
+    , Str "cool!"
+    , Space
+    , Str "AMAZING"
+    ]
+, Para []
+, OrderedList
+    ( 1 , UpperAlpha , Period )
+    [ [ Plain
+          [ Str "But"
+          , Space
+          , Str "we"
+          , Space
+          , Str "also"
+          , Space
+          , Str "have"
+          , Space
+          , Str "lists"
+          ]
+      ]
+    , [ Para
+          [ Str "With"
+          , Space
+          , Str "uppercase"
+          , Space
+          , Str "alphabet"
+          ]
+      , OrderedList
+          ( 1 , LowerAlpha , Period )
+          [ [ Plain
+                [ Str "And"
+                , Space
+                , Str "the"
+                , Space
+                , Str "sublist"
+                , Space
+                , Str "here"
+                , Space
+                , Str "again"
+                ]
+            ]
+          , [ Para
+                [ Str "Is"
+                , Space
+                , Str "lowercase"
+                , Space
+                , Str "alphabet"
+                ]
+            , OrderedList
+                ( 1 , LowerRoman , Period )
+                [ [ Plain
+                      [ Str "And"
+                      , Space
+                      , Str "lowercase"
+                      , Space
+                      , Str "roman"
+                      ]
+                  ]
+                ]
+            ]
+          ]
+      ]
+    , [ Plain
+          [ Str "BACK"
+          , Space
+          , Str "TO"
+          , Space
+          , Str "ORIGINAL"
+          , Space
+          , Str "LEVEL"
+          ]
+      ]
+    ]
+, Para []
+, Para
+    [ Str "And"
+    , Space
+    , Str "foremost,"
+    , Space
+    , Str "we"
+    , Space
+    , Str "have"
+    , Space
+    , Str "lists"
+    , Space
+    , Str "starting"
+    , Space
+    , Str "with"
+    , Space
+    , Str "uppercase"
+    , Space
+    , Str "roman."
+    ]
+, Para []
+, OrderedList
+    ( 1 , UpperRoman , Period )
+    [ [ Plain [ Str "Like" , Space , Str "this" ] ]
+    , [ Plain
+          [ Str "This"
+          , Space
+          , Str "list"
+          , Space
+          , Str "has"
+          , Space
+          , Str "uppercase"
+          , Space
+          , Str "roman"
+          ]
+      ]
+    , [ Para
+          [ Str "And"
+          , Space
+          , Str "that"
+          , Space
+          , Str "is"
+          , Space
+          , Str "very"
+          , Space
+          , Str "OK"
+          ]
+      , OrderedList
+          ( 1 , LowerAlpha , Period )
+          [ [ Para
+                [ Str "And"
+                , Space
+                , Str "again,"
+                , Space
+                , Str "the"
+                , Space
+                , Str "sublist"
+                , Space
+                , Str "starts"
+                , Space
+                , Str "with"
+                , Space
+                , Str "lowercase"
+                , Space
+                , Str "alphabet"
+                ]
+            , OrderedList
+                ( 1 , LowerRoman , Period )
+                [ [ Para
+                      [ Str "And"
+                      , Space
+                      , Str "a"
+                      , Space
+                      , Str "sub-sub-list"
+                      , Space
+                      , Str "with"
+                      , Space
+                      , Str "lowercase"
+                      , Space
+                      , Str "roman"
+                      ]
+                  , OrderedList
+                      ( 1 , Decimal , Period )
+                      [ [ Plain
+                            [ Str "But"
+                            , Space
+                            , Str "the"
+                            , Space
+                            , Str "sub-sub-sub-list"
+                            , Space
+                            , Str "starts"
+                            , Space
+                            , Str "with"
+                            , Space
+                            , Str "numbers"
+                            , Space
+                            , Str "here"
+                            ]
+                        ]
+                      ]
+                  ]
+                ]
+            ]
+          ]
+      ]
+    , [ Plain
+          [ Str "BACK"
+          , Space
+          , Str "TO"
+          , Space
+          , Str "ORIGINAL"
+          , Space
+          , Str "LEVEL"
+          ]
+      ]
+    ]
+, Para []
+, Para
+    [ Str "And"
+    , Space
+    , Str "a"
+    , Space
+    , Str "list"
+    , Space
+    , Str "in"
+    , Space
+    , Str "lowercase"
+    , Space
+    , Str "roman"
+    ]
+, Para []
+, OrderedList
+    ( 1 , LowerRoman , Period )
+    [ [ Para
+          [ Str "This"
+          , Space
+          , Str "is"
+          , Space
+          , Str "an"
+          , Space
+          , Str "example"
+          , Space
+          , Str "of"
+          , Space
+          , Str "that"
+          ]
+      , OrderedList
+          ( 1 , LowerAlpha , Period )
+          [ [ Para
+                [ Str "And"
+                , Space
+                , Str "this"
+                , Space
+                , Str "will"
+                , Space
+                , Str "be"
+                , Space
+                , Str "lowercase"
+                , Space
+                , Str "alphabetic"
+                ]
+            , OrderedList
+                ( 1 , LowerRoman , Period )
+                [ [ Para
+                      [ Str "And"
+                      , Space
+                      , Str "lowercase"
+                      , Space
+                      , Str "roman??"
+                      ]
+                  , OrderedList
+                      ( 1 , Decimal , Period )
+                      [ [ Plain [ Str "And" , Space , Str "numeric" ] ]
+                      ]
+                  ]
+                ]
+            ]
+          ]
+      ]
+    , [ Plain
+          [ Str "BACK"
+          , Space
+          , Str "TO"
+          , Space
+          , Str "ORIGINAL"
+          , Space
+          , Str "LEVEL"
+          ]
+      ]
+    ]
+, Para []
+, Para
+    [ Str "And"
+    , Space
+    , Str "an"
+    , Space
+    , Str "odd"
+    , Space
+    , Str "list,"
+    , Space
+    , Str "using"
+    , Space
+    , Str "1),"
+    , Space
+    , Str "2),"
+    , Space
+    , Str "etc:"
+    ]
+, Para []
+, OrderedList
+    ( 1 , Decimal , OneParen )
+    [ [ Para [ Str "Hello" , Space , Str "there" ]
+      , OrderedList
+          ( 1 , LowerAlpha , Period )
+          [ [ Para
+                [ Str "This"
+                , Space
+                , Str "is"
+                , Space
+                , Str "a"
+                , Space
+                , Str "sublist"
+                , Space
+                , Str "(lowercase"
+                , Space
+                , Str "alphabetic)"
+                ]
+            , OrderedList
+                ( 1 , LowerRoman , Period )
+                [ [ Para
+                      [ Str "Sub-sub-list"
+                      , Space
+                      , Str "(lowercase"
+                      , Space
+                      , Str "roman)"
+                      ]
+                  , OrderedList
+                      ( 1 , Decimal , Period )
+                      [ [ Plain
+                            [ Str "Numeric,"
+                            , Space
+                            , Str "but"
+                            , Space
+                            , Str "without"
+                            , Space
+                            , Str "the"
+                            , Space
+                            , Str ")"
+                            , Space
+                            , Str "but"
+                            , Space
+                            , Str "with"
+                            , Space
+                            , Str "the"
+                            , Space
+                            , Str "."
+                            ]
+                        ]
+                      ]
+                  ]
+                , [ Plain [ Str "Lower" , Space , Str "level" ] ]
+                ]
+            ]
+          , [ Plain [ Str "Lower" , Space , Str "level" ] ]
+          ]
+      ]
+    , [ Plain
+          [ Str "BACK"
+          , Space
+          , Str "TO"
+          , Space
+          , Str "ORIGINAL"
+          , Space
+          , Str "LEVEL"
+          ]
+      ]
+    ]
+, Para []
+, Para
+    [ Str "Some"
+    , Space
+    , Str "list"
+    , Space
+    , Str "do"
+    , Space
+    , Str "the"
+    , Space
+    , Str "same"
+    , Space
+    , Str "but"
+    , Space
+    , Str "with"
+    , Space
+    , Str "alphabetic:"
+    , Space
+    , Str "a),"
+    , Space
+    , Str "b),"
+    , Space
+    , Str "etc."
+    ]
+, Para []
+, OrderedList
+    ( 1 , LowerAlpha , OneParen )
+    [ [ Para [ Str "Hello" , Space , Str "there" ]
+      , OrderedList
+          ( 1 , LowerAlpha , Period )
+          [ [ Para
+                [ Str "Sub-list,"
+                , Space
+                , Str "normal"
+                , Space
+                , Str "alphabetic"
+                , Space
+                , Str "with"
+                , Space
+                , Str "dot"
+                ]
+            , OrderedList
+                ( 1 , LowerRoman , Period )
+                [ [ Plain
+                      [ Str "Sub-sub-list,"
+                      , Space
+                      , Str "lowercase"
+                      , Space
+                      , Str "roman"
+                      , Space
+                      , Str "again!"
+                      ]
+                  ]
+                ]
+            ]
+          ]
+      ]
+    , [ Plain
+          [ Str "BACK"
+          , Space
+          , Str "TO"
+          , Space
+          , Str "THE"
+          , Space
+          , Str "ORIGINAL"
+          ]
+      ]
+    ]
+, Para []
+, Para
+    [ Str "We"
+    , Space
+    , Str "also"
+    , Space
+    , Str "can"
+    , Space
+    , Str "have"
+    , Space
+    , Str "list"
+    , Space
+    , Str "functioning"
+    , Space
+    , Str "with"
+    , Space
+    , Str "1.,"
+    , Space
+    , Str "1.1.,"
+    , Space
+    , Str "1.1.1,"
+    , Space
+    , Str "etc."
+    ]
+, Para []
+, OrderedList
+    ( 1 , Decimal , Period )
+    [ [ Para
+          [ Str "This"
+          , Space
+          , Str "is"
+          , Space
+          , Str "an"
+          , Space
+          , Str "example"
+          , Space
+          , Str "of"
+          , Space
+          , Str "that"
+          ]
+      , OrderedList
+          ( 1 , Decimal , Period )
+          [ [ Plain
+                [ Str "This"
+                , Space
+                , Str "is"
+                , Space
+                , Str "the"
+                , Space
+                , Str "1.1"
+                ]
+            ]
+          , [ Para
+                [ Str "And"
+                , Space
+                , Str "this"
+                , Space
+                , Str "is"
+                , Space
+                , Str "the"
+                , Space
+                , Str "1.2."
+                ]
+            , OrderedList
+                ( 1 , Decimal , Period )
+                [ [ Para
+                      [ Str "And"
+                      , Space
+                      , Str "this"
+                      , Space
+                      , Str "is"
+                      , Space
+                      , Str "a"
+                      , Space
+                      , Str "1.2.1."
+                      ]
+                  , OrderedList
+                      ( 1 , Decimal , Period )
+                      [ [ Plain
+                            [ Str "And"
+                            , Space
+                            , Str "so"
+                            , Space
+                            , Str "forth,"
+                            , Space
+                            , Str "this"
+                            , Space
+                            , Str "will"
+                            , Space
+                            , Str "be"
+                            , Space
+                            , Str "a"
+                            , Space
+                            , Str "1.2.1.1"
+                            ]
+                        ]
+                      ]
+                  ]
+                ]
+            ]
+          ]
+      ]
+    , [ Plain
+          [ Str "Back"
+          , Space
+          , Str "to"
+          , Space
+          , Str "the"
+          , Space
+          , Str "original"
+          , Space
+          , Str "leven"
+          , Space
+          , Str "(2.)"
+          ]
+      ]
+    ]
+, Para []
+, Para
+    [ Str "Some"
+    , Space
+    , Str "other"
+    , Space
+    , Str "interesting"
+    , Space
+    , Str "list"
+    , Space
+    , Str "as"
+    , Space
+    , Str "follows,"
+    , Space
+    , Str "these"
+    , Space
+    , Str "are"
+    , Space
+    , Str "headings,"
+    , Space
+    , Str "but"
+    , Space
+    , Str "not"
+    , Space
+    , Str "really"
+    , Space
+    , Str "lists,"
+    , Space
+    , Str "but"
+    , Space
+    , Str "Microsoft"
+    , Space
+    , Str "Word"
+    , Space
+    , Str "pretends"
+    , Space
+    , Str "they"
+    , Space
+    , Str "are.."
+    ]
+, Para []
+, Header
+    1
+    ( "it-seems-like-this-list-has-headings-1." , [] , [] )
+    [ Str "It"
+    , Space
+    , Str "seems"
+    , Space
+    , Str "like"
+    , Space
+    , Str "this"
+    , Space
+    , Str "list"
+    , Space
+    , Str "has"
+    , Space
+    , Str "headings??"
+    , Space
+    , Str "(1.)"
+    ]
+, Para []
+, Header
+    2
+    ( "i-wonder-how-this-is-converted-1.1" , [] , [] )
+    [ Str "I"
+    , Space
+    , Str "wonder"
+    , Space
+    , Str "how"
+    , Space
+    , Str "this"
+    , Space
+    , Str "is"
+    , Space
+    , Str "converted"
+    , Space
+    , Str "(1.1)"
+    ]
+, Para []
+, Para []
+, Para [ Strong [ Str "And" , Space , Str "finally:" ] ]
+, Para []
+, Para
+    [ Str "We"
+    , Space
+    , Str "can"
+    , Space
+    , Str "also"
+    , Space
+    , Str "have"
+    , Space
+    , Str "lists"
+    , Space
+    , Str "with"
+    , Space
+    , Str "text"
+    , Space
+    , Str "in"
+    , Space
+    , Str "between."
+    , Space
+    ]
+, Para []
+, Para
+    [ Str "Things"
+    , Space
+    , Str "in"
+    , Space
+    , Str "life"
+    , Space
+    , Str "I"
+    , Space
+    , Str "like:"
+    ]
+, Para []
+, OrderedList
+    ( 1 , Decimal , Period ) [ [ Plain [ Str "Cookies" ] ] ]
+, Para []
+, Para
+    [ Str "Cookies"
+    , Space
+    , Str "are"
+    , Space
+    , Str "just"
+    , Space
+    , Str "delicious"
+    ]
+, Para []
+, OrderedList
+    ( 2 , Decimal , Period ) [ [ Plain [ Str "Alcohol" ] ] ]
+, Para []
+, Para
+    [ Str "It\8217s"
+    , Space
+    , Str "really"
+    , Space
+    , Str "nice."
+    ]
+, Para []
+, OrderedList
+    ( 3 , Decimal , Period ) [ [ Plain [ Str "CENSORED" ] ] ]
+, Para []
+, Para
+    [ Str "Yeah"
+    , Space
+    , Str "we"
+    , Space
+    , Str "all"
+    , Space
+    , Str "know"
+    , Space
+    , Str "what"
+    , Space
+    , Str "I"
+    , Space
+    , Str "mean"
+    , Space
+    , Str "by"
+    , Space
+    , Str "that."
+    ]
+]
diff --git a/test/odt/odt/blockquote.odt b/test/odt/odt/blockquote.odt
Binary files a/test/odt/odt/blockquote.odt and b/test/odt/odt/blockquote.odt differ
diff --git a/test/odt/odt/blockquote2.odt b/test/odt/odt/blockquote2.odt
Binary files a/test/odt/odt/blockquote2.odt and b/test/odt/odt/blockquote2.odt differ
diff --git a/test/odt/odt/bold.odt b/test/odt/odt/bold.odt
Binary files a/test/odt/odt/bold.odt and b/test/odt/odt/bold.odt differ
diff --git a/test/odt/odt/citation.odt b/test/odt/odt/citation.odt
Binary files a/test/odt/odt/citation.odt and b/test/odt/odt/citation.odt differ
diff --git a/test/odt/odt/endnote.odt b/test/odt/odt/endnote.odt
Binary files a/test/odt/odt/endnote.odt and b/test/odt/odt/endnote.odt differ
diff --git a/test/odt/odt/expression.odt b/test/odt/odt/expression.odt
Binary files a/test/odt/odt/expression.odt and b/test/odt/odt/expression.odt differ
diff --git a/test/odt/odt/expressionUnevaluated.odt b/test/odt/odt/expressionUnevaluated.odt
Binary files a/test/odt/odt/expressionUnevaluated.odt and b/test/odt/odt/expressionUnevaluated.odt differ
diff --git a/test/odt/odt/externalLink.odt b/test/odt/odt/externalLink.odt
Binary files a/test/odt/odt/externalLink.odt and b/test/odt/odt/externalLink.odt differ
diff --git a/test/odt/odt/footnote.odt b/test/odt/odt/footnote.odt
Binary files a/test/odt/odt/footnote.odt and b/test/odt/odt/footnote.odt differ
diff --git a/test/odt/odt/formula.odt b/test/odt/odt/formula.odt
Binary files a/test/odt/odt/formula.odt and b/test/odt/odt/formula.odt differ
diff --git a/test/odt/odt/headers.odt b/test/odt/odt/headers.odt
Binary files a/test/odt/odt/headers.odt and b/test/odt/odt/headers.odt differ
diff --git a/test/odt/odt/hiddenTextByStyle.odt b/test/odt/odt/hiddenTextByStyle.odt
Binary files a/test/odt/odt/hiddenTextByStyle.odt and b/test/odt/odt/hiddenTextByStyle.odt differ
diff --git a/test/odt/odt/hiddenTextByVariable.odt b/test/odt/odt/hiddenTextByVariable.odt
Binary files a/test/odt/odt/hiddenTextByVariable.odt and b/test/odt/odt/hiddenTextByVariable.odt differ
diff --git a/test/odt/odt/horizontalRule.odt b/test/odt/odt/horizontalRule.odt
Binary files a/test/odt/odt/horizontalRule.odt and b/test/odt/odt/horizontalRule.odt differ
diff --git a/test/odt/odt/image.odt b/test/odt/odt/image.odt
Binary files a/test/odt/odt/image.odt and b/test/odt/odt/image.odt differ
diff --git a/test/odt/odt/imageIndex.odt b/test/odt/odt/imageIndex.odt
Binary files a/test/odt/odt/imageIndex.odt and b/test/odt/odt/imageIndex.odt differ
diff --git a/test/odt/odt/imageRelative.odt b/test/odt/odt/imageRelative.odt
Binary files a/test/odt/odt/imageRelative.odt and b/test/odt/odt/imageRelative.odt differ
diff --git a/test/odt/odt/imageWithCaption.odt b/test/odt/odt/imageWithCaption.odt
Binary files a/test/odt/odt/imageWithCaption.odt and b/test/odt/odt/imageWithCaption.odt differ
diff --git a/test/odt/odt/inlinedCode.odt b/test/odt/odt/inlinedCode.odt
Binary files a/test/odt/odt/inlinedCode.odt and b/test/odt/odt/inlinedCode.odt differ
diff --git a/test/odt/odt/italic.odt b/test/odt/odt/italic.odt
Binary files a/test/odt/odt/italic.odt and b/test/odt/odt/italic.odt differ
diff --git a/test/odt/odt/listBlocks.odt b/test/odt/odt/listBlocks.odt
Binary files a/test/odt/odt/listBlocks.odt and b/test/odt/odt/listBlocks.odt differ
diff --git a/test/odt/odt/listContinueNumbering.odt b/test/odt/odt/listContinueNumbering.odt
Binary files a/test/odt/odt/listContinueNumbering.odt and b/test/odt/odt/listContinueNumbering.odt differ
diff --git a/test/odt/odt/listContinueNumbering2.odt b/test/odt/odt/listContinueNumbering2.odt
Binary files a/test/odt/odt/listContinueNumbering2.odt and b/test/odt/odt/listContinueNumbering2.odt differ
diff --git a/test/odt/odt/listContinueNumbering3.odt b/test/odt/odt/listContinueNumbering3.odt
new file mode 100644
Binary files /dev/null and b/test/odt/odt/listContinueNumbering3.odt differ
diff --git a/test/odt/odt/orderedListHeader.odt b/test/odt/odt/orderedListHeader.odt
Binary files a/test/odt/odt/orderedListHeader.odt and b/test/odt/odt/orderedListHeader.odt differ
diff --git a/test/odt/odt/orderedListMixed.odt b/test/odt/odt/orderedListMixed.odt
Binary files a/test/odt/odt/orderedListMixed.odt and b/test/odt/odt/orderedListMixed.odt differ
diff --git a/test/odt/odt/orderedListRoman.odt b/test/odt/odt/orderedListRoman.odt
Binary files a/test/odt/odt/orderedListRoman.odt and b/test/odt/odt/orderedListRoman.odt differ
diff --git a/test/odt/odt/orderedListSimple.odt b/test/odt/odt/orderedListSimple.odt
Binary files a/test/odt/odt/orderedListSimple.odt and b/test/odt/odt/orderedListSimple.odt differ
diff --git a/test/odt/odt/paragraph.odt b/test/odt/odt/paragraph.odt
Binary files a/test/odt/odt/paragraph.odt and b/test/odt/odt/paragraph.odt differ
diff --git a/test/odt/odt/preformattedText.odt b/test/odt/odt/preformattedText.odt
Binary files a/test/odt/odt/preformattedText.odt and b/test/odt/odt/preformattedText.odt differ
diff --git a/test/odt/odt/preformattedTextParentStyle.odt b/test/odt/odt/preformattedTextParentStyle.odt
Binary files a/test/odt/odt/preformattedTextParentStyle.odt and b/test/odt/odt/preformattedTextParentStyle.odt differ
diff --git a/test/odt/odt/referenceAllInOne.odt b/test/odt/odt/referenceAllInOne.odt
Binary files a/test/odt/odt/referenceAllInOne.odt and b/test/odt/odt/referenceAllInOne.odt differ
diff --git a/test/odt/odt/referenceToChapter.odt b/test/odt/odt/referenceToChapter.odt
Binary files a/test/odt/odt/referenceToChapter.odt and b/test/odt/odt/referenceToChapter.odt differ
diff --git a/test/odt/odt/referenceToListItem.odt b/test/odt/odt/referenceToListItem.odt
Binary files a/test/odt/odt/referenceToListItem.odt and b/test/odt/odt/referenceToListItem.odt differ
diff --git a/test/odt/odt/referenceToText.odt b/test/odt/odt/referenceToText.odt
Binary files a/test/odt/odt/referenceToText.odt and b/test/odt/odt/referenceToText.odt differ
diff --git a/test/odt/odt/simpleTable.odt b/test/odt/odt/simpleTable.odt
Binary files a/test/odt/odt/simpleTable.odt and b/test/odt/odt/simpleTable.odt differ
diff --git a/test/odt/odt/simpleTableWithCaption.odt b/test/odt/odt/simpleTableWithCaption.odt
Binary files a/test/odt/odt/simpleTableWithCaption.odt and b/test/odt/odt/simpleTableWithCaption.odt differ
diff --git a/test/odt/odt/simpleTableWithHeader.odt b/test/odt/odt/simpleTableWithHeader.odt
Binary files a/test/odt/odt/simpleTableWithHeader.odt and b/test/odt/odt/simpleTableWithHeader.odt differ
diff --git a/test/odt/odt/simpleTableWithMultipleHeaderRows.odt b/test/odt/odt/simpleTableWithMultipleHeaderRows.odt
Binary files a/test/odt/odt/simpleTableWithMultipleHeaderRows.odt and b/test/odt/odt/simpleTableWithMultipleHeaderRows.odt differ
diff --git a/test/odt/odt/sourceText.odt b/test/odt/odt/sourceText.odt
Binary files a/test/odt/odt/sourceText.odt and b/test/odt/odt/sourceText.odt differ
diff --git a/test/odt/odt/strikeout.odt b/test/odt/odt/strikeout.odt
Binary files a/test/odt/odt/strikeout.odt and b/test/odt/odt/strikeout.odt differ
diff --git a/test/odt/odt/tab.odt b/test/odt/odt/tab.odt
Binary files a/test/odt/odt/tab.odt and b/test/odt/odt/tab.odt differ
diff --git a/test/odt/odt/table.odt b/test/odt/odt/table.odt
Binary files a/test/odt/odt/table.odt and b/test/odt/odt/table.odt differ
diff --git a/test/odt/odt/tableWithCaption.odt b/test/odt/odt/tableWithCaption.odt
Binary files a/test/odt/odt/tableWithCaption.odt and b/test/odt/odt/tableWithCaption.odt differ
diff --git a/test/odt/odt/tableWithContents.odt b/test/odt/odt/tableWithContents.odt
Binary files a/test/odt/odt/tableWithContents.odt and b/test/odt/odt/tableWithContents.odt differ
diff --git a/test/odt/odt/tableWithSpans.odt b/test/odt/odt/tableWithSpans.odt
Binary files a/test/odt/odt/tableWithSpans.odt and b/test/odt/odt/tableWithSpans.odt differ
diff --git a/test/odt/odt/textMixedStyles.odt b/test/odt/odt/textMixedStyles.odt
Binary files a/test/odt/odt/textMixedStyles.odt and b/test/odt/odt/textMixedStyles.odt differ
diff --git a/test/odt/odt/trackedChanges.odt b/test/odt/odt/trackedChanges.odt
Binary files a/test/odt/odt/trackedChanges.odt and b/test/odt/odt/trackedChanges.odt differ
diff --git a/test/odt/odt/underlined.odt b/test/odt/odt/underlined.odt
Binary files a/test/odt/odt/underlined.odt and b/test/odt/odt/underlined.odt differ
diff --git a/test/odt/odt/unicode.odt b/test/odt/odt/unicode.odt
Binary files a/test/odt/odt/unicode.odt and b/test/odt/odt/unicode.odt differ
diff --git a/test/odt/odt/unorderedList.odt b/test/odt/odt/unorderedList.odt
Binary files a/test/odt/odt/unorderedList.odt and b/test/odt/odt/unorderedList.odt differ
diff --git a/test/odt/odt/unorderedListHeader.odt b/test/odt/odt/unorderedListHeader.odt
Binary files a/test/odt/odt/unorderedListHeader.odt and b/test/odt/odt/unorderedListHeader.odt differ
diff --git a/test/odt/odt/variable.odt b/test/odt/odt/variable.odt
Binary files a/test/odt/odt/variable.odt and b/test/odt/odt/variable.odt differ
diff --git a/test/pptx-reader/basic.native b/test/pptx-reader/basic.native
--- a/test/pptx-reader/basic.native
+++ b/test/pptx-reader/basic.native
@@ -1,149 +1,260 @@
-[ Header 2 ( "slide-1" , [] , [] ) [ Str "LLMs" ]
-, BulletList
-    [ [ Plain
-          [ Str
-              "Provider  \61664 Available LLMs \8211 who manages? How?"
+Pandoc
+  Meta { unMeta = fromList [] }
+  [ Header 2 ( "slide-1" , [] , [] ) [ Str "LLMs" ]
+  , BulletList
+      [ [ Plain
+            [ Str "Provider"
+            , Space
+            , Str "\61664"
+            , Space
+            , Str "Available"
+            , Space
+            , Str "LLMs"
+            , Space
+            , Str "\8211"
+            , Space
+            , Str "who"
+            , Space
+            , Str "manages?"
+            , Space
+            , Str "How?"
+            ]
+        ]
+      , [ Plain
+            [ Str "EW"
+            , Space
+            , Str "maintained"
+            , Space
+            , Str "list"
+            , Space
+            , Str "of"
+            , Space
+            , Str "\8220approved\8221"
+            , Space
+            , Str "LLMs"
+            , Space
+            , Str "for"
+            , Space
+            , Str "Universal"
+            , Space
+            , Str "workers"
+            ]
+        ]
+      , [ Plain
+            [ Str "Rebuilding"
+            , Space
+            , Str "of"
+            , Space
+            , Str "UWs"
+            , Space
+            , Str "to"
+            , Space
+            , Str "the"
+            , Space
+            , Str "\8220Newgen\8221"
+            , Space
+            , Str "thing"
+            , Space
+            , Str "completely"
+            ]
+        ]
+      , [ Plain [ Str "Streaming" , Space , Str "support" ] ]
+      , [ Plain
+            [ Str "Multimodal"
+            , Space
+            , Str "(voice"
+            , Space
+            , Str "streaming)"
+            , Space
+            , Str "models?"
+            ]
+        ]
+      ]
+  , Header
+      2
+      ( "slide-2" , [] , [] )
+      [ Str "Everworker"
+      , Space
+      , Str "venn"
+      , Space
+      , Str "diagram"
+      ]
+  , Para [ Strong [ Str "SKILLS" ] ]
+  , Para []
+  , Para
+      [ Strong
+          [ Str "Specialized"
+          , Space
+          , Str "Workers"
+          , Space
+          , Str "/"
+          , Space
+          , Str "Workflows:"
           ]
       ]
-    , [ Plain
-          [ Str
-              "EW maintained list of \8220approved\8221 LLMs for Universal workers"
+  , Para []
+  , Para
+      [ Str "n8n,"
+      , Space
+      , Str "UI"
+      , Space
+      , Str "Path,"
+      , Space
+      ]
+  , Para [ Str "other" , Space , Str "RPA" ]
+  , Para [ Strong [ Str "BRAINS" ] ]
+  , Para []
+  , Para
+      [ Strong
+          [ Str "Universal"
+          , Space
+          , Str "Workers"
+          , Space
+          , Str "/"
+          , Space
+          , Str "AI"
+          , Space
+          , Str "Agents:"
           ]
       ]
-    , [ Plain
-          [ Str
-              "Rebuilding of UWs to the \8220Newgen\8221 thing completely"
+  , Para []
+  , Para [ Str "openai," , Space , Str "anthropic," ]
+  , Para
+      [ Str "Crew"
+      , Space
+      , Str "AI,"
+      , Space
+      , Str "other"
+      , Space
+      ]
+  , Para [ Str "\8220AI" , Space , Str "natives\8221" ]
+  , Para [ Strong [ Str "KNOWLEDGE" ] , Space ]
+  , Para []
+  , Para [ Strong [ Str "Data" , Space , Str "/" ] , Space ]
+  , Para [ Strong [ Str "RAG" , Space , Str "Pipelines" ] ]
+  , Para []
+  , Para
+      [ Str "Vector"
+      , Space
+      , Str "DBs,"
+      , Space
+      , Str "specialized"
+      , Space
+      , Str "data"
+      , Space
+      , Str "prep"
+      , Space
+      , Str "vendors,"
+      , Space
+      , Str "\8230"
+      ]
+  , Para [ Str "glean" ]
+  , Para [ Strong [ Str "EW" ] ]
+  , Header 2 ( "slide-3" , [] , [] ) [ Str "Table" ]
+  , Table
+      ( "" , [] , [] )
+      (Caption Nothing [])
+      [ ( AlignDefault , ColWidthDefault )
+      , ( AlignDefault , ColWidthDefault )
+      , ( AlignDefault , ColWidthDefault )
+      ]
+      (TableHead
+         ( "" , [] , [] )
+         [ Row
+             ( "" , [] , [] )
+             [ Cell
+                 ( "" , [] , [] )
+                 AlignDefault
+                 (RowSpan 1)
+                 (ColSpan 1)
+                 [ Plain [ Str "Col1" ] ]
+             , Cell
+                 ( "" , [] , [] )
+                 AlignDefault
+                 (RowSpan 1)
+                 (ColSpan 1)
+                 [ Plain [ Str "Col2" ] ]
+             , Cell
+                 ( "" , [] , [] )
+                 AlignDefault
+                 (RowSpan 1)
+                 (ColSpan 1)
+                 [ Plain [ Str "Col3" ] ]
+             ]
+         ])
+      [ TableBody
+          ( "" , [] , [] )
+          (RowHeadColumns 0)
+          []
+          [ Row
+              ( "" , [] , [] )
+              [ Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "Name" ] ]
+              , Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "Anton" ] ]
+              , Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "Antich" ] ]
+              ]
+          , Row
+              ( "" , [] , [] )
+              [ Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "Age" ] ]
+              , Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "23" ] ]
+              , Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "years" ] ]
+              ]
           ]
       ]
-    , [ Plain [ Str "Streaming support" ] ]
-    , [ Plain [ Str "Multimodal (voice streaming) models?" ] ]
-    ]
-, Header
-    2
-    ( "slide-2" , [] , [] )
-    [ Str "Everworker   venn   diagram" ]
-, Para [ Str "SKILLS" ]
-, Para [ Str "" ]
-, Para [ Str "Specialized Workers / Workflows:" ]
-, Para [ Str "" ]
-, Para [ Str "n8n, UI Path, " ]
-, Para [ Str "other RPA" ]
-, Para [ Str "BRAINS" ]
-, Para [ Str "" ]
-, Para [ Str "Universal Workers / AI Agents:" ]
-, Para [ Str "" ]
-, Para [ Str "openai , anthropic," ]
-, Para [ Str "Crew AI, other " ]
-, Para [ Str "\8220AI natives\8221" ]
-, Para [ Str "KNOWLEDGE " ]
-, Para [ Str "" ]
-, Para [ Str "Data / " ]
-, Para [ Str "RAG Pipelines" ]
-, Para [ Str "" ]
-, Para
-    [ Str "Vector DBs, specialized data prep vendors, \8230" ]
-, Para [ Str "glean" ]
-, Para [ Str "EW" ]
-, Header 2 ( "slide-3" , [] , [] ) [ Str "Table" ]
-, Table
-    ( "" , [] , [] )
-    (Caption Nothing [])
-    [ ( AlignDefault , ColWidthDefault )
-    , ( AlignDefault , ColWidthDefault )
-    , ( AlignDefault , ColWidthDefault )
-    ]
-    (TableHead
-       ( "" , [] , [] )
-       [ Row
-           ( "" , [] , [] )
-           [ Cell
-               ( "" , [] , [] )
-               AlignDefault
-               (RowSpan 1)
-               (ColSpan 1)
-               [ Plain [ Str "Col1" ] ]
-           , Cell
-               ( "" , [] , [] )
-               AlignDefault
-               (RowSpan 1)
-               (ColSpan 1)
-               [ Plain [ Str "Col2" ] ]
-           , Cell
-               ( "" , [] , [] )
-               AlignDefault
-               (RowSpan 1)
-               (ColSpan 1)
-               [ Plain [ Str "Col3" ] ]
-           ]
-       ])
-    [ TableBody
-        ( "" , [] , [] )
-        (RowHeadColumns 0)
-        []
-        [ Row
-            ( "" , [] , [] )
-            [ Cell
-                ( "" , [] , [] )
-                AlignDefault
-                (RowSpan 1)
-                (ColSpan 1)
-                [ Plain [ Str "Name" ] ]
-            , Cell
-                ( "" , [] , [] )
-                AlignDefault
-                (RowSpan 1)
-                (ColSpan 1)
-                [ Plain [ Str "Anton" ] ]
-            , Cell
-                ( "" , [] , [] )
-                AlignDefault
-                (RowSpan 1)
-                (ColSpan 1)
-                [ Plain [ Str "Antich" ] ]
-            ]
-        , Row
-            ( "" , [] , [] )
-            [ Cell
-                ( "" , [] , [] )
-                AlignDefault
-                (RowSpan 1)
-                (ColSpan 1)
-                [ Plain [ Str "Age" ] ]
-            , Cell
-                ( "" , [] , [] )
-                AlignDefault
-                (RowSpan 1)
-                (ColSpan 1)
-                [ Plain [ Str "23" ] ]
-            , Cell
-                ( "" , [] , [] )
-                AlignDefault
-                (RowSpan 1)
-                (ColSpan 1)
-                [ Plain [ Str "years" ] ]
+      (TableFoot ( "" , [] , [] ) [])
+  , Para
+      [ Image
+          ( "" , [] , [] ) [] ( "ppt/media/image1.png" , "Picture 6" )
+      ]
+  , Header
+      2
+      ( "slide-4" , [] , [] )
+      [ Str "Smart" , Space , Str "Art" ]
+  , Div
+      ( ""
+      , [ "smartart" , "chevron2" ]
+      , [ ( "layout" , "chevron2" ) ]
+      )
+      [ Para [ Strong [ Str "First" ] ]
+      , BulletList
+          [ [ Plain [ Str "another" ] ]
+          , [ Plain [ Str "subtitle" ] ]
+          ]
+      , Para [ Strong [ Str "Second" ] ]
+      , BulletList
+          [ [ Plain
+                [ Str "and" , Space , Str "yet" , Space , Str "again" ]
             ]
-        ]
-    ]
-    (TableFoot ( "" , [] , [] ) [])
-, Para
-    [ Image
-        ( "" , [] , [] ) [] ( "ppt/media/image1.png" , "Picture 6" )
-    ]
-, Header 2 ( "slide-4" , [] , [] ) [ Str "Smart Art" ]
-, Div
-    ( ""
-    , [ "smartart" , "chevron2" ]
-    , [ ( "layout" , "chevron2" ) ]
-    )
-    [ Para [ Strong [ Str "First" ] ]
-    , BulletList
-        [ [ Plain [ Str "another" ] ]
-        , [ Plain [ Str "subtitle" ] ]
-        ]
-    , Para [ Strong [ Str "Second" ] ]
-    , BulletList
-        [ [ Plain [ Str "and yet again" ] ]
-        , [ Plain [ Str "yet more" ] ]
-        ]
-    ]
-]
+          , [ Plain [ Str "yet" , Space , Str "more" ] ]
+          ]
+      ]
+  ]
diff --git a/test/pptx-reader/basic.pptx b/test/pptx-reader/basic.pptx
Binary files a/test/pptx-reader/basic.pptx and b/test/pptx-reader/basic.pptx differ
diff --git a/test/pptx-reader/charts.native b/test/pptx-reader/charts.native
new file mode 100644
--- /dev/null
+++ b/test/pptx-reader/charts.native
@@ -0,0 +1,336 @@
+Pandoc
+  Meta { unMeta = fromList [] }
+  [ Header
+      2
+      ( "slide-1" , [] , [] )
+      [ Str "Bar" , Space , Str "chart" ]
+  , Div
+      ( "" , [ "chart" ] , [ ( "type" , "bar" ) ] )
+      [ Table
+          ( "" , [] , [] )
+          (Caption
+             Nothing
+             [ Plain
+                 [ Str "Growth"
+                 , Space
+                 , Str "by"
+                 , Space
+                 , Str "debt"
+                 ]
+             ])
+          [ ( AlignDefault , ColWidthDefault )
+          , ( AlignDefault , ColWidthDefault )
+          , ( AlignDefault , ColWidthDefault )
+          ]
+          (TableHead
+             ( "" , [] , [] )
+             [ Row
+                 ( "" , [] , [] )
+                 [ Cell
+                     ( "" , [] , [] )
+                     AlignDefault
+                     (RowSpan 1)
+                     (ColSpan 1)
+                     [ Plain [] ]
+                 , Cell
+                     ( "" , [] , [] )
+                     AlignDefault
+                     (RowSpan 1)
+                     (ColSpan 1)
+                     [ Plain [ Str "2019" ] ]
+                 , Cell
+                     ( "" , [] , [] )
+                     AlignDefault
+                     (RowSpan 1)
+                     (ColSpan 1)
+                     [ Plain [ Str "2020" ] ]
+                 ]
+             ])
+          [ TableBody
+              ( "" , [] , [] )
+              (RowHeadColumns 0)
+              []
+              [ Row
+                  ( "" , [] , [] )
+                  [ Cell
+                      ( "" , [] , [] )
+                      AlignDefault
+                      (RowSpan 1)
+                      (ColSpan 1)
+                      [ Plain [ Str "Below" , Space , Str "30%" ] ]
+                  , Cell
+                      ( "" , [] , [] )
+                      AlignDefault
+                      (RowSpan 1)
+                      (ColSpan 1)
+                      [ Plain [ Str "4.1" ] ]
+                  , Cell
+                      ( "" , [] , [] )
+                      AlignDefault
+                      (RowSpan 1)
+                      (ColSpan 1)
+                      [ Plain [ Str "3.9" ] ]
+                  ]
+              , Row
+                  ( "" , [] , [] )
+                  [ Cell
+                      ( "" , [] , [] )
+                      AlignDefault
+                      (RowSpan 1)
+                      (ColSpan 1)
+                      [ Plain
+                          [ Str "30"
+                          , Space
+                          , Str "to"
+                          , Space
+                          , Str "60%"
+                          ]
+                      ]
+                  , Cell
+                      ( "" , [] , [] )
+                      AlignDefault
+                      (RowSpan 1)
+                      (ColSpan 1)
+                      [ Plain [ Str "2.8" ] ]
+                  , Cell
+                      ( "" , [] , [] )
+                      AlignDefault
+                      (RowSpan 1)
+                      (ColSpan 1)
+                      [ Plain [ Str "2.5" ] ]
+                  ]
+              , Row
+                  ( "" , [] , [] )
+                  [ Cell
+                      ( "" , [] , [] )
+                      AlignDefault
+                      (RowSpan 1)
+                      (ColSpan 1)
+                      [ Plain
+                          [ Str "60"
+                          , Space
+                          , Str "to"
+                          , Space
+                          , Str "90%"
+                          ]
+                      ]
+                  , Cell
+                      ( "" , [] , [] )
+                      AlignDefault
+                      (RowSpan 1)
+                      (ColSpan 1)
+                      [ Plain [ Str "2.8" ] ]
+                  , Cell
+                      ( "" , [] , [] )
+                      AlignDefault
+                      (RowSpan 1)
+                      (ColSpan 1)
+                      [ Plain [] ]
+                  ]
+              , Row
+                  ( "" , [] , [] )
+                  [ Cell
+                      ( "" , [] , [] )
+                      AlignDefault
+                      (RowSpan 1)
+                      (ColSpan 1)
+                      [ Plain
+                          [ Str "90%"
+                          , Space
+                          , Str "and"
+                          , Space
+                          , Str "above"
+                          ]
+                      ]
+                  , Cell
+                      ( "" , [] , [] )
+                      AlignDefault
+                      (RowSpan 1)
+                      (ColSpan 1)
+                      [ Plain [ Str "-0.1" ] ]
+                  , Cell
+                      ( "" , [] , [] )
+                      AlignDefault
+                      (RowSpan 1)
+                      (ColSpan 1)
+                      [ Plain [ Str "0.4" ] ]
+                  ]
+              ]
+          ]
+          (TableFoot ( "" , [] , [] ) [])
+      ]
+  , Header
+      2
+      ( "slide-2" , [] , [] )
+      [ Str "Line" , Space , Str "chart" ]
+  , Div
+      ( "" , [ "chart" ] , [ ( "type" , "line" ) ] )
+      [ Table
+          ( "" , [] , [] )
+          (Caption Nothing [])
+          [ ( AlignDefault , ColWidthDefault )
+          , ( AlignDefault , ColWidthDefault )
+          ]
+          (TableHead
+             ( "" , [] , [] )
+             [ Row
+                 ( "" , [] , [] )
+                 [ Cell
+                     ( "" , [] , [] )
+                     AlignDefault
+                     (RowSpan 1)
+                     (ColSpan 1)
+                     [ Plain [] ]
+                 , Cell
+                     ( "" , [] , [] )
+                     AlignDefault
+                     (RowSpan 1)
+                     (ColSpan 1)
+                     [ Plain [ Str "Revenue" ] ]
+                 ]
+             ])
+          [ TableBody
+              ( "" , [] , [] )
+              (RowHeadColumns 0)
+              []
+              [ Row
+                  ( "" , [] , [] )
+                  [ Cell
+                      ( "" , [] , [] )
+                      AlignDefault
+                      (RowSpan 1)
+                      (ColSpan 1)
+                      [ Plain [ Str "Q1" ] ]
+                  , Cell
+                      ( "" , [] , [] )
+                      AlignDefault
+                      (RowSpan 1)
+                      (ColSpan 1)
+                      [ Plain [ Str "10" ] ]
+                  ]
+              , Row
+                  ( "" , [] , [] )
+                  [ Cell
+                      ( "" , [] , [] )
+                      AlignDefault
+                      (RowSpan 1)
+                      (ColSpan 1)
+                      [ Plain [ Str "Q2" ] ]
+                  , Cell
+                      ( "" , [] , [] )
+                      AlignDefault
+                      (RowSpan 1)
+                      (ColSpan 1)
+                      [ Plain [ Str "12" ] ]
+                  ]
+              , Row
+                  ( "" , [] , [] )
+                  [ Cell
+                      ( "" , [] , [] )
+                      AlignDefault
+                      (RowSpan 1)
+                      (ColSpan 1)
+                      [ Plain [ Str "Q3" ] ]
+                  , Cell
+                      ( "" , [] , [] )
+                      AlignDefault
+                      (RowSpan 1)
+                      (ColSpan 1)
+                      [ Plain [ Str "15" ] ]
+                  ]
+              ]
+          ]
+          (TableFoot ( "" , [] , [] ) [])
+      ]
+  , Header
+      2
+      ( "slide-3" , [] , [] )
+      [ Str "Scatter" , Space , Str "chart" ]
+  , Div
+      ( "" , [ "chart" ] , [ ( "type" , "scatter" ) ] )
+      [ Table
+          ( "" , [] , [] )
+          (Caption Nothing [])
+          [ ( AlignDefault , ColWidthDefault )
+          , ( AlignDefault , ColWidthDefault )
+          ]
+          (TableHead
+             ( "" , [] , [] )
+             [ Row
+                 ( "" , [] , [] )
+                 [ Cell
+                     ( "" , [] , [] )
+                     AlignDefault
+                     (RowSpan 1)
+                     (ColSpan 1)
+                     [ Plain [] ]
+                 , Cell
+                     ( "" , [] , [] )
+                     AlignDefault
+                     (RowSpan 1)
+                     (ColSpan 1)
+                     [ Plain [ Str "Trial" ] ]
+                 ]
+             ])
+          [ TableBody
+              ( "" , [] , [] )
+              (RowHeadColumns 0)
+              []
+              [ Row
+                  ( "" , [] , [] )
+                  [ Cell
+                      ( "" , [] , [] )
+                      AlignDefault
+                      (RowSpan 1)
+                      (ColSpan 1)
+                      [ Plain [ Str "1" ] ]
+                  , Cell
+                      ( "" , [] , [] )
+                      AlignDefault
+                      (RowSpan 1)
+                      (ColSpan 1)
+                      [ Plain [ Str "2.5" ] ]
+                  ]
+              , Row
+                  ( "" , [] , [] )
+                  [ Cell
+                      ( "" , [] , [] )
+                      AlignDefault
+                      (RowSpan 1)
+                      (ColSpan 1)
+                      [ Plain [ Str "2" ] ]
+                  , Cell
+                      ( "" , [] , [] )
+                      AlignDefault
+                      (RowSpan 1)
+                      (ColSpan 1)
+                      [ Plain [ Str "4.0" ] ]
+                  ]
+              , Row
+                  ( "" , [] , [] )
+                  [ Cell
+                      ( "" , [] , [] )
+                      AlignDefault
+                      (RowSpan 1)
+                      (ColSpan 1)
+                      [ Plain [ Str "3" ] ]
+                  , Cell
+                      ( "" , [] , [] )
+                      AlignDefault
+                      (RowSpan 1)
+                      (ColSpan 1)
+                      [ Plain [ Str "5.5" ] ]
+                  ]
+              ]
+          ]
+          (TableFoot ( "" , [] , [] ) [])
+      ]
+  , Header
+      2
+      ( "slide-4" , [] , [] )
+      [ Str "Unreadable" , Space , Str "chart" ]
+  , Para
+      [ Str
+          "[Graphic: other: http://schemas.openxmlformats.org/drawingml/2006/chart]"
+      ]
+  ]
diff --git a/test/pptx-reader/charts.pptx b/test/pptx-reader/charts.pptx
new file mode 100644
Binary files /dev/null and b/test/pptx-reader/charts.pptx differ
diff --git a/test/pptx-reader/equations.native b/test/pptx-reader/equations.native
new file mode 100644
--- /dev/null
+++ b/test/pptx-reader/equations.native
@@ -0,0 +1,26 @@
+Pandoc
+  Meta { unMeta = fromList [] }
+  [ Header 2 ( "slide-1" , [] , [] ) [ Str "Equations" ]
+  , Para
+      [ Str "The"
+      , Space
+      , Str "mean"
+      , Space
+      , Str "is"
+      , Space
+      , Math InlineMath "\\bar{x} = \\frac{1}{n}\\sum x_{i}"
+      , Space
+      , Str "here."
+      ]
+  , Para [ Math DisplayMath "E = mc^{2}" ]
+  , Para
+      [ Str "After"
+      , Space
+      , Str "the"
+      , Space
+      , Str "equations."
+      ]
+  , Header 2 ( "slide-2" , [] , [] ) [ Str "Fallback" ]
+  , Para
+      [ Str "From" , Space , Str "the" , Space , Str "fallback" ]
+  ]
diff --git a/test/pptx-reader/equations.pptx b/test/pptx-reader/equations.pptx
new file mode 100644
Binary files /dev/null and b/test/pptx-reader/equations.pptx differ
diff --git a/test/pptx-reader/formatting.native b/test/pptx-reader/formatting.native
new file mode 100644
--- /dev/null
+++ b/test/pptx-reader/formatting.native
@@ -0,0 +1,65 @@
+Pandoc
+  Meta { unMeta = fromList [] }
+  [ Header 2 ( "slide-1" , [] , [] ) [ Str "Formatting" ]
+  , Para
+      [ Str "A"
+      , Space
+      , Strong [ Str "bold" , Space , Str "word" ]
+      , Space
+      , Str "and"
+      , Space
+      , Str "an"
+      , Space
+      , Emph [ Str "italic" ]
+      , Space
+      , Str "one,"
+      , Space
+      , Str "not"
+      , Space
+      , Str "bold"
+      , Space
+      , Str "and"
+      , Space
+      , Str "mid"
+      , Strong [ Str "word" ]
+      ]
+  , Para
+      [ Str "Area"
+      , Space
+      , Str "in"
+      , Space
+      , Str "m"
+      , Superscript [ Str "2" ]
+      , Str ","
+      , Space
+      , Str "water"
+      , Space
+      , Str "is"
+      , Space
+      , Str "H"
+      , Subscript [ Str "2" ]
+      , Str "O."
+      ]
+  , Para
+      [ Str "See"
+      , Space
+      , Link
+          ( "" , [] , [] )
+          [ Str "the"
+          , Space
+          , Str "pandoc"
+          , Space
+          , Strong [ Str "site" ]
+          ]
+          ( "https://pandoc.org" , "" )
+      , Space
+      , Str "or"
+      , Space
+      , Link
+          ( "" , [] , [] )
+          [ Str "the" , Space , Str "report" ]
+          ( "Report%20draft.pdf" , "" )
+      , Str "."
+      ]
+  , Para [ Str "Next" , Space , Str "slide" ]
+  ]
diff --git a/test/pptx-reader/formatting.pptx b/test/pptx-reader/formatting.pptx
new file mode 100644
Binary files /dev/null and b/test/pptx-reader/formatting.pptx differ
diff --git a/test/pptx-reader/groups.native b/test/pptx-reader/groups.native
new file mode 100644
--- /dev/null
+++ b/test/pptx-reader/groups.native
@@ -0,0 +1,14 @@
+Pandoc
+  Meta { unMeta = fromList [] }
+  [ Header 2 ( "slide-1" , [] , [] ) [ Str "Groups" ]
+  , Para [ Str "Before" ]
+  , Para [ Str "Grouped" ]
+  , Para
+      [ Image
+          ( "" , [] , [] )
+          [ Str "image.png" ]
+          ( "ppt/media/image1.png" , "Picture 5" )
+      ]
+  , Para [ Str "Nested" ]
+  , Para [ Str "After" ]
+  ]
diff --git a/test/pptx-reader/groups.pptx b/test/pptx-reader/groups.pptx
new file mode 100644
Binary files /dev/null and b/test/pptx-reader/groups.pptx differ
diff --git a/test/pptx-reader/hidden.native b/test/pptx-reader/hidden.native
new file mode 100644
--- /dev/null
+++ b/test/pptx-reader/hidden.native
@@ -0,0 +1,21 @@
+Pandoc
+  Meta { unMeta = fromList [] }
+  [ Header 2 ( "slide-1" , [] , [] ) [ Str "Shown" ]
+  , Header
+      2 ( "slide-2" , [ "hidden" ] , [] ) [ Str "Hidden" ]
+  , Para
+      [ Str "Body"
+      , Space
+      , Str "of"
+      , Space
+      , Str "the"
+      , Space
+      , Str "hidden"
+      , Space
+      , Str "slide"
+      ]
+  , Header
+      2
+      ( "slide-3" , [] , [] )
+      [ Str "Shown" , Space , Str "explicitly" ]
+  ]
diff --git a/test/pptx-reader/hidden.pptx b/test/pptx-reader/hidden.pptx
new file mode 100644
Binary files /dev/null and b/test/pptx-reader/hidden.pptx differ
diff --git a/test/pptx-reader/lists-writer.native b/test/pptx-reader/lists-writer.native
new file mode 100644
--- /dev/null
+++ b/test/pptx-reader/lists-writer.native
@@ -0,0 +1,26 @@
+Pandoc
+  Meta { unMeta = fromList [] }
+  [ Header 2 ( "slide-1" , [] , [] ) [ Str "Bullets" ]
+  , BulletList
+      [ [ Plain [ Str "one" ] ]
+      , [ Plain [ Str "two" ]
+        , BulletList
+            [ [ Plain [ Str "nested" , Space , Str "a" ] ]
+            , [ Plain [ Str "nested" , Space , Str "b" ] ]
+            ]
+        ]
+      , [ Plain [ Str "three" ] ]
+      ]
+  , Header 2 ( "slide-2" , [] , [] ) [ Str "Numbers" ]
+  , OrderedList
+      ( 1 , Decimal , Period )
+      [ [ Plain [ Str "first" ] ]
+      , [ Plain [ Str "second" ]
+        , OrderedList
+            ( 1 , LowerAlpha , Period ) [ [ Plain [ Str "inner" ] ] ]
+        ]
+      , [ Plain [ Str "third" ] ]
+      ]
+  , Para
+      [ Str "After" , Space , Str "the" , Space , Str "list." ]
+  ]
diff --git a/test/pptx-reader/lists-writer.pptx b/test/pptx-reader/lists-writer.pptx
new file mode 100644
Binary files /dev/null and b/test/pptx-reader/lists-writer.pptx differ
diff --git a/test/pptx-reader/lists.native b/test/pptx-reader/lists.native
new file mode 100644
--- /dev/null
+++ b/test/pptx-reader/lists.native
@@ -0,0 +1,21 @@
+Pandoc
+  Meta { unMeta = fromList [] }
+  [ Header
+      2
+      ( "slide-1" , [] , [] )
+      [ Str "Inherited" , Space , Str "bullets" ]
+  , BulletList
+      [ [ Plain [ Str "one" ] ]
+      , [ Plain [ Str "two" ]
+        , BulletList [ [ Plain [ Str "nested" ] ] ]
+        ]
+      , [ Plain [ Str "three" ] ]
+      ]
+  , Para [ Str "no" , Space , Str "bullet" ]
+  , Header
+      2 ( "slide-2" , [] , [] ) [ Str "Text" , Space , Str "box" ]
+  , Para [ Str "plain" ]
+  , OrderedList
+      ( 3 , LowerAlpha , OneParen )
+      [ [ Plain [ Str "third" ] ] , [ Plain [ Str "fourth" ] ] ]
+  ]
diff --git a/test/pptx-reader/lists.pptx b/test/pptx-reader/lists.pptx
new file mode 100644
Binary files /dev/null and b/test/pptx-reader/lists.pptx differ
diff --git a/test/pptx-reader/notes.native b/test/pptx-reader/notes.native
new file mode 100644
--- /dev/null
+++ b/test/pptx-reader/notes.native
@@ -0,0 +1,60 @@
+Pandoc
+  Meta { unMeta = fromList [] }
+  [ Header
+      2
+      ( "slide-1" , [] , [] )
+      [ Str "Notes"
+      , Space
+      , Str "on"
+      , Space
+      , Str "two"
+      , Space
+      , Str "paragraphs"
+      ]
+  , Div
+      ( "" , [ "notes" ] , [] )
+      [ Para
+          [ Str "First"
+          , Space
+          , Str "paragraph"
+          , Space
+          , Str "of"
+          , Space
+          , Str "the"
+          , Space
+          , Str "notes."
+          ]
+      , Para [ Str "Second" , Space , Str "paragraph." ]
+      ]
+  , Header
+      2 ( "slide-2" , [] , [] ) [ Str "No" , Space , Str "notes" ]
+  , Header
+      2
+      ( "slide-3" , [] , [] )
+      [ Str "Empty" , Space , Str "notes" ]
+  , Header
+      2
+      ( "slide-4" , [ "hidden" ] , [] )
+      [ Str "Hidden"
+      , Space
+      , Str "slide"
+      , Space
+      , Str "with"
+      , Space
+      , Str "notes"
+      ]
+  , Div
+      ( "" , [ "notes" ] , [] )
+      [ Para
+          [ Str "Notes"
+          , Space
+          , Str "on"
+          , Space
+          , Str "the"
+          , Space
+          , Str "hidden"
+          , Space
+          , Str "slide."
+          ]
+      ]
+  ]
diff --git a/test/pptx-reader/notes.pptx b/test/pptx-reader/notes.pptx
new file mode 100644
Binary files /dev/null and b/test/pptx-reader/notes.pptx differ
diff --git a/test/pptx-reader/runs.native b/test/pptx-reader/runs.native
new file mode 100644
--- /dev/null
+++ b/test/pptx-reader/runs.native
@@ -0,0 +1,51 @@
+Pandoc
+  Meta { unMeta = fromList [] }
+  [ Header
+      2
+      ( "slide-1" , [] , [] )
+      [ Str "Everworker" , Space , Str "diagram" ]
+  , Para
+      [ Str "Hel" , Strong [ Str "lo" ] , Space , Str "world" ]
+  , Para [ Str "openai," , Space , Str "anthropic" ]
+  , Para
+      [ Str "line"
+      , Space
+      , Str "one"
+      , LineBreak
+      , Str "line"
+      , Space
+      , Str "two"
+      ]
+  , Table
+      ( "" , [] , [] )
+      (Caption Nothing [])
+      [ ( AlignDefault , ColWidthDefault ) ]
+      (TableHead
+         ( "" , [] , [] )
+         [ Row
+             ( "" , [] , [] )
+             [ Cell
+                 ( "" , [] , [] )
+                 AlignDefault
+                 (RowSpan 1)
+                 (ColSpan 1)
+                 [ Plain [ Str "Header" ] ]
+             ]
+         ])
+      [ TableBody
+          ( "" , [] , [] )
+          (RowHeadColumns 0)
+          []
+          [ Row
+              ( "" , [] , [] )
+              [ Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "cell" ] ]
+              ]
+          ]
+      ]
+      (TableFoot ( "" , [] , [] ) [])
+  ]
diff --git a/test/pptx-reader/runs.pptx b/test/pptx-reader/runs.pptx
new file mode 100644
Binary files /dev/null and b/test/pptx-reader/runs.pptx differ
diff --git a/test/pptx-reader/slide-numbers.native b/test/pptx-reader/slide-numbers.native
new file mode 100644
--- /dev/null
+++ b/test/pptx-reader/slide-numbers.native
@@ -0,0 +1,7 @@
+Pandoc
+  Meta { unMeta = fromList [] }
+  [ Header 2 ( "slide-1" , [] , [] ) [ Str "Numbered" ]
+  , Para [ Str "Body" , Space , Str "text" ]
+  , Para
+      [ Str "A" , Space , Str "footer" , Space , Str "note" ]
+  ]
diff --git a/test/pptx-reader/slide-numbers.pptx b/test/pptx-reader/slide-numbers.pptx
new file mode 100644
Binary files /dev/null and b/test/pptx-reader/slide-numbers.pptx differ
diff --git a/test/pptx-reader/table-spans.native b/test/pptx-reader/table-spans.native
new file mode 100644
--- /dev/null
+++ b/test/pptx-reader/table-spans.native
@@ -0,0 +1,90 @@
+Pandoc
+  Meta { unMeta = fromList [] }
+  [ Header
+      2
+      ( "slide-1" , [] , [] )
+      [ Str "Merged" , Space , Str "cells" ]
+  , Table
+      ( "" , [] , [] )
+      (Caption Nothing [])
+      [ ( AlignDefault , ColWidthDefault )
+      , ( AlignDefault , ColWidthDefault )
+      , ( AlignDefault , ColWidthDefault )
+      ]
+      (TableHead
+         ( "" , [] , [] )
+         [ Row
+             ( "" , [] , [] )
+             [ Cell
+                 ( "" , [] , [] )
+                 AlignDefault
+                 (RowSpan 1)
+                 (ColSpan 2)
+                 [ Plain [ Str "Group" ] ]
+             , Cell
+                 ( "" , [] , [] )
+                 AlignDefault
+                 (RowSpan 1)
+                 (ColSpan 1)
+                 [ Plain [ Str "Total" ] ]
+             ]
+         ])
+      [ TableBody
+          ( "" , [] , [] )
+          (RowHeadColumns 0)
+          []
+          [ Row
+              ( "" , [] , [] )
+              [ Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 2)
+                  (ColSpan 1)
+                  [ Plain [ Str "a" ] ]
+              , Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "1" ] ]
+              , Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [] ]
+              ]
+          , Row
+              ( "" , [] , [] )
+              [ Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 2)
+                  [ Plain [ Str "wide" ] ]
+              ]
+          , Row
+              ( "" , [] , [] )
+              [ Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "b" ] ]
+              , Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "2" ] ]
+              , Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "3" ] ]
+              ]
+          ]
+      ]
+      (TableFoot ( "" , [] , [] ) [])
+  ]
diff --git a/test/pptx-reader/table-spans.pptx b/test/pptx-reader/table-spans.pptx
new file mode 100644
Binary files /dev/null and b/test/pptx-reader/table-spans.pptx differ
diff --git a/test/pptx/background-image/output.pptx b/test/pptx/background-image/output.pptx
Binary files a/test/pptx/background-image/output.pptx and b/test/pptx/background-image/output.pptx differ
diff --git a/test/pptx/background-image/templated.pptx b/test/pptx/background-image/templated.pptx
Binary files a/test/pptx/background-image/templated.pptx and b/test/pptx/background-image/templated.pptx differ
diff --git a/test/pptx/blanks/just-speaker-notes/output.pptx b/test/pptx/blanks/just-speaker-notes/output.pptx
Binary files a/test/pptx/blanks/just-speaker-notes/output.pptx and b/test/pptx/blanks/just-speaker-notes/output.pptx differ
diff --git a/test/pptx/blanks/just-speaker-notes/templated.pptx b/test/pptx/blanks/just-speaker-notes/templated.pptx
Binary files a/test/pptx/blanks/just-speaker-notes/templated.pptx and b/test/pptx/blanks/just-speaker-notes/templated.pptx differ
diff --git a/test/pptx/document-properties/output.pptx b/test/pptx/document-properties/output.pptx
Binary files a/test/pptx/document-properties/output.pptx and b/test/pptx/document-properties/output.pptx differ
diff --git a/test/pptx/document-properties/templated.pptx b/test/pptx/document-properties/templated.pptx
Binary files a/test/pptx/document-properties/templated.pptx and b/test/pptx/document-properties/templated.pptx differ
diff --git a/test/pptx/footer/basic/output.pptx b/test/pptx/footer/basic/output.pptx
Binary files a/test/pptx/footer/basic/output.pptx and b/test/pptx/footer/basic/output.pptx differ
diff --git a/test/pptx/footer/fixed-date/output.pptx b/test/pptx/footer/fixed-date/output.pptx
Binary files a/test/pptx/footer/fixed-date/output.pptx and b/test/pptx/footer/fixed-date/output.pptx differ
diff --git a/test/pptx/footer/higher-slide-number/output.pptx b/test/pptx/footer/higher-slide-number/output.pptx
Binary files a/test/pptx/footer/higher-slide-number/output.pptx and b/test/pptx/footer/higher-slide-number/output.pptx differ
diff --git a/test/pptx/footer/no-title-slide/output.pptx b/test/pptx/footer/no-title-slide/output.pptx
Binary files a/test/pptx/footer/no-title-slide/output.pptx and b/test/pptx/footer/no-title-slide/output.pptx differ
diff --git a/test/pptx/layouts/deleted.pptx b/test/pptx/layouts/deleted.pptx
Binary files a/test/pptx/layouts/deleted.pptx and b/test/pptx/layouts/deleted.pptx differ
diff --git a/test/pptx/layouts/moved.pptx b/test/pptx/layouts/moved.pptx
Binary files a/test/pptx/layouts/moved.pptx and b/test/pptx/layouts/moved.pptx differ
diff --git a/test/pptx/metadata-speaker-notes/output.pptx b/test/pptx/metadata-speaker-notes/output.pptx
Binary files a/test/pptx/metadata-speaker-notes/output.pptx and b/test/pptx/metadata-speaker-notes/output.pptx differ
diff --git a/test/pptx/metadata-speaker-notes/templated.pptx b/test/pptx/metadata-speaker-notes/templated.pptx
Binary files a/test/pptx/metadata-speaker-notes/templated.pptx and b/test/pptx/metadata-speaker-notes/templated.pptx differ
diff --git a/test/pptx/reference-no-slides/with-notes/output.pptx b/test/pptx/reference-no-slides/with-notes/output.pptx
Binary files a/test/pptx/reference-no-slides/with-notes/output.pptx and b/test/pptx/reference-no-slides/with-notes/output.pptx differ
diff --git a/test/pptx/speaker-notes-after-metadata/output.pptx b/test/pptx/speaker-notes-after-metadata/output.pptx
Binary files a/test/pptx/speaker-notes-after-metadata/output.pptx and b/test/pptx/speaker-notes-after-metadata/output.pptx differ
diff --git a/test/pptx/speaker-notes-after-metadata/templated.pptx b/test/pptx/speaker-notes-after-metadata/templated.pptx
Binary files a/test/pptx/speaker-notes-after-metadata/templated.pptx and b/test/pptx/speaker-notes-after-metadata/templated.pptx differ
diff --git a/test/pptx/speaker-notes-afterheader/output.pptx b/test/pptx/speaker-notes-afterheader/output.pptx
Binary files a/test/pptx/speaker-notes-afterheader/output.pptx and b/test/pptx/speaker-notes-afterheader/output.pptx differ
diff --git a/test/pptx/speaker-notes-afterheader/templated.pptx b/test/pptx/speaker-notes-afterheader/templated.pptx
Binary files a/test/pptx/speaker-notes-afterheader/templated.pptx and b/test/pptx/speaker-notes-afterheader/templated.pptx differ
diff --git a/test/pptx/speaker-notes-afterseps/output.pptx b/test/pptx/speaker-notes-afterseps/output.pptx
Binary files a/test/pptx/speaker-notes-afterseps/output.pptx and b/test/pptx/speaker-notes-afterseps/output.pptx differ
diff --git a/test/pptx/speaker-notes-afterseps/templated.pptx b/test/pptx/speaker-notes-afterseps/templated.pptx
Binary files a/test/pptx/speaker-notes-afterseps/templated.pptx and b/test/pptx/speaker-notes-afterseps/templated.pptx differ
diff --git a/test/pptx/speaker-notes/output.pptx b/test/pptx/speaker-notes/output.pptx
Binary files a/test/pptx/speaker-notes/output.pptx and b/test/pptx/speaker-notes/output.pptx differ
diff --git a/test/pptx/speaker-notes/templated.pptx b/test/pptx/speaker-notes/templated.pptx
Binary files a/test/pptx/speaker-notes/templated.pptx and b/test/pptx/speaker-notes/templated.pptx differ
diff --git a/test/s5-basic.html b/test/s5-basic.html
--- a/test/s5-basic.html
+++ b/test/s5-basic.html
@@ -15,6 +15,12 @@
     ** See https://pandoc.org/MANUAL.html#variables-for-html for config info.
     */
     span.smallcaps{font-variant: small-caps;}
+    em, em em em, em em em em em {
+      font-style: italic;
+    }
+    em em, em em em em {
+      font-style: normal;
+    }
     div.columns{display: flex; gap: 1.5em;}
     div.column{flex: auto;}
     @media screen {
@@ -31,7 +37,27 @@
       margin: 0 0.8em 0.2em -1.6em;
       vertical-align: middle;
     }
-  </style>
+    @media print {
+      html {
+        color-scheme: light only;
+      }
+      html, body, pre, code {
+        background-color: transparent;
+      }
+      body, a, a:visited, blockquote {
+        color: black;
+      }
+      pre, code {
+        padding: 0;
+      }
+      p, h2, h3 {
+        orphans: 3;
+        widows: 3;
+      }
+      h2, h3, h4 {
+        page-break-after: avoid;
+      }
+    }  </style>
   <!-- configuration parameters -->
   <meta name="defaultView" content="slideshow" />
   <meta name="controlVis" content="hidden" />
diff --git a/test/s5-fancy.html b/test/s5-fancy.html
--- a/test/s5-fancy.html
+++ b/test/s5-fancy.html
@@ -15,6 +15,12 @@
     ** See https://pandoc.org/MANUAL.html#variables-for-html for config info.
     */
     span.smallcaps{font-variant: small-caps;}
+    em, em em em, em em em em em {
+      font-style: italic;
+    }
+    em em, em em em em {
+      font-style: normal;
+    }
     div.columns{display: flex; gap: 1.5em;}
     div.column{flex: auto;}
     @media screen {
@@ -31,7 +37,27 @@
       margin: 0 0.8em 0.2em -1.6em;
       vertical-align: middle;
     }
-  </style>
+    @media print {
+      html {
+        color-scheme: light only;
+      }
+      html, body, pre, code {
+        background-color: transparent;
+      }
+      body, a, a:visited, blockquote {
+        color: black;
+      }
+      pre, code {
+        padding: 0;
+      }
+      p, h2, h3 {
+        orphans: 3;
+        widows: 3;
+      }
+      h2, h3, h4 {
+        page-break-after: avoid;
+      }
+    }  </style>
   <!-- configuration parameters -->
   <meta name="defaultView" content="slideshow" />
   <meta name="controlVis" content="hidden" />
diff --git a/test/s5-inserts.html b/test/s5-inserts.html
--- a/test/s5-inserts.html
+++ b/test/s5-inserts.html
@@ -13,6 +13,12 @@
     ** See https://pandoc.org/MANUAL.html#variables-for-html for config info.
     */
     span.smallcaps{font-variant: small-caps;}
+    em, em em em, em em em em em {
+      font-style: italic;
+    }
+    em em, em em em em {
+      font-style: normal;
+    }
     div.columns{display: flex; gap: 1.5em;}
     div.column{flex: auto;}
     @media screen {
@@ -29,7 +35,27 @@
       margin: 0 0.8em 0.2em -1.6em;
       vertical-align: middle;
     }
-  </style>
+    @media print {
+      html {
+        color-scheme: light only;
+      }
+      html, body, pre, code {
+        background-color: transparent;
+      }
+      body, a, a:visited, blockquote {
+        color: black;
+      }
+      pre, code {
+        padding: 0;
+      }
+      p, h2, h3 {
+        orphans: 3;
+        widows: 3;
+      }
+      h2, h3, h4 {
+        page-break-after: avoid;
+      }
+    }  </style>
   <link rel="stylesheet" href="main.css" type="text/css" />
   STUFF INSERTED
 </head>
diff --git a/test/test-pandoc.hs b/test/test-pandoc.hs
--- a/test/test-pandoc.hs
+++ b/test/test-pandoc.hs
@@ -1,6 +1,6 @@
 module Main (main) where
 
-import System.Environment (getArgs, getExecutablePath)
+import System.Environment (getArgs, getExecutablePath, setEnv)
 import qualified Control.Exception as E
 import Text.Pandoc.App (convertWithOpts, handleOptInfo, defaultOpts, options,
                         parseOptionsFromArgs)
@@ -58,7 +58,10 @@
 import qualified Tests.Writers.Txt2Tags
 import qualified Tests.XML
 import qualified Tests.MediaBag
+import qualified Tests.Data
 import Text.Pandoc.Shared (inDirectory)
+import System.FilePath (takeDirectory)
+import System.Directory (getCurrentDirectory)
 
 tests :: FilePath -> TestTree
 tests pandocPath = testGroup "pandoc tests"
@@ -66,6 +69,7 @@
         , testGroup "Old" (Tests.Old.tests pandocPath)
         , testGroup "Shared" Tests.Shared.tests
         , testGroup "MediaBag" Tests.MediaBag.tests
+        , testGroup "Data" Tests.Data.tests
         , testGroup "XML" Tests.XML.tests
         , testGroup "ImageSize" Tests.ImageSize.tests
         , testGroup "Writers"
@@ -134,4 +138,7 @@
     _ -> inDirectory "test" $ do
            fp <- getExecutablePath
            -- putStrLn $ "Using pandoc executable at " ++ fp
+           -- look for data in data/ directory...
+           cwd <- getCurrentDirectory
+           setEnv "pandoc_datadir" (takeDirectory cwd) -- drop the /test
            defaultMain $ tests fp
diff --git a/test/writer.html4 b/test/writer.html4
--- a/test/writer.html4
+++ b/test/writer.html4
@@ -40,27 +40,6 @@
         font-size: 1.8em;
       }
     }
-    @media print {
-      html {
-        color-scheme: light only;
-      }
-      html, body, pre, code {
-        background-color: transparent;
-      }
-      body, a, a:visited, blockquote {
-        color: black;
-      }
-      pre, code {
-        padding: 0;
-      }
-      p, h2, h3 {
-        orphans: 3;
-        widows: 3;
-      }
-      h2, h3, h4 {
-        page-break-after: avoid;
-      }
-    }
     p {
       margin: 1em 0;
     }
@@ -166,6 +145,12 @@
       text-decoration: none;
     }
     span.smallcaps{font-variant: small-caps;}
+    em, em em em, em em em em em {
+      font-style: italic;
+    }
+    em em, em em em em {
+      font-style: normal;
+    }
     div.columns{display: flex; gap: 1.5em;}
     div.column{flex: auto;}
     @media screen {
@@ -182,7 +167,27 @@
       margin: 0 0.8em 0.2em -1.6em;
       vertical-align: middle;
     }
-  </style>
+    @media print {
+      html {
+        color-scheme: light only;
+      }
+      html, body, pre, code {
+        background-color: transparent;
+      }
+      body, a, a:visited, blockquote {
+        color: black;
+      }
+      pre, code {
+        padding: 0;
+      }
+      p, h2, h3 {
+        orphans: 3;
+        widows: 3;
+      }
+      h2, h3, h4 {
+        page-break-after: avoid;
+      }
+    }  </style>
 </head>
 <body>
 <div id="header">
diff --git a/test/writer.html5 b/test/writer.html5
--- a/test/writer.html5
+++ b/test/writer.html5
@@ -40,27 +40,6 @@
         font-size: 1.8em;
       }
     }
-    @media print {
-      html {
-        color-scheme: light only;
-      }
-      html, body, pre, code {
-        background-color: transparent;
-      }
-      body, a, a:visited, blockquote {
-        color: black;
-      }
-      pre, code {
-        padding: 0;
-      }
-      p, h2, h3 {
-        orphans: 3;
-        widows: 3;
-      }
-      h2, h3, h4 {
-        page-break-after: avoid;
-      }
-    }
     p {
       margin: 1em 0;
     }
@@ -166,6 +145,12 @@
       text-decoration: none;
     }
     span.smallcaps{font-variant: small-caps;}
+    em, em em em, em em em em em {
+      font-style: italic;
+    }
+    em em, em em em em {
+      font-style: normal;
+    }
     div.columns{display: flex; gap: 1.5em;}
     div.column{flex: auto;}
     @media screen {
@@ -182,7 +167,27 @@
       margin: 0 0.8em 0.2em -1.6em;
       vertical-align: middle;
     }
-  </style>
+    @media print {
+      html {
+        color-scheme: light only;
+      }
+      html, body, pre, code {
+        background-color: transparent;
+      }
+      body, a, a:visited, blockquote {
+        color: black;
+      }
+      pre, code {
+        padding: 0;
+      }
+      p, h2, h3 {
+        orphans: 3;
+        widows: 3;
+      }
+      h2, h3, h4 {
+        page-break-after: avoid;
+      }
+    }  </style>
 </head>
 <body>
 <header id="title-block-header">
diff --git a/test/xlsx-reader/absolute-targets.native b/test/xlsx-reader/absolute-targets.native
new file mode 100644
--- /dev/null
+++ b/test/xlsx-reader/absolute-targets.native
@@ -0,0 +1,50 @@
+Pandoc
+  Meta { unMeta = fromList [] }
+  [ Header 2 ( "sheet-1" , [] , [] ) [ Str "Data" ]
+  , Table
+      ( "" , [] , [] )
+      (Caption Nothing [])
+      [ ( AlignDefault , ColWidthDefault )
+      , ( AlignDefault , ColWidthDefault )
+      ]
+      (TableHead
+         ( "" , [] , [] )
+         [ Row
+             ( "" , [] , [] )
+             [ Cell
+                 ( "" , [] , [] )
+                 AlignDefault
+                 (RowSpan 1)
+                 (ColSpan 1)
+                 [ Plain [ Str "Item" ] ]
+             , Cell
+                 ( "" , [] , [] )
+                 AlignDefault
+                 (RowSpan 1)
+                 (ColSpan 1)
+                 [ Plain [ Str "Count" ] ]
+             ]
+         ])
+      [ TableBody
+          ( "" , [] , [] )
+          (RowHeadColumns 0)
+          []
+          [ Row
+              ( "" , [] , [] )
+              [ Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "Apples" ] ]
+              , Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "3" ] ]
+              ]
+          ]
+      ]
+      (TableFoot ( "" , [] , [] ) [])
+  ]
diff --git a/test/xlsx-reader/absolute-targets.xlsx b/test/xlsx-reader/absolute-targets.xlsx
new file mode 100644
Binary files /dev/null and b/test/xlsx-reader/absolute-targets.xlsx differ
diff --git a/test/xlsx-reader/basic.native b/test/xlsx-reader/basic.native
--- a/test/xlsx-reader/basic.native
+++ b/test/xlsx-reader/basic.native
@@ -49,7 +49,7 @@
                   AlignDefault
                   (RowSpan 1)
                   (ColSpan 1)
-                  [ Plain [ Str "23.0" ] ]
+                  [ Plain [ Str "23" ] ]
               , Cell
                   ( "" , [] , [] )
                   AlignDefault
@@ -70,7 +70,7 @@
                   AlignDefault
                   (RowSpan 1)
                   (ColSpan 1)
-                  [ Plain [ Str "35.0" ] ]
+                  [ Plain [ Str "35" ] ]
               , Cell
                   ( "" , [] , [] )
                   AlignDefault
@@ -262,7 +262,7 @@
                   AlignDefault
                   (RowSpan 1)
                   (ColSpan 1)
-                  [ Plain [ Str "23.0" ] ]
+                  [ Plain [ Str "23" ] ]
               , Cell
                   ( "" , [] , [] )
                   AlignDefault
@@ -274,7 +274,7 @@
                   AlignDefault
                   (RowSpan 1)
                   (ColSpan 1)
-                  [ Plain [ Str "23.0" ] ]
+                  [ Plain [ Str "23" ] ]
               ]
           , Row
               ( "" , [] , [] )
@@ -289,7 +289,7 @@
                   AlignDefault
                   (RowSpan 1)
                   (ColSpan 1)
-                  [ Plain [ Str "35.0" ] ]
+                  [ Plain [ Str "35" ] ]
               , Cell
                   ( "" , [] , [] )
                   AlignDefault
@@ -307,7 +307,7 @@
                   AlignDefault
                   (RowSpan 1)
                   (ColSpan 1)
-                  [ Plain [ Str "35.0" ] ]
+                  [ Plain [ Str "35" ] ]
               ]
           , Row
               ( "" , [] , [] )
@@ -355,13 +355,13 @@
                   AlignDefault
                   (RowSpan 1)
                   (ColSpan 1)
-                  [ Plain [ Str "35.0" ] ]
+                  [ Plain [ Str "35" ] ]
               , Cell
                   ( "" , [] , [] )
                   AlignDefault
                   (RowSpan 1)
                   (ColSpan 1)
-                  [ Plain [ Str "23.0" ] ]
+                  [ Plain [ Str "23" ] ]
               , Cell
                   ( "" , [] , [] )
                   AlignDefault
@@ -373,7 +373,7 @@
                   AlignDefault
                   (RowSpan 1)
                   (ColSpan 1)
-                  [ Plain [ Str "58.0" ] ]
+                  [ Plain [ Str "58" ] ]
               ]
           ]
       ]
diff --git a/test/xlsx-reader/cell-fonts.native b/test/xlsx-reader/cell-fonts.native
new file mode 100644
--- /dev/null
+++ b/test/xlsx-reader/cell-fonts.native
@@ -0,0 +1,54 @@
+Pandoc
+  Meta { unMeta = fromList [] }
+  [ Header 2 ( "sheet-1" , [] , [] ) [ Str "Fonts" ]
+  , Table
+      ( "" , [] , [] )
+      (Caption Nothing [])
+      [ ( AlignDefault , ColWidthDefault ) ]
+      (TableHead
+         ( "" , [] , [] )
+         [ Row
+             ( "" , [] , [] )
+             [ Cell
+                 ( "" , [] , [] )
+                 AlignDefault
+                 (RowSpan 1)
+                 (ColSpan 1)
+                 [ Plain [ Str "Format" ] ]
+             ]
+         ])
+      [ TableBody
+          ( "" , [] , [] )
+          (RowHeadColumns 0)
+          []
+          [ Row
+              ( "" , [] , [] )
+              [ Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Emph [ Str "italic" ] ] ]
+              ]
+          , Row
+              ( "" , [] , [] )
+              [ Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Strong [ Str "bold" ] ] ]
+              ]
+          , Row
+              ( "" , [] , [] )
+              [ Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "regular" ] ]
+              ]
+          ]
+      ]
+      (TableFoot ( "" , [] , [] ) [])
+  ]
diff --git a/test/xlsx-reader/cell-fonts.xlsx b/test/xlsx-reader/cell-fonts.xlsx
new file mode 100644
Binary files /dev/null and b/test/xlsx-reader/cell-fonts.xlsx differ
diff --git a/test/xlsx-reader/charts.native b/test/xlsx-reader/charts.native
new file mode 100644
--- /dev/null
+++ b/test/xlsx-reader/charts.native
@@ -0,0 +1,273 @@
+Pandoc
+  Meta { unMeta = fromList [] }
+  [ Header 2 ( "sheet-1" , [] , [] ) [ Str "Data" ]
+  , Table
+      ( "" , [] , [] )
+      (Caption Nothing [])
+      [ ( AlignDefault , ColWidthDefault )
+      , ( AlignDefault , ColWidthDefault )
+      ]
+      (TableHead
+         ( "" , [] , [] )
+         [ Row
+             ( "" , [] , [] )
+             [ Cell
+                 ( "" , [] , [] )
+                 AlignDefault
+                 (RowSpan 1)
+                 (ColSpan 1)
+                 [ Plain [ Str "Group" ] ]
+             , Cell
+                 ( "" , [] , [] )
+                 AlignDefault
+                 (RowSpan 1)
+                 (ColSpan 1)
+                 [ Plain [ Str "Mean" ] ]
+             ]
+         ])
+      [ TableBody
+          ( "" , [] , [] )
+          (RowHeadColumns 0)
+          []
+          [ Row
+              ( "" , [] , [] )
+              [ Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "Low" ] ]
+              , Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "4.1" ] ]
+              ]
+          , Row
+              ( "" , [] , [] )
+              [ Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "High" ] ]
+              , Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "-0.1" ] ]
+              ]
+          ]
+      ]
+      (TableFoot ( "" , [] , [] ) [])
+  , Div
+      ( "" , [ "chart" ] , [ ( "type" , "bar" ) ] )
+      [ Table
+          ( "" , [] , [] )
+          (Caption
+             Nothing [ Plain [ Str "Mean" , Space , Str "growth" ] ])
+          [ ( AlignDefault , ColWidthDefault )
+          , ( AlignDefault , ColWidthDefault )
+          ]
+          (TableHead
+             ( "" , [] , [] )
+             [ Row
+                 ( "" , [] , [] )
+                 [ Cell
+                     ( "" , [] , [] )
+                     AlignDefault
+                     (RowSpan 1)
+                     (ColSpan 1)
+                     [ Plain [] ]
+                 , Cell
+                     ( "" , [] , [] )
+                     AlignDefault
+                     (RowSpan 1)
+                     (ColSpan 1)
+                     [ Plain [ Str "Mean" ] ]
+                 ]
+             ])
+          [ TableBody
+              ( "" , [] , [] )
+              (RowHeadColumns 0)
+              []
+              [ Row
+                  ( "" , [] , [] )
+                  [ Cell
+                      ( "" , [] , [] )
+                      AlignDefault
+                      (RowSpan 1)
+                      (ColSpan 1)
+                      [ Plain [ Str "Low" ] ]
+                  , Cell
+                      ( "" , [] , [] )
+                      AlignDefault
+                      (RowSpan 1)
+                      (ColSpan 1)
+                      [ Plain [ Str "4.1" ] ]
+                  ]
+              , Row
+                  ( "" , [] , [] )
+                  [ Cell
+                      ( "" , [] , [] )
+                      AlignDefault
+                      (RowSpan 1)
+                      (ColSpan 1)
+                      [ Plain [ Str "High" ] ]
+                  , Cell
+                      ( "" , [] , [] )
+                      AlignDefault
+                      (RowSpan 1)
+                      (ColSpan 1)
+                      [ Plain [ Str "-0.1" ] ]
+                  ]
+              ]
+          ]
+          (TableFoot ( "" , [] , [] ) [])
+      ]
+  , Div
+      ( "" , [ "chart" ] , [ ( "type" , "line" ) ] )
+      [ Table
+          ( "" , [] , [] )
+          (Caption Nothing [])
+          [ ( AlignDefault , ColWidthDefault )
+          , ( AlignDefault , ColWidthDefault )
+          ]
+          (TableHead
+             ( "" , [] , [] )
+             [ Row
+                 ( "" , [] , [] )
+                 [ Cell
+                     ( "" , [] , [] )
+                     AlignDefault
+                     (RowSpan 1)
+                     (ColSpan 1)
+                     [ Plain [] ]
+                 , Cell
+                     ( "" , [] , [] )
+                     AlignDefault
+                     (RowSpan 1)
+                     (ColSpan 1)
+                     [ Plain [ Str "Mean" ] ]
+                 ]
+             ])
+          [ TableBody
+              ( "" , [] , [] )
+              (RowHeadColumns 0)
+              []
+              [ Row
+                  ( "" , [] , [] )
+                  [ Cell
+                      ( "" , [] , [] )
+                      AlignDefault
+                      (RowSpan 1)
+                      (ColSpan 1)
+                      [ Plain [ Str "Low" ] ]
+                  , Cell
+                      ( "" , [] , [] )
+                      AlignDefault
+                      (RowSpan 1)
+                      (ColSpan 1)
+                      [ Plain [ Str "4.1" ] ]
+                  ]
+              , Row
+                  ( "" , [] , [] )
+                  [ Cell
+                      ( "" , [] , [] )
+                      AlignDefault
+                      (RowSpan 1)
+                      (ColSpan 1)
+                      [ Plain [ Str "High" ] ]
+                  , Cell
+                      ( "" , [] , [] )
+                      AlignDefault
+                      (RowSpan 1)
+                      (ColSpan 1)
+                      [ Plain [ Str "-0.1" ] ]
+                  ]
+              ]
+          ]
+          (TableFoot ( "" , [] , [] ) [])
+      ]
+  , Header
+      2
+      ( "sheet-2" , [] , [] )
+      [ Str "Chart" , Space , Str "sheet" ]
+  , Div
+      ( "" , [ "chart" ] , [ ( "type" , "pie" ) ] )
+      [ Table
+          ( "" , [] , [] )
+          (Caption
+             Nothing
+             [ Plain
+                 [ Str "On"
+                 , Space
+                 , Str "its"
+                 , Space
+                 , Str "own"
+                 , Space
+                 , Str "sheet"
+                 ]
+             ])
+          [ ( AlignDefault , ColWidthDefault )
+          , ( AlignDefault , ColWidthDefault )
+          ]
+          (TableHead
+             ( "" , [] , [] )
+             [ Row
+                 ( "" , [] , [] )
+                 [ Cell
+                     ( "" , [] , [] )
+                     AlignDefault
+                     (RowSpan 1)
+                     (ColSpan 1)
+                     [ Plain [] ]
+                 , Cell
+                     ( "" , [] , [] )
+                     AlignDefault
+                     (RowSpan 1)
+                     (ColSpan 1)
+                     [ Plain [ Str "Share" ] ]
+                 ]
+             ])
+          [ TableBody
+              ( "" , [] , [] )
+              (RowHeadColumns 0)
+              []
+              [ Row
+                  ( "" , [] , [] )
+                  [ Cell
+                      ( "" , [] , [] )
+                      AlignDefault
+                      (RowSpan 1)
+                      (ColSpan 1)
+                      [ Plain [ Str "Low" ] ]
+                  , Cell
+                      ( "" , [] , [] )
+                      AlignDefault
+                      (RowSpan 1)
+                      (ColSpan 1)
+                      [ Plain [ Str "0.6" ] ]
+                  ]
+              , Row
+                  ( "" , [] , [] )
+                  [ Cell
+                      ( "" , [] , [] )
+                      AlignDefault
+                      (RowSpan 1)
+                      (ColSpan 1)
+                      [ Plain [ Str "High" ] ]
+                  , Cell
+                      ( "" , [] , [] )
+                      AlignDefault
+                      (RowSpan 1)
+                      (ColSpan 1)
+                      [ Plain [ Str "0.4" ] ]
+                  ]
+              ]
+          ]
+          (TableFoot ( "" , [] , [] ) [])
+      ]
+  ]
diff --git a/test/xlsx-reader/charts.xlsx b/test/xlsx-reader/charts.xlsx
new file mode 100644
Binary files /dev/null and b/test/xlsx-reader/charts.xlsx differ
diff --git a/test/xlsx-reader/dates-1904.native b/test/xlsx-reader/dates-1904.native
new file mode 100644
--- /dev/null
+++ b/test/xlsx-reader/dates-1904.native
@@ -0,0 +1,65 @@
+Pandoc
+  Meta { unMeta = fromList [] }
+  [ Header 2 ( "sheet-1" , [] , [] ) [ Str "Dates" ]
+  , Table
+      ( "" , [] , [] )
+      (Caption Nothing [])
+      [ ( AlignDefault , ColWidthDefault )
+      , ( AlignDefault , ColWidthDefault )
+      ]
+      (TableHead
+         ( "" , [] , [] )
+         [ Row
+             ( "" , [] , [] )
+             [ Cell
+                 ( "" , [] , [] )
+                 AlignDefault
+                 (RowSpan 1)
+                 (ColSpan 1)
+                 [ Plain [ Str "Case" ] ]
+             , Cell
+                 ( "" , [] , [] )
+                 AlignDefault
+                 (RowSpan 1)
+                 (ColSpan 1)
+                 [ Plain [ Str "Value" ] ]
+             ]
+         ])
+      [ TableBody
+          ( "" , [] , [] )
+          (RowHeadColumns 0)
+          []
+          [ Row
+              ( "" , [] , [] )
+              [ Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "day" , Space , Str "zero" ] ]
+              , Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "1904-01-01" ] ]
+              ]
+          , Row
+              ( "" , [] , [] )
+              [ Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "built-in" , Space , Str "14" ] ]
+              , Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "2023-11-01" ] ]
+              ]
+          ]
+      ]
+      (TableFoot ( "" , [] , [] ) [])
+  ]
diff --git a/test/xlsx-reader/dates-1904.xlsx b/test/xlsx-reader/dates-1904.xlsx
new file mode 100644
Binary files /dev/null and b/test/xlsx-reader/dates-1904.xlsx differ
diff --git a/test/xlsx-reader/dates.native b/test/xlsx-reader/dates.native
new file mode 100644
--- /dev/null
+++ b/test/xlsx-reader/dates.native
@@ -0,0 +1,432 @@
+Pandoc
+  Meta { unMeta = fromList [] }
+  [ Header 2 ( "sheet-1" , [] , [] ) [ Str "Dates" ]
+  , Table
+      ( "" , [] , [] )
+      (Caption Nothing [])
+      [ ( AlignDefault , ColWidthDefault )
+      , ( AlignDefault , ColWidthDefault )
+      ]
+      (TableHead
+         ( "" , [] , [] )
+         [ Row
+             ( "" , [] , [] )
+             [ Cell
+                 ( "" , [] , [] )
+                 AlignDefault
+                 (RowSpan 1)
+                 (ColSpan 1)
+                 [ Plain [ Str "Case" ] ]
+             , Cell
+                 ( "" , [] , [] )
+                 AlignDefault
+                 (RowSpan 1)
+                 (ColSpan 1)
+                 [ Plain [ Str "Value" ] ]
+             ]
+         ])
+      [ TableBody
+          ( "" , [] , [] )
+          (RowHeadColumns 0)
+          []
+          [ Row
+              ( "" , [] , [] )
+              [ Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "built-in" , Space , Str "14" ] ]
+              , Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "2023-11-01" ] ]
+              ]
+          , Row
+              ( "" , [] , [] )
+              [ Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "built-in" , Space , Str "22" ] ]
+              , Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "2023-11-01" , Space , Str "14:30" ] ]
+              ]
+          , Row
+              ( "" , [] , [] )
+              [ Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "built-in" , Space , Str "20" ] ]
+              , Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "14:30" ] ]
+              ]
+          , Row
+              ( "" , [] , [] )
+              [ Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "built-in" , Space , Str "21" ] ]
+              , Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "14:30:05" ] ]
+              ]
+          , Row
+              ( "" , [] , [] )
+              [ Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "built-in" , Space , Str "45" ] ]
+              , Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "00:05:30" ] ]
+              ]
+          , Row
+              ( "" , [] , [] )
+              [ Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain
+                      [ Str "built-in"
+                      , Space
+                      , Str "46,"
+                      , Space
+                      , Str "a"
+                      , Space
+                      , Str "duration"
+                      ]
+                  ]
+              , Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "1.5" ] ]
+              ]
+          , Row
+              ( "" , [] , [] )
+              [ Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "custom" , Space , Str "date" ] ]
+              , Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "2023-11-01" ] ]
+              ]
+          , Row
+              ( "" , [] , [] )
+              [ Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain
+                      [ Str "custom"
+                      , Space
+                      , Str "date"
+                      , Space
+                      , Str "and"
+                      , Space
+                      , Str "time"
+                      ]
+                  ]
+              , Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "2023-11-01" , Space , Str "14:30:05" ]
+                  ]
+              ]
+          , Row
+              ( "" , [] , [] )
+              [ Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain
+                      [ Str "custom"
+                      , Space
+                      , Str "elapsed"
+                      , Space
+                      , Str "hours"
+                      ]
+                  ]
+              , Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "1.5" ] ]
+              ]
+          , Row
+              ( "" , [] , [] )
+              [ Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "custom" , Space , Str "month" ] ]
+              , Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "2023-11-01" ] ]
+              ]
+          , Row
+              ( "" , [] , [] )
+              [ Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "fixed" , Space , Str "decimals" ] ]
+              , Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "45231" ] ]
+              ]
+          , Row
+              ( "" , [] , [] )
+              [ Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "quoted" , Space , Str "d" ] ]
+              , Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "7" ] ]
+              ]
+          , Row
+              ( "" , [] , [] )
+              [ Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "locale" , Space , Str "prefix" ] ]
+              , Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "2023-11-01" ] ]
+              ]
+          , Row
+              ( "" , [] , [] )
+              [ Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "first" , Space , Str "day" ] ]
+              , Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "1900-01-01" ] ]
+              ]
+          , Row
+              ( "" , [] , [] )
+              [ Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain
+                      [ Str "28"
+                      , Space
+                      , Str "February"
+                      , Space
+                      , Str "1900"
+                      ]
+                  ]
+              , Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "1900-02-28" ] ]
+              ]
+          , Row
+              ( "" , [] , [] )
+              [ Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain
+                      [ Str "nonexistent"
+                      , Space
+                      , Str "29"
+                      , Space
+                      , Str "February"
+                      , Space
+                      , Str "1900"
+                      ]
+                  ]
+              , Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "60" ] ]
+              ]
+          , Row
+              ( "" , [] , [] )
+              [ Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain
+                      [ Str "1"
+                      , Space
+                      , Str "March"
+                      , Space
+                      , Str "1900"
+                      ]
+                  ]
+              , Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "1900-03-01" ] ]
+              ]
+          , Row
+              ( "" , [] , [] )
+              [ Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain
+                      [ Str "zero"
+                      , Space
+                      , Str "under"
+                      , Space
+                      , Str "a"
+                      , Space
+                      , Str "date"
+                      , Space
+                      , Str "format"
+                      ]
+                  ]
+              , Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "0" ] ]
+              ]
+          , Row
+              ( "" , [] , [] )
+              [ Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain
+                      [ Str "negative"
+                      , Space
+                      , Str "under"
+                      , Space
+                      , Str "a"
+                      , Space
+                      , Str "date"
+                      , Space
+                      , Str "format"
+                      ]
+                  ]
+              , Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "-1" ] ]
+              ]
+          , Row
+              ( "" , [] , [] )
+              [ Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain
+                      [ Str "rounds"
+                      , Space
+                      , Str "to"
+                      , Space
+                      , Str "the"
+                      , Space
+                      , Str "next"
+                      , Space
+                      , Str "day"
+                      ]
+                  ]
+              , Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "2023-11-02" , Space , Str "00:00" ] ]
+              ]
+          , Row
+              ( "" , [] , [] )
+              [ Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "General" ] ]
+              , Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "45231" ] ]
+              ]
+          ]
+      ]
+      (TableFoot ( "" , [] , [] ) [])
+  ]
diff --git a/test/xlsx-reader/dates.xlsx b/test/xlsx-reader/dates.xlsx
new file mode 100644
Binary files /dev/null and b/test/xlsx-reader/dates.xlsx differ
diff --git a/test/xlsx-reader/merged.native b/test/xlsx-reader/merged.native
new file mode 100644
--- /dev/null
+++ b/test/xlsx-reader/merged.native
@@ -0,0 +1,161 @@
+Pandoc
+  Meta { unMeta = fromList [] }
+  [ Header 2 ( "sheet-1" , [] , [] ) [ Str "Merged" ]
+  , Table
+      ( "" , [] , [] )
+      (Caption Nothing [])
+      [ ( AlignDefault , ColWidthDefault )
+      , ( AlignDefault , ColWidthDefault )
+      , ( AlignDefault , ColWidthDefault )
+      , ( AlignDefault , ColWidthDefault )
+      ]
+      (TableHead
+         ( "" , [] , [] )
+         [ Row
+             ( "" , [] , [] )
+             [ Cell
+                 ( "" , [] , [] )
+                 AlignDefault
+                 (RowSpan 1)
+                 (ColSpan 2)
+                 [ Plain [ Str "Group" ] ]
+             , Cell
+                 ( "" , [] , [] )
+                 AlignDefault
+                 (RowSpan 1)
+                 (ColSpan 1)
+                 [ Plain [ Str "Total" ] ]
+             , Cell
+                 ( "" , [] , [] )
+                 AlignDefault
+                 (RowSpan 1)
+                 (ColSpan 1)
+                 [ Plain [] ]
+             ]
+         ])
+      [ TableBody
+          ( "" , [] , [] )
+          (RowHeadColumns 0)
+          []
+          [ Row
+              ( "" , [] , [] )
+              [ Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 2)
+                  (ColSpan 1)
+                  [ Plain [ Str "x" ] ]
+              , Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "1" ] ]
+              , Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [] ]
+              , Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "note" ] ]
+              ]
+          , Row
+              ( "" , [] , [] )
+              [ Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "2" ] ]
+              , Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [] ]
+              , Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [] ]
+              ]
+          , Row
+              ( "" , [] , [] )
+              [ Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 4)
+                  [ Plain
+                      [ Str "A"
+                      , Space
+                      , Str "row"
+                      , Space
+                      , Str "across"
+                      ]
+                  ]
+              ]
+          , Row
+              ( "" , [] , [] )
+              [ Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "last" ] ]
+              , Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "3" ] ]
+              , Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [] ]
+              , Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "wide" ] ]
+              ]
+          , Row
+              ( "" , [] , [] )
+              [ Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "tail" ] ]
+              , Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [] ]
+              , Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [] ]
+              , Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [] ]
+              ]
+          ]
+      ]
+      (TableFoot ( "" , [] , [] ) [])
+  ]
diff --git a/test/xlsx-reader/merged.xlsx b/test/xlsx-reader/merged.xlsx
new file mode 100644
Binary files /dev/null and b/test/xlsx-reader/merged.xlsx differ
diff --git a/test/xlsx-reader/numbers.native b/test/xlsx-reader/numbers.native
new file mode 100644
--- /dev/null
+++ b/test/xlsx-reader/numbers.native
@@ -0,0 +1,260 @@
+Pandoc
+  Meta { unMeta = fromList [] }
+  [ Header 2 ( "sheet-1" , [] , [] ) [ Str "Numbers" ]
+  , Table
+      ( "" , [] , [] )
+      (Caption Nothing [])
+      [ ( AlignDefault , ColWidthDefault )
+      , ( AlignDefault , ColWidthDefault )
+      ]
+      (TableHead
+         ( "" , [] , [] )
+         [ Row
+             ( "" , [] , [] )
+             [ Cell
+                 ( "" , [] , [] )
+                 AlignDefault
+                 (RowSpan 1)
+                 (ColSpan 1)
+                 [ Plain [ Str "Case" ] ]
+             , Cell
+                 ( "" , [] , [] )
+                 AlignDefault
+                 (RowSpan 1)
+                 (ColSpan 1)
+                 [ Plain [ Str "Value" ] ]
+             ]
+         ])
+      [ TableBody
+          ( "" , [] , [] )
+          (RowHeadColumns 0)
+          []
+          [ Row
+              ( "" , [] , [] )
+              [ Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "small" ] ]
+              , Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "0.05" ] ]
+              ]
+          , Row
+              ( "" , [] , [] )
+              [ Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "integer" ] ]
+              , Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "21" ] ]
+              ]
+          , Row
+              ( "" , [] , [] )
+              [ Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "large" ] ]
+              , Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "12345678" ] ]
+              ]
+          , Row
+              ( "" , [] , [] )
+              [ Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "negative" ] ]
+              , Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "-0.1" ] ]
+              ]
+          , Row
+              ( "" , [] , [] )
+              [ Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "float" , Space , Str "noise" ] ]
+              , Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "0.3" ] ]
+              ]
+          , Row
+              ( "" , [] , [] )
+              [ Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "carry" ] ]
+              , Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "1" ] ]
+              ]
+          , Row
+              ( "" , [] , [] )
+              [ Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "eleven" , Space , Str "digits" ] ]
+              , Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "12345678901" ] ]
+              ]
+          , Row
+              ( "" , [] , [] )
+              [ Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "twelve" , Space , Str "digits" ] ]
+              , Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "1.23456789012E+11" ] ]
+              ]
+          , Row
+              ( "" , [] , [] )
+              [ Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "fifteen" , Space , Str "digits" ] ]
+              , Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "1.23456789012345E+14" ] ]
+              ]
+          , Row
+              ( "" , [] , [] )
+              [ Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "huge" ] ]
+              , Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "1.23456789012346E+17" ] ]
+              ]
+          , Row
+              ( "" , [] , [] )
+              [ Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "tiny" ] ]
+              , Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "1.5E-10" ] ]
+              ]
+          , Row
+              ( "" , [] , [] )
+              [ Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "zero" ] ]
+              , Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "0" ] ]
+              ]
+          , Row
+              ( "" , [] , [] )
+              [ Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "true" ] ]
+              , Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "TRUE" ] ]
+              ]
+          , Row
+              ( "" , [] , [] )
+              [ Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "false" ] ]
+              , Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "FALSE" ] ]
+              ]
+          , Row
+              ( "" , [] , [] )
+              [ Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "error" ] ]
+              , Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "#DIV/0!" ] ]
+              ]
+          ]
+      ]
+      (TableFoot ( "" , [] , [] ) [])
+  ]
diff --git a/test/xlsx-reader/numbers.xlsx b/test/xlsx-reader/numbers.xlsx
new file mode 100644
Binary files /dev/null and b/test/xlsx-reader/numbers.xlsx differ
diff --git a/test/xlsx-reader/strings.native b/test/xlsx-reader/strings.native
new file mode 100644
--- /dev/null
+++ b/test/xlsx-reader/strings.native
@@ -0,0 +1,67 @@
+Pandoc
+  Meta { unMeta = fromList [] }
+  [ Header 2 ( "sheet-1" , [] , [] ) [ Str "Strings" ]
+  , Table
+      ( "" , [] , [] )
+      (Caption Nothing [])
+      [ ( AlignDefault , ColWidthDefault )
+      , ( AlignDefault , ColWidthDefault )
+      ]
+      (TableHead
+         ( "" , [] , [] )
+         [ Row
+             ( "" , [] , [] )
+             [ Cell
+                 ( "" , [] , [] )
+                 AlignDefault
+                 (RowSpan 1)
+                 (ColSpan 1)
+                 [ Plain [ Str "Inline" ] ]
+             , Cell
+                 ( "" , [] , [] )
+                 AlignDefault
+                 (RowSpan 1)
+                 (ColSpan 1)
+                 [ Plain [ Str "Shared" ] ]
+             ]
+         ])
+      [ TableBody
+          ( "" , [] , [] )
+          (RowHeadColumns 0)
+          []
+          [ Row
+              ( "" , [] , [] )
+              [ Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "plain" , Space , Str "inline" ] ]
+              , Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "Hello" , Space , Str "world" ] ]
+              ]
+          , Row
+              ( "" , [] , [] )
+              [ Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain [ Str "Hello" , Space , Str "world" ] ]
+              , Cell
+                  ( "" , [] , [] )
+                  AlignDefault
+                  (RowSpan 1)
+                  (ColSpan 1)
+                  [ Plain
+                      [ Str "x" , Space , Str "=" , Space , Str "1" ]
+                  ]
+              ]
+          ]
+      ]
+      (TableFoot ( "" , [] , [] ) [])
+  ]
diff --git a/test/xlsx-reader/strings.xlsx b/test/xlsx-reader/strings.xlsx
new file mode 100644
Binary files /dev/null and b/test/xlsx-reader/strings.xlsx differ
