Skip to content

fix: propagate #| filename: from DecoratedCodeBlock to inner CodeBlock#31

Merged
mcanouil merged 2 commits intomainfrom
fix/decorated-codeblock-filename-propagation
Apr 21, 2026
Merged

fix: propagate #| filename: from DecoratedCodeBlock to inner CodeBlock#31
mcanouil merged 2 commits intomainfrom
fix/decorated-codeblock-filename-propagation

Conversation

@mcanouil
Copy link
Copy Markdown
Owner

When filename is set via the #| filename: Quarto chunk option, Quarto stores the value in its internal custom node registry and wraps the CodeBlock in a DecoratedCodeBlock Div, leaving the inner CodeBlock without a filename attribute. The pre-quarto filter saw no explicit filename and fell back to auto-filename.

In HTML this caused a double .code-with-filename wrapper: one created by Quarto from #| filename: and a second created by the extension's injected JavaScript for the auto-filename. In Typst the code-window wrapper showed the auto-generated language name instead of the user-specified filename.

The fix reads the filename from _quarto.ast.custom_node_data via the __quarto_custom_id attribute present on every DecoratedCodeBlock Div. For Typst the transfer happens in the existing DecoratedCodeBlock branch of process_typst_blocks. For HTML a new Pandoc filter branch runs fix_html_decorated_filenames before the CodeBlock filter, so process_html sees the explicit filename and skips auto-filename.

The {.r filename="..."} Pandoc attribute syntax is unaffected.

When filename is set via the #| filename: Quarto chunk option, Quarto
stores the value in its internal custom node registry and wraps the
CodeBlock in a DecoratedCodeBlock Div, leaving the inner CodeBlock
without a filename attribute. The pre-quarto filter saw no explicit
filename and fell back to auto-filename, causing two problems:

- HTML: auto-filename set the language name as filename, which the
  injected JS then used to create a second .code-with-filename wrapper
  alongside the one Quarto already created from #| filename:.
- Typst: the code-window wrapper used the auto-generated language name
  instead of the user-specified filename.

Fix by reading the filename from _quarto.ast.custom_node_data via the
__quarto_custom_id attribute on the DecoratedCodeBlock Div. For Typst
the transfer happens in the existing DecoratedCodeBlock branch of
process_typst_blocks. For HTML a new Pandoc filter branch runs
fix_html_decorated_filenames before the CodeBlock filter, so
process_html sees the explicit filename and skips auto-filename.
@mcanouil mcanouil added the Type: Bug 🐛 Issues related to bugs, errors, or mistakes label Apr 21, 2026
@mcanouil mcanouil self-assigned this Apr 21, 2026
@mcanouil mcanouil merged commit 7a91c8f into main Apr 21, 2026
@mcanouil mcanouil deleted the fix/decorated-codeblock-filename-propagation branch April 21, 2026 14:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Type: Bug 🐛 Issues related to bugs, errors, or mistakes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant