`include-before-body` and `include-after-body` have no effect for docx output

Offen
#15,403 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Anfängerfreundlichkeit
58/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
javascript, lua
Bereich
backend

Rechercherichtung

Start with src/resources/filters/quarto-init/includes.lua and src/resources/filters/common/meta.lua, which the issue links to, and trace how include content becomes a raw block for docx. Check the existing tests for docx includes, then reproduce with the provided before.xml and after.xml example. Done means both markers appear in word/document.xml for include-before-body and include-after-body.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

bug docx

I have:

  • searched the issue tracker for similar issues
  • installed the latest version of Quarto CLI
  • formatted my issue following the Bug Reports guide

Bug description

Since Pandoc 3.2.1, --include-before-body and --include-after-body work with docx: the files are OpenXML fragments inserted in the document body. With Quarto, their content never reaches word/document.xml. The same happens with text in include-before and include-after.

Quarto reads include files in a Lua filter and adds their content to the metadata as a raw block, with FORMAT as the raw format:

https://github.com/quarto-dev/quarto-cli/blob/cda41021442b20964e10e265b9dcdf81f490c18e/src/resources/filters/quarto-init/includes.lua#L44-L61

https://github.com/quarto-dev/quarto-cli/blob/cda41021442b20964e10e265b9dcdf81f490c18e/src/resources/filters/common/meta.lua#L32-L40

For docx, FORMAT is docx, so the raw block is RawBlock("docx", ...). Pandoc's docx writer only keeps raw openxml and drops the rest. A markdown document with both a ```{=docx} and a ```{=openxml} block shows it: only the openxml one is in the output.

Steps to reproduce

before.xml:

<w:p><w:r><w:t>MARKER-BEFORE</w:t></w:r></w:p>

after.xml:

<w:p><w:r><w:t>MARKER-AFTER</w:t></w:r></w:p>

doc.qmd:

---
title: Hello
format:
  docx:
    include-before-body: before.xml
    include-after-body: after.xml
---

Body text.
quarto render doc.qmd
unzip -p doc.docx word/document.xml | grep -o 'MARKER-[A-Z]*'

Actual behavior

No output: neither paragraph is in word/document.xml. Same with include-before: '<w:p>...</w:p>' and include-after: in YAML.

Expected behavior

Both paragraphs are in the document, like with Pandoc directly:

quarto pandoc -f markdown -t docx --include-before-body before.xml --include-after-body after.xml -o p.docx doc.qmd
unzip -p p.docx word/document.xml | grep -o 'MARKER-[A-Z]*'
# MARKER-BEFORE
# MARKER-AFTER

A post-render Lua filter that changes the format of these raw blocks in include-before to openxml makes the paragraph appear, and the result opens in Word. We could use openxml as the raw format for docx when adding includes.

Your environment

  • OS: Windows 11
  • Same result with Quarto 1.11.9, 1.12.3, and main at cda4102 (Pandoc 3.13). Not a regression as far as I can tell.

Related: #15399

Vorherrschende Sprache
JavaScript
Sterne
6.2k
Forks
492
Ø Merge
15 Std. 15 Min.
Gemergte PRs (30 T.)
94

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus quarto-dev/quarto-cli

Alle Issues in quarto-dev/quarto-cli

Ähnliche Issues

Weitere Issues zu JavaScript

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.