summaryrefslogtreecommitdiff
path: root/biblio.js
diff options
context:
space:
mode:
Diffstat (limited to 'biblio.js')
-rw-r--r--biblio.js76
1 files changed, 76 insertions, 0 deletions
diff --git a/biblio.js b/biblio.js
new file mode 100644
index 0000000..0e4daae
--- /dev/null
+++ b/biblio.js
@@ -0,0 +1,76 @@
+/**
+ * Load the No.6092 datasheet into the OKCMS JSON
+ */
+
+import { loadJSON, loadCSV, writeJSON, writeFile } from "./file_utils.js";
+import { readdir } from "fs/promises";
+import parseRTF from "rtf-parser";
+import fs from "fs";
+import sizeOf from "image-size";
+
+async function main() {
+ const bib = {};
+ await loadText("./data_store/biblio.rtf", bib);
+ await writeFile("./biblio.html", bib.text);
+}
+
+/**
+ * Load the text from an RTF
+ */
+async function loadText(path, bib) {
+ // const warn = path.match("McCurry", "i");
+ return new Promise((resolve, reject) => {
+ parseRTF.stream(fs.createReadStream(path), (err, doc) => {
+ // Separate paragraphs from spans since this library doesn't handle
+ // the last paragraph correctly.
+ const paragraphs = doc.content.filter((para) => para.content);
+ const finalParagraph = doc.content.filter((para) => !para.content);
+ let content = "";
+
+ paragraphs.forEach((para, paragraphIndex) => {
+ const paragraph = [];
+ para.content.forEach((clip) => {
+ appendClip(paragraph, clip);
+ });
+ const text = paragraph.join("");
+ if (text) {
+ content += "<p>\n" + text + "\n</p>\n\n";
+ }
+ });
+
+ // The last paragraph is just spans for some reason
+ const finalParagraphExtract = [];
+ finalParagraph.forEach((clip) => {
+ appendClip(finalParagraphExtract, clip);
+ });
+ if (finalParagraphExtract.length) {
+ content += "<p>\n" + finalParagraphExtract.join("") + "\n</p>\n\n";
+ }
+ bib.text = content;
+ resolve();
+ });
+ });
+}
+
+/**
+ * Append a clip to a paragraph, adding formating (i.e. italics)
+ */
+function appendClip(paragraph, clip) {
+ paragraph.push(getClipValue(clip));
+}
+function getClipValue(clip) {
+ let value = clip.value;
+ if (clip.style.italic) {
+ value = "<i>" + value + "</i>";
+ } else if (clip.style.bold) {
+ value = "<b>" + value + "</b>";
+ } else if (clip.style.underline) {
+ value = "<u>" + value + "</u>";
+ }
+ return value;
+}
+
+/**
+ * Load everything and then exit!
+ */
+main().then(() => process.exit(0));