Support `template-partials` for docx output
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Aptitud para principiantes
- 35/100
- Tipo de issue
- Nueva funcionalidad
- Claridad
- Bastante claro
- Estado de actividad
- Activo
- Stack tecnológico
- javascript, openapi
- Área
- documentation
Línea de trabajo
Start with src/command/render/pandoc.ts around the reported template-partials check and src/format/docx/format-docx.ts; compare the Typst setup at src/format/typst/format-typst.ts. The proposal also names package/src/common/update-pandoc.ts, dev-docs/update-pandoc-checklist.md, and the updating-pandoc skill. Done means docx partials can be used while preserving current document.xml output and the template update and documentation paths are covered.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Following some discussion with 🤖
template-partials works for html, revealjs, pdf, beamer and typst, but not for docx. Since Pandoc 3.2.1, the docx writer has an OpenXML template for the body of the document (word/document.xml), and plain Pandoc resolves partials in it. Quarto passes a user template: to Pandoc for docx, but refuses template-partials.
What works today
quarto pandoc -D docx prints Pandoc's default.openxml: one w:p each for title, subtitle, authors, date and abstract (with variables like $title-style-id$), then include-before, toc, lof, lot, body, include-after and sectpr.
A copy of it given as format: docx: template: tpl.openxml is used by Quarto, and Pandoc finds a partial placed next to it ($logo-block.openxml()$ with logo-block.openxml in the same directory). This is what https://github.com/mcanouil/quarto-better-word does with its title-block.xml and toc.xml partials.
Metadata reaches the template as OpenXML runs: institute: NSO used as $institute$ gives <w:r><w:t xml:space="preserve">NSO</w:t></w:r>, so it must be placed inside a w:p. Quarto's normalized by-author and labels are available too ($it.name.literal$, affiliations, $labels.abstract$). An image in metadata (logo: "{width=1cm}") used as $logo$ is embedded in the package.
What fails
---
title: Hello
format:
docx:
template: tpl.openxml
template-partials:
- logo-block.openxml
---
Body text.
ERROR: The format docx does not support providing any template partials.
The error comes from the else branch for formats without a templateContext. docx declares none, so partials are refused even when the user gives a template.
Use case
I wrote an example where one document renders to HTML, Typst and Word with the same title block and a logo. HTML needed a 21-line title-block.html partial and Typst an override of article(). For Word there was no hook in the body, so the logo went into a page header of a reference document built by a script (source). A title-block partial for docx would have been enough for that part.
Proposal
We could support docx the way Typst and LaTeX do: Quarto keeps its own copy of Pandoc's template, split into named partials, and format-docx.ts declares a templateContext.
Design questions, with what I think for each:
-
Minimal change or full support ? Accepting
template-partialswhenever the user gives atemplatewould not bring much for docx, as a user template already finds partials next to it. Full support is what lets a user override only the title block. One thing to handle: when a format has atemplateContext, Quarto copies the user template into a temporary directory, and sibling partials are no longer found. Withformat: htmland atemplate.htmlcalling$foo.html()$next to it, render fails withCould not find data file 'templates\foo.html'. If docx gets atemplateContext, templates written for today's behavior (like the extension above) would break the same way. We could keep passing a usertemplateto Pandoc unstaged when notemplate-partialsis given, or copy its directory. Open. -
Partials and names. Following
title-block.htmland LaTeX'stoc.tex,before-body.tex,after-body.tex:template.openxml: the orchestrator;title-block.openxml: title, subtitle, authors, date, abstract;toc.openxml:toc,lof,lot;before-body.openxmlandafter-body.openxml: empty, aroundbody.
Whether
sectprgets its own partial (page size and margins, see #11163 and #12917) is open. The first version should produce the samedocument.xmlas today. -
File extension. Quarto stages the main template as
template.patched, so Pandoc's rule that a partial without extension takes the extension of the template does not apply.$foo()$in a user HTML template fails withCould not find data file 'templates\foo.patched'. Quarto templates call partials with an explicit extension, so the extension is only a naming choice..openxmlmatches Pandoc'sdefault.openxml. User partials replace built-in ones by file name, sotitle-block.xmlwould not replacetitle-block.openxml: the docs need to say it. -
Maintenance. The writer and the template are coupled:
default.openxmlchanged five times since 3.2.1, including the switch to style ids ($title-style-id$) in Pandoc 3.6.1 (jgm/pandoc#10282). An outdated Quarto copy would give wrong styles without an error. So:package/src/common/update-pandoc.ts: copydefault.openxmlassrc/resources/formats/docx/pandoc/openxml.template, next to Quarto'stemplate.openxmland partials (same naming as other formats);dev-docs/update-pandoc-checklist.md: a Docx entry in the template list;- the
updating-pandocskill: add docx to the template port step, and anllm-docspage like the Typst and LaTeX ones.
-
Interactions.
- Title block: Quarto does not write its own title block for docx today, Pandoc's template does it from metadata. Quarto's author normalization only sets variables, so moving the title block into a partial changes nothing by itself. Showing affiliations like the other formats could come later (they are dropped today, see #14435).
- Books: a docx book renders to a single document with one title block from
book:metadata. A two-chapter book withtemplate:uses it once, with a sibling partial resolved, andtemplate-partialsfails with the same error. Partials would apply to the whole book, nothing book-specific is needed. - Extensions: a docx format extension can set
template:today (see item 1). With full support, it could also shiptemplate-partials, like Typst and LaTeX extensions do. include-before-bodyfiles have no effect for docx in Quarto, unlike plain Pandoc. This is a separate bug, I'll open its own issue.
-
Documentation: the template partials page on quarto.org (https://quarto.org/docs/journals/templates.html) lists formats and their partials, docx would be added there, with a note that partials are OpenXML fragments and that variables are runs to place inside a
w:p.
Checked
Checked on main at cda4102 with Pandoc 3.13, on Windows. Outputs with a custom template, a partial and an embedded image opened in Word 16.0 (Microsoft 365) without errors. Not checked on Linux or macOS.
Related: #14695 (discussion asking for docx templates), #4511, #11014 and #6114 (title or cover page for Word), #15381 (_brand.yml for docx).
- Lenguaje dominante
- JavaScript
- Estrellas
- 6.2k
- Forks
- 492
- Merge medio
- 15 h 15 min
- PR fusionados (30 d)
- 94
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de quarto-dev/quarto-cli
-
bootstrap enhancement themes
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
quarto-dev/quarto-cli#15421 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 85/100
quarto-dev/quarto-cli#15408 ·
Los mantenedores suelen responder en 1 día
-
accessibility bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 79/100
quarto-dev/quarto-cli#15401 · 1 reacción ·
Los mantenedores suelen responder en 1 día
-
bug callouts docx regression
Dificultad 2/5 1-3 horas Aptitud para principiantes 81/100
quarto-dev/quarto-cli#15394 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
-
bug lightbox
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
quarto-dev/quarto-cli#15393 ·
Los mantenedores suelen responder en 1 día
Todos los issues de quarto-dev/quarto-cli
Issues similares
-
bug help wanted
Dificultad 2/5 1-3 horas Aptitud para principiantes 80/100
LangerSword/gitone#7 ·
-
good first issue reliability security should-have
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 13 días
-
[BUG]: chunkSource protocol stripping truncates URLs or reads an inner schemePosiblemente ocupada @Bensonbenyi la tomó hoy. Abierto
Dificultad 1/5 Menos de una hora Aptitud para principiantes 88/100
Mintplex-Labs/anything-llm#7338 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
Los mantenedores suelen responder en 1 día