Skip to content

Commit

Permalink
Update citeproc-js-based-replacer.js
Browse files Browse the repository at this point in the history
To fix #1
  • Loading branch information
kotobuki committed Apr 16, 2023
1 parent a65d777 commit 9035a9a
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions citeproc-js-based-replacer.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,22 @@ function replaceCitations(obj) {
} else if (typeof obj === "object" && obj !== null) {
if (obj.t === "Cite") {
return {
t: "Str",
c: formattedCitations.shift(),
t: "RawInline",
c: [
"markdown",
formattedCitations
.shift()
.trim()
.replace(/<i>/g, "*")
.replace(/<\/i>/g, "*")
.replace(/<div class="csl-entry">/g, "")
.replace(/<\/div>/g, "")
.replace(/&ndash;/g, "--")
.replace(/&mdash;/g, "---")
.replace(/&amp;/g, "&")
.replace(/&lt;/g, "<")
.replace(/&gt;/g, ">"),
],
};
} else {
return Object.fromEntries(
Expand Down Expand Up @@ -165,7 +179,7 @@ process.stdin.on("end", () => {
};

citeprocEngine = new citeproc.CSL.Engine(sys, style);
citeprocEngine.setOutputFormat("text");
citeprocEngine.setOutputFormat("html");

const citableItemIds = bibliography.map((item) => item.id);
debugLog(`citableItemIds: ${JSON.stringify(citableItemIds)}`);
Expand Down Expand Up @@ -213,7 +227,6 @@ process.stdin.on("end", () => {
);

if (bibliographyHeaderIndex >= 0) {
citeprocEngine.setOutputFormat("html");
const bibResult = citeprocEngine.makeBibliography();
const pandocBibResult = convertBibResultToPandoc(bibResult);
dataObj.blocks.splice(bibliographyHeaderIndex + 1, 0, ...pandocBibResult);
Expand Down

0 comments on commit 9035a9a

Please sign in to comment.