Skip to content

Commit 5001d8b

Browse files
authored
Fix Google Scholar render failure with a CSL JSON bibliography (#15125)
With google-scholar enabled, rendering a document that cites from a CSL JSON bibliography (.json) failed with "JSON parse error: Error in $: mempty". The Scholar metadata ran `pandoc <file> -t csljson` without an input format, so pandoc read the .json file as its own JSON AST. Pass `-f csljson` for .json bibliographies. The conversion dates back to v1.4, so this affected every Scholar render with a CSL JSON bibliography. The per-page tags and the book references page both go through it. See #15118
1 parent f93239c commit 5001d8b

4 files changed

Lines changed: 31 additions & 1 deletion

File tree

‎news/changelog-1.11.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ All changes included in 1.11:
6464
- ([#15108](https://github.com/quarto-dev/quarto-cli/pull/15108)): Fix Google Scholar metadata showing formatting markup such as `<i>` in `citation_reference` tags for bibliography entries, and `undefined` as the book title of a chapter without one.
6565
- ([#15115](https://github.com/quarto-dev/quarto-cli/pull/15115)): Fix Google Scholar writing two `citation_reference` tags for a reference defined in two bibliography files. The tag now describes the entry Pandoc renders.
6666
- ([#15118](https://github.com/quarto-dev/quarto-cli/pull/15118)): Fix Google Scholar metadata missing the first and last page of bibliography entries, and giving wrong pages for a citation `page` written with an en-dash or as a page list.
67+
- ([#15125](https://github.com/quarto-dev/quarto-cli/pull/15125)): Fix Google Scholar metadata failing the render with a CSL JSON (`.json`) bibliography.
6768

6869
### `pdf`
6970

‎src/core/bibliography.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Adapted from: https://github.com/watson/ci-info
88
*/
99

10-
import { dirname, isAbsolute, join } from "../deno_ral/path.ts";
10+
import { dirname, extname, isAbsolute, join } from "../deno_ral/path.ts";
1111
import { kBibliography } from "../config/constants.ts";
1212
import { Metadata } from "../config/types.ts";
1313
import { asArray } from "./array.ts";
@@ -85,6 +85,11 @@ export async function renderToCSLJSON(
8585
// in which case just leave it alone (otherwise it is cwd relative)
8686
const biblioPath = join(dir, biblio);
8787
const cmd = [pandocBinaryPath()];
88+
// Without -f, pandoc reads a .json input as its own JSON AST
89+
if (extname(biblioPath).toLowerCase() === ".json") {
90+
cmd.push("-f");
91+
cmd.push("csljson");
92+
}
8893
cmd.push(
8994
isAbsolute(biblioPath) ? biblioPath : join(Deno.cwd(), biblioPath),
9095
);
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
title: Scholar metadata for a CSL JSON bibliography
3+
format: html
4+
google-scholar: true
5+
bibliography: references.json
6+
_quarto:
7+
tests:
8+
html:
9+
ensureHtmlElements:
10+
- ['meta[name="citation_reference"][content*="citation_author=Alice Smith;"]']
11+
---
12+
13+
The bibliography is a CSL JSON file. Pandoc reads a bare `.json` input as its own JSON AST, so the Scholar reference tags need the bibliography read explicitly as CSL JSON.
14+
15+
This article cites one work [@cited].
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[
2+
{
3+
"id": "cited",
4+
"type": "article-journal",
5+
"title": "Cited reference",
6+
"author": [{ "family": "Smith", "given": "Alice" }],
7+
"issued": { "date-parts": [[2024]] }
8+
}
9+
]

0 commit comments

Comments
 (0)