diff --git a/src/core/biblio.js b/src/core/biblio.js index 50a6933088..efee9bdc30 100644 --- a/src/core/biblio.js +++ b/src/core/biblio.js @@ -47,24 +47,23 @@ const REF_STATUSES = new Map([ ["WG-NOTE", "W3C Working Group Note"], ]); + + export function stringifyReference(ref) { if (typeof ref === "string") return ref; - var output = ""; + let output = `${ref.title}`; + if (ref.href) { + output = `${output}. `; + } if (ref.authors && ref.authors.length) { output += ref.authors.join("; "); if (ref.etAl) output += " et al"; - output += ". "; + output += "."; } if (ref.publisher) { - output += ref.publisher; - if (/\.$/.test(ref.publisher)) { - output += " "; - } else { - output += ". "; - } + const publisher = ref.publisher + (/\.$/.test(ref.publisher) ? "" : "."); + output = `${output} ${publisher} `; } - if (ref.href) output += `${ref.title}. `; - else output += `${ref.title}. `; if (ref.date) output += ref.date + ". "; if (ref.status) output += (REF_STATUSES.get(ref.status) || ref.status) + ". "; if (ref.href) output += `URL: ${ref.href}`; diff --git a/tests/spec/core/biblio-spec.js b/tests/spec/core/biblio-spec.js index 230a9394fb..c9c17b50a7 100644 --- a/tests/spec/core/biblio-spec.js +++ b/tests/spec/core/biblio-spec.js @@ -92,7 +92,7 @@ describe("W3C — Bibliographic References", function() { // Make sure publisher is shown even when there is no author ref = doc.querySelector("#bib-TestRef3 + dd"); expect(ref).toBeTruthy(); - expect(ref.textContent).toMatch(/^Publisher Here\.\s/); + expect(ref.textContent).toMatch(/Publisher Here\.\s/); }).then(done).catch(done); }); }); \ No newline at end of file