Skip to content

Commit eb1c5db

Browse files
authored
Fix BibTeX citation decoding HTML entities in the HTML appendix (#15212)
The appendix BibTeX block was inserted as HTML, so the parser decoded entity-like text in the Pandoc output: R\&notebook showed as R\¬ebook and a\&lt;b as a\<b. The block now holds the text as Pandoc wrote it, with LF line endings, and the copy button copies the same text. - Set the BibTeX block with textContent in createCodeBlock, and normalize newlines to LF - Add regression fixtures for entity-like text in titles Fixes #15210 See #15209
1 parent 4906587 commit eb1c5db

4 files changed

Lines changed: 26 additions & 4 deletions

File tree

‎news/changelog-1.11.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ All changes included in 1.11:
8383
- ([#15128](https://github.com/quarto-dev/quarto-cli/pull/15128)): Fix Google Scholar metadata missing references with a YAML bibliography not wrapped in `---` delimiters.
8484
- ([#15131](https://github.com/quarto-dev/quarto-cli/issues/15131)): Fix the light/dark toggle appearing, with no dark styles to switch to, when the `dark` brand file holds only comments and is ignored.
8585
- ([#15207](https://github.com/quarto-dev/quarto-cli/issues/15207)): Fix the BibTeX citation in the HTML appendix showing a copy button that does nothing when `code-copy: false` is set.
86+
- ([#15210](https://github.com/quarto-dev/quarto-cli/issues/15210)): Fix the BibTeX citation in the HTML appendix showing and copying altered text when the title contains text that looks like an HTML entity, such as `&lt;` or `R&notebook`.
8687

8788
### `pdf`
8889

‎src/format/html/format-html-shared.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import { Document, Element } from "../../core/deno-dom.ts";
3030
import { normalizePath } from "../../core/path.ts";
3131
import { formatHasBootstrap } from "./format-html-info.ts";
3232
import { HtmlFormatFeatureDefaults } from "./format-html-types.ts";
33+
import { normalizeNewlines } from "../../core/text.ts";
3334

3435
// features that are enabled by default for 'html'. setting
3536
// all of these to false will yield the minimal html output
@@ -516,7 +517,7 @@ export function createCodeCopyButton(doc: Document, format: Format) {
516517

517518
export function createCodeBlock(
518519
doc: Document,
519-
htmlContents: string,
520+
text: string,
520521
language?: string,
521522
) {
522523
const preEl = doc.createElement("PRE");
@@ -527,7 +528,7 @@ export function createCodeBlock(
527528
if (language) {
528529
codeEl.classList.add(language);
529530
}
530-
codeEl.innerHTML = htmlContents;
531+
codeEl.textContent = normalizeNewlines(text);
531532
preEl.appendChild(codeEl);
532533
return preEl;
533534
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
title: 'Tags a&amp;lt;b and x&amp;amp;nbsp;y'
3+
author: Jane Doe
4+
date: 2025-04-30
5+
citation: true
6+
appendix-cite-as: [bibtex]
7+
format: html
8+
_quarto:
9+
tests:
10+
html:
11+
ensureFileRegexMatches:
12+
- ['title = \{Tags a\\&amp;lt;b and x\\&amp;amp;nbsp;y\}']
13+
# Pandoc writes CRLF on Windows; the block must keep LF line endings
14+
- ['\r']
15+
---
16+
17+
The BibTeX appendix block shows the Pandoc biblatex output as text. The title text `a&lt;b` becomes `a\&lt;b` in BibTeX and must not display as `a\<b`; `x&amp;nbsp;y` becomes `x\&amp;nbsp;y` and must not display as `x\&nbsp;y`. These words are not title-cased, so the entity-like sequences stay intact.
18+
19+
Pandoc writes the BibTeX with CRLF line endings on Windows; the block keeps LF line endings like the rest of the page.

‎tests/docs/smoke-all/2026/10/16/citation-title/entity-literals.qmd‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ _quarto:
1616
matches: ['“Literal &Nbsp; and &Notanentity; and\s+R&notebook and &#123\.”']
1717
noMatches: [" "]
1818
ensureFileRegexMatches:
19-
# BibTeX title; R&notebook is not asserted there because the block is inserted as HTML, which decodes &not
20-
- ['title = \{Literal \\&amp;Nbsp; and \\&amp;Notanentity; and', '\\&amp;\\#123\}']
19+
# BibTeX title; R\&notebook must not have its legacy &not decoded to ¬
20+
- ['title = \{Literal \\&amp;Nbsp; and \\&amp;Notanentity; and', 'R\\&amp;notebook', '\\&amp;\\#123\}']
21+
- ['R\\¬ebook']
2122
---
2223

2324
Text that only looks like an HTML entity stays literal in the appendix citation, the BibTeX citation and the Google Scholar metadata: an escaped `&amp;nbsp;` is the text `&nbsp;`, not a no-break space, and an unknown entity or an incomplete reference is not decoded.

0 commit comments

Comments
 (0)