Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/core/render-biblio.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,18 @@ function stringifyReference(ref) {

output = ref.href ? `<a href="${ref.href}">${output}</a>. ` : `${output}. `;

if (ref.authors && ref.authors.length) {
output += ref.authors.join("; ");
if (ref.etAl) output += " et al";
if (!output.endsWith(".")) output += ". ";
if (ref.authors) {
if (!Array.isArray(ref.authors)) {
const msg = `The "authors" field in reference "${ref.id || ref.title}" must be an array.`;
const hint = `Use \`authors: [${JSON.stringify(ref.authors)}]\` instead of \`authors: ${JSON.stringify(ref.authors)}\`.`;
showError(msg, name, { hint });
ref.authors = [ref.authors];
}
if (ref.authors.length) {
output += ref.authors.join("; ");
if (ref.etAl) output += " et al";
if (!output.endsWith(".")) output += ". ";
}
}
if (ref.publisher) {
output = `${output} ${endWithDot(ref.publisher)} `;
Expand Down
28 changes: 28 additions & 0 deletions tests/spec/core/biblio-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,34 @@ describe("W3C — Bibliographic References", () => {
expect(refs).toHaveSize(1);
expect(refs[0].textContent).toBe("[dom]");
});

it("handles authors as a string instead of array", async () => {
const body = `
<section id="conformance">
<p>[[StringAuthorRef]]</p>
</section>
`;
const localBiblio = {
StringAuthorRef: {
title: "String Author Test",
href: "https://example.com",
authors: "Jane Doe",
},
};
const ops = makeStandardOps({ localBiblio }, body);
const doc = await makeRSDoc(ops);

const ref = doc.querySelector("#bib-stringauthorref + dd");
expect(ref).toBeTruthy();
expect(ref.textContent).toContain("Jane Doe");

const errors = doc.respec.errors.filter(
e => e.plugin === "core/render-biblio" && e.message.includes('"authors"')
);
expect(errors).toHaveSize(1);
expect(errors[0].message).toContain("must be an array");
expect(errors[0].hint).toContain('authors: ["Jane Doe"]');
});
});

it("makes sure references section has expected localization text", async () => {
Expand Down
Loading