unpack-whenwe-json.js - convert html to markdown

This commit is contained in:
Nick Stokoe
2022-12-27 18:16:27 +00:00
parent 063c6742b2
commit 152d2d8993
2 changed files with 11 additions and 3 deletions

View File

@@ -7,5 +7,8 @@
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
"license": "ISC",
"dependencies": {
"node-html-markdown": "^1.3.0"
}
}

View File

@@ -1,10 +1,15 @@
const data = require('./whenwe.json');
const fs = require('fs');
const path = require('path');
const { NodeHtmlMarkdown, NodeHtmlMarkdownOptions } = require('node-html-markdown');
const nhm = new NodeHtmlMarkdown({
useLinkReferenceDefinitions: true,
useInlineLinks: true,
});
function toYaml(data, body) {
const frontmatter = Object.keys(data).sort().map(key => key+': '+(data[key] ?? '')).join("\n");
return frontmatter + "\n---\n" + body;
return frontmatter + "\n---\n" + nhm.translate(body);
}
function date(datestr) {
@@ -19,7 +24,7 @@ function date(datestr) {
data.forEach((node, ix) => {
const lang = 'und';
const filepath = path.join('out', 'node.type');
const filepath = path.join('out', node.type);
const body = node.body.und[0].value;
const filename = `${node.uuid}.yml`;