Skip to content

Commit 8efdd7d

Browse files
cdervclaude
andcommitted
Fix false citeproc warning from @ in book metadata URLs
URLs with @ (e.g. https://mastodon.online/@user) in book navbar config caused false `[WARNING] Citeproc: citation not found` warnings because Pandoc parses YAML metadata strings as Markdown. Book metadata can't be deleted like website/about since {{< meta book.* >}} shortcodes depend on it. Escape @ to HTML entity &#64; which Pandoc resolves back to @ in the AST before templates and shortcodes see it. Fixes #12136 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 4c60a3e commit 8efdd7d

5 files changed

Lines changed: 62 additions & 0 deletions

File tree

‎src/command/render/pandoc.ts‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1339,6 +1339,13 @@ export async function runPandoc(
13391339
}
13401340
}
13411341

1342+
// Escape @ in book metadata to prevent false citeproc warnings (#12136).
1343+
// Book metadata can't be deleted like website/about because {{< meta book.* >}}
1344+
// shortcodes depend on it. Pandoc resolves &#64; back to @ in the AST.
1345+
if (pandocPassedMetadata.book) {
1346+
pandocPassedMetadata.book = escapeAtInMetadata(pandocPassedMetadata.book);
1347+
}
1348+
13421349
Deno.writeTextFileSync(
13431350
metadataTemp,
13441351
stringify(pandocPassedMetadata, {
@@ -1833,3 +1840,21 @@ function resolveTextHighlightStyle(
18331840
}
18341841
return extras;
18351842
}
1843+
1844+
// deno-lint-ignore no-explicit-any
1845+
function escapeAtInMetadata(value: any): any {
1846+
if (typeof value === "string") {
1847+
return value.replaceAll("@", "&#64;");
1848+
}
1849+
if (Array.isArray(value)) {
1850+
return value.map(escapeAtInMetadata);
1851+
}
1852+
if (value !== null && typeof value === "object") {
1853+
const result: Record<string, unknown> = {};
1854+
for (const [k, v] of Object.entries(value)) {
1855+
result[k] = escapeAtInMetadata(v);
1856+
}
1857+
return result;
1858+
}
1859+
return value;
1860+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/.quarto/
2+
**/*.quarto_ipynb
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
project:
2+
type: book
3+
4+
book:
5+
title: "Test Issue 12136"
6+
navbar:
7+
right:
8+
- icon: mastodon
9+
href: https://mastodon.online/@testuser
10+
chapters:
11+
- index.qmd
12+
13+
bibliography: references.bib
14+
15+
format:
16+
html: default
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
title: "Test"
3+
_quarto:
4+
tests:
5+
html:
6+
printsMessage:
7+
level: INFO
8+
regex: 'Citeproc: citation'
9+
negate: true
10+
---
11+
12+
# Test {.unnumbered}
13+
14+
No false citeproc warnings from @ in book navbar URLs.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@misc{example,
2+
author = {Test Author},
3+
title = {Example},
4+
year = {2024}
5+
}

0 commit comments

Comments
 (0)