Skip to content

Commit bfcf9cb

Browse files
committed
feat(core/render-biblio): render pages field from bibliography entries
Closes #4067
1 parent a3d08f9 commit bfcf9cb

3 files changed

Lines changed: 28 additions & 18 deletions

File tree

src/core/render-biblio.js

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Module core/render-biblio
33
// renders the biblio data pre-processed in core/biblio
44

5-
import { addId, getIntlData, showError, toId } from "./utils.js";
5+
import { addId, getIntlData, showError, toId, xmlEscape } from "./utils.js";
66
import { biblio } from "./biblio.js";
77
import { html } from "./import-maps.js";
88

@@ -34,6 +34,12 @@ const localizationStrings = {
3434
references: "Referencias",
3535
reference_not_found: "Referencia no encontrada.",
3636
},
37+
fr: {
38+
info_references: "Références informatives",
39+
norm_references: "Références normatives",
40+
references: "Références",
41+
reference_not_found: "Référence non trouvée.",
42+
},
3743
ja: {
3844
info_references: "参照用参考文献",
3945
norm_references: "規範的参考文献",
@@ -69,8 +75,6 @@ const REF_STATUSES = new Map([
6975
["WD", "W3C Working Draft"],
7076
]);
7177

72-
const endWithDot = endNormalizer(".");
73-
7478
/** @param {Conf} conf */
7579
export function run(conf) {
7680
const informs = Array.from(conf.informativeReferences);
@@ -225,19 +229,6 @@ function showRef(reference) {
225229
return result;
226230
}
227231

228-
/**
229-
* @param {string} endStr
230-
* @returns {(str: string) => string}
231-
*/
232-
function endNormalizer(endStr) {
233-
return str => {
234-
const trimmed = str.trim();
235-
const result =
236-
!trimmed || trimmed.endsWith(endStr) ? trimmed : trimmed + endStr;
237-
return result;
238-
};
239-
}
240-
241232
/** @param {BiblioData|string} ref */
242233
function stringifyReference(ref) {
243234
if (typeof ref === "string") return ref;
@@ -259,7 +250,13 @@ function stringifyReference(ref) {
259250
}
260251
}
261252
if (ref.publisher) {
262-
output = `${output} ${endWithDot(ref.publisher)} `;
253+
const pub = ref.publisher.trim().replace(/\.$/, "");
254+
output += ` ${pub}`;
255+
if (ref.pages) output += `, pp. ${xmlEscape(ref.pages)}`;
256+
if (!output.endsWith(".")) output += ".";
257+
output += " ";
258+
} else if (ref.pages) {
259+
output += `pp. ${xmlEscape(ref.pages)}. `;
263260
}
264261
if (ref.date) output += `${ref.date}. `;
265262
if (ref.status) output += `${REF_STATUSES.get(ref.status) || ref.status}. `;

src/type-helper.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ interface BiblioData {
7878
href?: string;
7979
authors?: string[];
8080
publisher?: string;
81+
pages?: string;
8182
date?: string;
8283
rawDate?: string;
8384
isbn?: string;

tests/spec/core/biblio-spec.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ describe("W3C — Bibliographic References", () => {
3232
href: "http://test.com",
3333
publisher: "Publisher Here",
3434
},
35+
TestRef4: {
36+
title: "Fourth test",
37+
href: "http://test.com",
38+
publisher: "Publisher Pages",
39+
pages: "369-384",
40+
},
3541
FOOBARGLOP: {
3642
aliasOf: "BARBAR",
3743
},
@@ -48,7 +54,7 @@ describe("W3C — Bibliographic References", () => {
4854
const body = `
4955
<section id='sotd'>
5056
<p>[[DOM]] [[dom]] [[fetch]] [[?FeTcH]] [[FETCh]] [[fetCH]]
51-
<p>foo [[TestRef1]] [[TestRef2]] [[TestRef3]]</p>
57+
<p>foo [[TestRef1]] [[TestRef2]] [[TestRef3]] [[TestRef4]]</p>
5258
<p>[[EVERCOOKIE]]</p>
5359
</section>
5460
<section id='sample'>
@@ -144,6 +150,12 @@ describe("W3C — Bibliographic References", () => {
144150
expect(ref.textContent).toMatch(/Publisher Here\.\s/);
145151
});
146152

153+
it("displays the pages field when present", () => {
154+
const ref = doc.querySelector("#bib-testref4 + dd");
155+
expect(ref).toBeTruthy();
156+
expect(ref.textContent).toContain("pp. 369-384");
157+
});
158+
147159
it("resolves a localy-aliased spec", () => {
148160
const ref = doc.querySelector("#bib-foobarglop + dd");
149161
expect(ref).toBeTruthy();

0 commit comments

Comments
 (0)