diff --git a/src/generator.js b/src/generator.js index 5b0ebaf..e3bf382 100644 --- a/src/generator.js +++ b/src/generator.js @@ -73,7 +73,7 @@ const rehypeCitationGenerator = (Cite) => { } } } - const citations = new Cite(bibtexFile, {generateGraph: false}); + const citations = new Cite(bibtexFile, {generateGraph: false}) const citationIds = citations.data.map((x) => x.id) const citationPre = [] const citationDict = {} @@ -82,7 +82,7 @@ const rehypeCitationGenerator = (Cite) => { /** @type {Mode} */ const mode = citeproc.opt.xclass const citationFormat = getCitationFormat(citeproc) - + let parsedEntries = [] visit(tree, 'text', (node, idx, parent) => { const match = node.value.match(citationRE) if (!match || ('tagName' in parent && !permittedTags.includes(parent.tagName))) return @@ -105,6 +105,7 @@ const rehypeCitationGenerator = (Cite) => { } const [entries, isComposite] = parseCitation(match) + parsedEntries = entries // If id is not in citation file (e.g. route alias or js package), abort process for (const citeItem of entries) { @@ -146,11 +147,17 @@ const rehypeCitationGenerator = (Cite) => { ] }) + if (noCite) { if (noCite.length === 1 && noCite[0] === '@*') { citeproc.updateItems(citationIds) } else { - citeproc.updateItems(noCite.map((x) => x.replace('@', ''))) + const mergedIds = citations.data + .filter((x) => noCite.map((x) => x.replace('@', '')).includes(x['citation-key'])) + .map((x) => x.id) + .concat(parsedEntries.map((x) => x.id)) + + citeproc.updateItems(mergedIds) } } diff --git a/test/index.js b/test/index.js index 6cd3e95..4700771 100644 --- a/test/index.js +++ b/test/index.js @@ -168,6 +168,18 @@ rehypeCitationTest('no-cite', async () => { ` assert.is(result, expected) }) ++ +rehypeCitationTest('no-cite citations must be added to template citations', async () => { + const result = await processHtml('
[@Nash1950]
', { + noCite: ['@Nash1951'], + }) + const expected = dedent`
(Nash, 1950)
+
Nash, J. (1950). Equilibrium points in n-person games. Proceedings of the National Academy of Sciences, 36(1), 48–49.
+
Nash, J. (1951). Non-cooperative games. Annals of Mathematics, 286–295.
+
` + assert.is(result, expected) +}) + rehypeCitationTest('no-cite catch all', async () => { const result = await processHtml('
text
', {