Files
John MacFarlane 1c7cfb2a2a OpenDocument/ODT writer: use predefined styles. (#11672)
Previously the OpenDocument writer emitted a fresh automatic style
(L1..Ln, P1..Pn, T1..Tn) for nearly every list, list-item paragraph,
block quote, preformatted block, and inline text style.  This produced
large ODT files, made `--reference-doc` customization ineffective (the
user's predefined styles were never referenced), and gave each list its
own indentation independent of any containing block quote.

This commit teaches the writer to reference the predefined styles that
LibreOffice ships and that pandoc's reference.odt now exports:

- Bullet lists use `List_20_1`; ordered lists with default start and
  decimal format use `Numbering_20_1`.  Non-default ordered lists
  generate a single named override style (`Pandoc_Numbering_N`)
  memoised by (ListNumberStyle, ListNumberDelim); a non-default start
  value with the default format is expressed via `text:start-value`
  on the `text:list` element instead of a new style.
- List-item paragraphs use `List_20_Bullet[_Tight]` and
  `List_20_Number[_Tight]`.  The Tight variants are pandoc-specific
  (zero top/bottom margin) and are injected into the user's
  reference.odt if missing, just like the Skylighting token styles.
- Block quotes use the predefined `Quotations` paragraph style
  directly.  Nested block quotes use a single automatic style that
  inherits from Quotations and only adds extra margin-left, so a list
  inside a block quote now inherits its container's indent (#2747).
- Preformatted blocks use `Preformatted_20_Text` directly.
- Emphasis, Strong, Strikeout, Subscript, Superscript and Code spans
  use the predefined `Emphasis`, `Strong_20_Emphasis`, `Strikeout`,
  `Subscript`, `Superscript` and `Source_20_Text` text styles.
- `paraStyle`/`paraStyleFromParent` no longer emit a wrapper automatic
  style when its only attribute would be `parent-style-name`; the
  parent name is returned directly.

Closes #9136.
Closes #5086.
Closes #2747.
Closes #3426.
Closes #7336.

Co-authored by: Claude Opus 4.7.
2026-05-27 17:35:39 +02:00

2.4 KiB

Verify that the OpenDocument writer uses predefined list, paragraph, and text styles instead of generating per-instance automatic styles.

% pandoc -t opendocument
- one
- two

1. ordered one
2. ordered two

Some *italic*, **bold**, ~~strike~~, and `code`.

> A block quote.

Final paragraph.
^D
<text:list text:style-name="List_20_1">
  <text:list-item>
    <text:p text:style-name="List_20_Bullet_20_Tight">one</text:p>
  </text:list-item>
  <text:list-item>
    <text:p text:style-name="List_20_Bullet_20_Tight">two</text:p>
  </text:list-item>
</text:list>
<text:list text:style-name="Numbering_20_1">
  <text:list-item>
    <text:p text:style-name="List_20_Number_20_Tight">ordered
    one</text:p>
  </text:list-item>
  <text:list-item>
    <text:p text:style-name="List_20_Number_20_Tight">ordered
    two</text:p>
  </text:list-item>
</text:list>
<text:p text:style-name="First_20_paragraph">Some
<text:span text:style-name="Emphasis">italic</text:span>,
<text:span text:style-name="Strong_20_Emphasis">bold</text:span>,
<text:span text:style-name="Strikeout">strike</text:span>, and
<text:span text:style-name="Source_20_Text">code</text:span>.</text:p>
<text:p text:style-name="Quotations">A block quote.</text:p>
<text:p text:style-name="First_20_paragraph">Final paragraph.</text:p>

A non-default ordered list (start value other than 1, or non-decimal format) generates a single named override style, not one per instance.

% pandoc -t opendocument
A) upper-alpha one
B) upper-alpha two

5. start at five
6. and continue
^D
<text:list text:style-name="Pandoc_5f_Numbering_5f_1">
  <text:list-item>
    <text:p text:style-name="List_20_Number_20_Tight">upper-alpha
    one</text:p>
  </text:list-item>
  <text:list-item>
    <text:p text:style-name="List_20_Number_20_Tight">upper-alpha
    two</text:p>
  </text:list-item>
</text:list>
<text:list text:style-name="Numbering_20_1" text:start-value="5">
  <text:list-item>
    <text:p text:style-name="List_20_Number_20_Tight">start at
    five</text:p>
  </text:list-item>
  <text:list-item>
    <text:p text:style-name="List_20_Number_20_Tight">and
    continue</text:p>
  </text:list-item>
</text:list>

A nested block quote uses the predefined Quotations style for the outer paragraph, and inherits indent from it for the inner paragraph.

% pandoc -t opendocument
> First.
>
> > Nested.
^D
<text:p text:style-name="Quotations">First.</text:p>
<text:p text:style-name="P1">Nested.</text:p>