Skip to content

Fix BibTeX citation decoding HTML entities in the HTML appendix - #15212

Merged
cderv merged 3 commits into
mainfrom
fix-bibtex-entity-encoding
Oct 27, 2026
Merged

cderv merged 3 commits into
mainfrom
fix-bibtex-entity-encoding

Conversation

@cderv

@cderv cderv commented Oct 27, 2026

Copy link
Copy Markdown
Member

When a document title contains text that looks like an HTML entity, the BibTeX citation in the HTML appendix does not show the BibTeX Pandoc produced. R\&notebook displays as R\¬ebook, a\&lt;b as a\<b, and the copy button copies this altered text.

Root cause

The BibTeX is the plain text output of pandoc -t biblatex, but createCodeBlock inserted it with innerHTML, so the HTML parser decoded any & sequence forming an entity, including legacy ones without semicolon like &not. innerHTML comes from the original appendix block and the BibTeX string never carried markup. A < in the title is not affected as Pandoc writes it \textless.

Fix

createCodeBlock now sets the text content of the code block. The appendix BibTeX block is its only caller.

Setting text skips the HTML parser's newline normalization too, and Pandoc writes CRLF on Windows, so the text goes through normalizeNewlines to keep the LF line endings the block had. Rendering the 19 citation smoke-all documents with and without the change gives identical HTML, apart from the two titles with entity-like text.

createCodeBlock is also modified by #15209, which may need a small rebase depending on merge order.

Fixes #15210

Checklist

I have (if applicable):

  • referenced the GitHub issue this PR closes
  • updated the appropriate changelog in the PR
  • ensured the present test suite passes
  • added new tests
  • created a separate documentation PR in Quarto's website repo and linked it to this PR
AI-assisted PR
  • AI tool used: Claude Code
  • Codebase grounding: DeepWiki MCP, local clone
  • Human review: I have reviewed, tested, and verified the AI-generated content before submitting.

Note: autonomous AI agents submitting PRs without human oversight are not permitted — see the Code of Conduct.

@posit-snyk-bot

posit-snyk-bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Collaborator

✅ Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
✅ Open Source Security 0 0 0 0 0 issues
✅ Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

cderv added 3 commits October 27, 2026 16:28
The BibTeX block in the HTML appendix holds the plain-text output of
`pandoc -t biblatex`, but createCodeBlock assigned it to innerHTML. The
HTML parser then decoded any `&` sequence forming an entity: Pandoc's
`R\&notebook` displayed as `R\¬ebook` (legacy `&not` without
semicolon), `a\&lt;b` as `a\<b`, `x\&amp;nbsp;y` as `x\&nbsp;y`. The
copy button copied the same decoded text.

A raw `<` never reaches the parser because the biblatex writer emits
`\textless`, so `&` is the only trigger. innerHTML dates from the
original appendix DIV; the BibTeX string has never carried markup, and
the appendix block is createCodeBlock's only caller, so the helper now
sets textContent.

The existing entity-literals fixture now asserts the R\&notebook case.
Its `&amp;nbsp;` case only passed because title-casing turns it into the
non-entity `&Nbsp;`, so a new fixture covers `&lt;` and `&amp;nbsp;`
in words title-casing leaves alone.
Pandoc writes its biblatex output with CRLF on Windows. innerHTML went
through the HTML parser, which normalizes CRLF to LF; textContent keeps
the carriage returns, so the rendered page had CRLF lines inside the
BibTeX block and LF everywhere else. Browsers normalize again on load,
so display and copy were unaffected, but the output file bytes changed.

normalizeNewlines splits on the same `\r\n?|\n` set as the HTML parser,
so the block's text is now byte-identical to the innerHTML result for
any BibTeX without `&` entity sequences: rendering the 19 citation
smoke-all fixtures with and without the change differs only in the two
entity-literal titles.
@cderv
cderv force-pushed the fix-bibtex-entity-encoding branch from cd94f7a to 04e8bac Compare October 27, 2026 15:34
@cderv
cderv merged commit eb1c5db into main Oct 27, 2026
52 checks passed
@cderv
cderv deleted the fix-bibtex-entity-encoding branch October 27, 2026 16:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BibTeX citation in the HTML appendix decodes HTML entities from the Pandoc output

2 participants