From 368a91c19383b844c68db2b251090c2146f1bd1f Mon Sep 17 00:00:00 2001 From: Artem Kostiuk Date: Tue, 1 Oct 2019 11:21:58 +0300 Subject: [PATCH 01/16] Prepare code for markdown conversion --- .gitignore | 2 +- README.md | 6 +++--- src/data_collectors.js | 29 +++++++++++++++-------------- src/index.js | 6 +++--- src/utils.js | 26 ++++++++++++++++---------- templates/dialect.mustache | 6 +++--- templates/index.mustache | 2 +- templates/node.mustache | 24 ++++++++++++------------ 8 files changed, 54 insertions(+), 47 deletions(-) diff --git a/.gitignore b/.gitignore index e75a363..ae27bda 100644 --- a/.gitignore +++ b/.gitignore @@ -83,4 +83,4 @@ typings/ # DynamoDB Local files .dynamodb/ -test_data/html/ +outdir/ diff --git a/README.md b/README.md index f86f1dc..cc61733 100644 --- a/README.md +++ b/README.md @@ -16,12 +16,12 @@ npm run aml2html -- ... --outdir=DIR --css=https://foo.bar/some.css E.g.: ```sh -$ npm run aml2html -- test_data/amf/dialects/canonical_webapi.yaml test_data/amf/dialects/oas20.yaml test_data/amf/dialects/validation.yaml test_data/music/dialect/playlist.yaml --outdir=./test_data/html/ +$ npm run aml2html -- test_data/amf/dialects/canonical_webapi.yaml test_data/amf/dialects/oas20.yaml test_data/amf/dialects/validation.yaml test_data/music/dialect/playlist.yaml --outdir=./outdir/ ``` Or using `--indir` option: ```sh -$ npm run aml2html -- --indir=./test_data/ --outdir=./test_data/html/ +$ npm run aml2html -- --indir=./test_data/ --outdir=./outdir/ ``` @@ -58,7 +58,7 @@ This file can be used when invoking the HTML generator in the following way: E.g. ```sh -$ npm run aml2html -- test_data/amf/dialects/canonical_webapi.yaml test_data/amf/dialects/oas20.yaml test_data/amf/dialects/validation.yaml test_data/music/dialect/playlist.yaml --outdir=./test_data/html/ --cfg=cfg.js +$ npm run aml2html -- test_data/amf/dialects/canonical_webapi.yaml test_data/amf/dialects/oas20.yaml test_data/amf/dialects/validation.yaml test_data/music/dialect/playlist.yaml --outdir=./outdir/ --cfg=cfg.js ``` Configuration files will be searched relative to the working directory of the node interpreter. diff --git a/src/data_collectors.js b/src/data_collectors.js index 54e0955..9327a65 100644 --- a/src/data_collectors.js +++ b/src/data_collectors.js @@ -15,7 +15,7 @@ function collectVocabularyData (doc, ctx, acc) { vocabularyData.usage = usage[0]['@value'] } vocabularyData.slug = utils.slugify(vocabularyData.name + '_vocab') - vocabularyData.htmlName = `${vocabularyData.slug}.html` + vocabularyData.pageUrl = utils.makePageUrl(vocabularyData.slug, 'html') console.log(`Collecting nodes info for vocabulary ${id}`) vocabularyData.nodeMappings = collectVocabularyNodesData( doc, vocabularyData, ctx).sort(utils.nameSorter) @@ -41,7 +41,7 @@ function collectDialectData (doc, ctx, acc, ontologyTerms) { dialectData.usage = usage[0]['@value'] } dialectData.slug = utils.slugify(dialectData.name) - dialectData.htmlName = `${dialectData.slug}.html` + dialectData.pageUrl = utils.makePageUrl(dialectData.slug, 'html') console.log(`Collecting nodes info for dialect ${id}`) dialectData.nodeMappings = collectNodesData( doc, dialectData, ctx, ontologyTerms) @@ -83,10 +83,10 @@ function collectVocabularyNodesData (doc, dialectData, ctx) { id: ctx.config.idMapping(node.query('@id')), dialectName: dialectData.name } - // htmlName + // pageUrl nodeData.slug = utils.slugify(`${nodeData.name}_${cred.type}`) - nodeData.htmlName = utils.makeSchemaHtmlName( - dialectData.slug, nodeData.slug) + nodeData.pageUrl = utils.makeSchemaPageUrl( + dialectData.slug, nodeData.slug, 'html') // save acc[nodeId] = nodeData } @@ -109,10 +109,10 @@ function collectNodesData (doc, dialectData, ctx, ontologyTerms) { id: ctx.config.idMapping(node.query('@id')), dialectName: dialectData.name } - // htmlName + // pageUrl nodeData.slug = utils.slugify(nodeData.name) - nodeData.htmlName = utils.makeSchemaHtmlName( - dialectData.slug, nodeData.slug) + nodeData.pageUrl = utils.makeSchemaPageUrl( + dialectData.slug, nodeData.slug, 'html') const isUnion = node.query('@type') .indexOf(`${ctx.meta}UnionNodeMapping`) > -1 @@ -139,10 +139,10 @@ function collectNodesData (doc, dialectData, ctx, ontologyTerms) { // properties nodeData.scalarProperties = utils.removeDuplicatesById( collectScalarPropsData(doc, node, ontologyTerms)) - .sort(utils.nameSorter) + .sort(utils.nameSorter) nodeData.linkProperties = utils.removeDuplicatesById( collectLinkPropsData(doc, node, dialectData.slug, ontologyTerms)) - .sort(utils.nameSorter) + .sort(utils.nameSorter) } nodeData.linkedSchemas = [] nodeData.linkProperties.forEach(prop => { @@ -183,9 +183,10 @@ function collectLinkPropsData (doc, node, dialectSlug, ontologyTerms) { } const decl = doc.query(`amldoc:declares[@id=${rangeId}]`) if (decl) { - data.rangeHtmlName = utils.makeSchemaHtmlName( + data.rangePageUrl = utils.makeSchemaPageUrl( utils.slugify(decl.parent().query('> schema:name @value')), - utils.slugify(data.rangeName)) + utils.slugify(data.rangeName), + 'html') } return data }) @@ -253,7 +254,7 @@ function collectCommonNavData (dialectsData) { dialects: dialectsData.map(data => { return { name: data.name, - htmlName: data.htmlName, + pageUrl: data.pageUrl, active: false } }), @@ -269,7 +270,7 @@ function collectNavData (dialectData, commonNavData) { nodeMappings: dialectData.nodeMappings.map(data => { return { name: data.name, - htmlName: data.htmlName, + pageUrl: data.pageUrl, active: false } }) diff --git a/src/index.js b/src/index.js index a5b23f3..d14458e 100644 --- a/src/index.js +++ b/src/index.js @@ -129,7 +129,7 @@ async function main () { utils.renderTemplate( { ...dialectData, ...ctx.config }, path.join(TMPL_DIR, 'dialect.mustache'), - path.join(outDir, dialectData.htmlName)) + path.join(outDir, dialectData.pageUrl)) // Render nodeMappings item data dialectData.nodeMappings.forEach(nodeData => { @@ -141,7 +141,7 @@ async function main () { utils.renderTemplate( { ...nodeData, ...ctx.config }, path.join(TMPL_DIR, 'node.mustache'), - path.join(outDir, nodeData.htmlName)) + path.join(outDir, nodeData.pageUrl)) }) }) @@ -155,7 +155,7 @@ async function main () { ...ctx.config }, path.join(TMPL_DIR, 'index.mustache'), - path.join(outDir, 'index.html')) + path.join(outDir, utils.makePageUrl('index', 'html'))) utils.copyStaticFiles(outDir) } diff --git a/src/utils.js b/src/utils.js index 1143f20..0bf5b07 100644 --- a/src/utils.js +++ b/src/utils.js @@ -56,19 +56,19 @@ function parseHashValue (id) { return afterHash } -/** Renders Mustache template with data and writes it to an HTML file. +/** Renders Mustache template with data and writes it to a file. * * @param data Data to be renreder in a template. * @param tmplPath Mustache template path. - * @param htmlPath Output HTML path. + * @param outPath Output file path. */ -function renderTemplate (data, tmplPath, htmlPath) { +function renderTemplate (data, tmplPath, outPath) { console.log( `Rendering "${tmplPath}" template`, data.id ? `for ${data.id}` : '') const tmplStr = fs.readFileSync(tmplPath, 'utf-8') - const htmlStr = Mustache.render(tmplStr, data) - fs.writeFileSync(htmlPath, htmlStr) + const renderedStr = Mustache.render(tmplStr, data) + fs.writeFileSync(outPath, renderedStr) } function nameSorter (a, b) { @@ -81,14 +81,19 @@ function nameSorter (a, b) { return 0 } -/* Makes a slug used in html names creation. */ +/* Makes a slug used in page urls creation. */ function slugify (val) { return val.split(' ').join('').toLowerCase() } -/* Creates an html page name for nodeMappings item. */ -function makeSchemaHtmlName (dialectSlug, schemaName) { - return `schema_${dialectSlug}_${schemaName}.html` +/* Creates a schema page url for nodeMappings item. */ +function makeSchemaPageUrl (dialectSlug, schemaName, ext) { + return makePageUrl(`schema_${dialectSlug}_${schemaName}`, ext) +} + +/* Creates page url using name and extension. */ +function makePageUrl (name, ext) { + return `${name}.${ext}` } /* Marks item with matching name as active/selected. */ @@ -160,7 +165,8 @@ module.exports = { TMPL_DIR: TMPL_DIR, nameSorter: nameSorter, slugify: slugify, - makeSchemaHtmlName: makeSchemaHtmlName, + makeSchemaPageUrl: makeSchemaPageUrl, + makePageUrl: makePageUrl, markActive: markActive, getDefaultContext: getDefaultContext, loadConfig: loadConfig diff --git a/templates/dialect.mustache b/templates/dialect.mustache index 5582173..de9f22e 100644 --- a/templates/dialect.mustache +++ b/templates/dialect.mustache @@ -27,7 +27,7 @@
{{#navData.dialects}}

- {{name}} + {{name}}

{{/navData.dialects}} @@ -36,7 +36,7 @@
{{#navData.nodeMappings}}

- {{name}} + {{name}}

{{/navData.nodeMappings}} @@ -65,7 +65,7 @@ diff --git a/templates/index.mustache b/templates/index.mustache index 3536577..b2dea48 100644 --- a/templates/index.mustache +++ b/templates/index.mustache @@ -25,7 +25,7 @@
{{#navData.dialects}}

- {{name}} + {{name}}

{{/navData.dialects}} diff --git a/templates/node.mustache b/templates/node.mustache index 9cb1d19..7747574 100644 --- a/templates/node.mustache +++ b/templates/node.mustache @@ -26,7 +26,7 @@
{{#navData.dialects}}

- {{name}} + {{name}}

{{/navData.dialects}} @@ -35,7 +35,7 @@
{{#navData.nodeMappings}}

- {{name}} + {{name}}

{{/navData.nodeMappings}} @@ -63,12 +63,12 @@ @@ -112,12 +112,12 @@ From 6bcffd69553850704d4f770f692ce43d23cf036f Mon Sep 17 00:00:00 2001 From: Artem Kostiuk Date: Tue, 1 Oct 2019 11:38:27 +0300 Subject: [PATCH 02/16] Add some base for using turndown --- package-lock.json | 310 +++++++++++++++++++++++++++++++++++++++++++--- package.json | 4 +- src/utils.js | 8 ++ 3 files changed, 303 insertions(+), 19 deletions(-) diff --git a/package-lock.json b/package-lock.json index 8ebeb8e..f170785 100644 --- a/package-lock.json +++ b/package-lock.json @@ -24,18 +24,44 @@ "js-tokens": "^4.0.0" } }, + "abab": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/abab/-/abab-2.0.2.tgz", + "integrity": "sha512-2scffjvioEmNz0OyDSLGWDfKCVwaKc6l9Pm9kOIREU13ClXZvHpg/nRL5xyjSSSLhOnXqft2HpsAzNEEA8cFFg==" + }, "acorn": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/acorn/-/acorn-7.0.0.tgz", "integrity": "sha512-PaF/MduxijYYt7unVGRuds1vBC9bFxbNf+VWqhOClfdgy7RlVkQqt610ig1/yxTgsDIfW1cWDel5EBbOy3jdtQ==", "dev": true }, + "acorn-globals": { + "version": "4.3.4", + "resolved": "https://registry.npmjs.org/acorn-globals/-/acorn-globals-4.3.4.tgz", + "integrity": "sha512-clfQEh21R+D0leSbUdWf3OcfqyaCSAQ8Ryq00bofSekfr9W8u1jyYZo6ir0xu9Gtcf7BjcHJpnbZH7JOCpP60A==", + "requires": { + "acorn": "^6.0.1", + "acorn-walk": "^6.0.1" + }, + "dependencies": { + "acorn": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-6.3.0.tgz", + "integrity": "sha512-/czfa8BwS88b9gWQVhc8eknunSA2DoJpJyTQkhheIf5E48u1N0R4q/YxxsAeqRrmK9TQ/uYfgLDfZo91UlANIA==" + } + } + }, "acorn-jsx": { "version": "5.0.2", "resolved": "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-5.0.2.tgz", "integrity": "sha512-tiNTrP1MP0QrChmD2DdupCr6HWSFeKVw5d/dHTu4Y7rkAkRhU/Dt7dphAfIUyxtHpl/eBVip5uTNSpQJHylpAw==", "dev": true }, + "acorn-walk": { + "version": "6.2.0", + "resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-6.2.0.tgz", + "integrity": "sha512-7evsyfH1cLOCdAzZAd43Cic04yKydNx0cF+7tiA19p1XnLLPU4dpCQOqpjqwokFe//vS0QqfqqjCS2JkiIs0cA==" + }, "ajv": { "version": "6.5.2", "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.5.2.tgz", @@ -91,6 +117,11 @@ "sprintf-js": "~1.0.2" } }, + "array-equal": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/array-equal/-/array-equal-1.0.0.tgz", + "integrity": "sha1-jCpe8kcv2ep0KwTHenUJO6J1fJM=" + }, "array-includes": { "version": "3.0.3", "resolved": "https://registry.npmjs.org/array-includes/-/array-includes-3.0.3.tgz", @@ -120,6 +151,11 @@ "integrity": "sha512-+Ryf6g3BKoRc7jfp7ad8tM4TtMiaWvbF/1/sQcZPkkS7ag3D5nMBCe2UfOTONtAkaG0tO0ij3C5Lwmf1EiyjHg==", "dev": true }, + "async-limiter": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/async-limiter/-/async-limiter-1.0.1.tgz", + "integrity": "sha512-csOlWGAcRFJaI6m+F2WKdnMKr4HhdhFVBk0H/QbJFMCr+uO2kwohwXQPxw/9OCxp05r5ghVBFSyioixx3gfkNQ==" + }, "asynckit": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", @@ -159,6 +195,11 @@ "concat-map": "0.0.1" } }, + "browser-process-hrtime": { + "version": "0.1.3", + "resolved": "https://registry.npmjs.org/browser-process-hrtime/-/browser-process-hrtime-0.1.3.tgz", + "integrity": "sha512-bRFnI4NnjO6cnyLmOV/7PVoDEMJChlcfN0z4s1YMBY989/SvlfMI1lgCnkFUs53e9gQF+w7qu7XdllSTiSl8Aw==" + }, "callsites": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz", @@ -255,6 +296,19 @@ "which": "^1.2.9" } }, + "cssom": { + "version": "0.3.8", + "resolved": "https://registry.npmjs.org/cssom/-/cssom-0.3.8.tgz", + "integrity": "sha512-b0tGHbfegbhPJpxpiBPU2sCkigAqtM9O121le6bbOlgyV+NyGyCmVfJ6QW9eRjz8CpNfWEOYBIMIGRYkLwsIYg==" + }, + "cssstyle": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/cssstyle/-/cssstyle-1.4.0.tgz", + "integrity": "sha512-GBrLZYZ4X4x6/QEoBnIrqb8B/f5l4+8me2dkom/j1Gtbxy0kBv6OGzKuAsGM75bkGwGAFkt56Iwg28S3XTZgSA==", + "requires": { + "cssom": "0.3.x" + } + }, "dashdash": { "version": "1.14.1", "resolved": "https://registry.npmjs.org/dashdash/-/dashdash-1.14.1.tgz", @@ -263,6 +317,28 @@ "assert-plus": "^1.0.0" } }, + "data-urls": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/data-urls/-/data-urls-1.1.0.tgz", + "integrity": "sha512-YTWYI9se1P55u58gL5GkQHW4P6VJBJ5iBT+B5a7i2Tjadhv52paJG0qHX4A0OR6/t52odI64KP2YvFpkDOi3eQ==", + "requires": { + "abab": "^2.0.0", + "whatwg-mimetype": "^2.2.0", + "whatwg-url": "^7.0.0" + }, + "dependencies": { + "whatwg-url": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-7.0.0.tgz", + "integrity": "sha512-37GeVSIJ3kn1JgKyjiYNmSLP1yzbpb29jdmwBSgkD9h40/hyrR/OifpVUndji3tmwGgD8qpw7iQu3RSbCrBpsQ==", + "requires": { + "lodash.sortby": "^4.7.0", + "tr46": "^1.0.1", + "webidl-conversions": "^4.0.2" + } + } + } + }, "debug": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz", @@ -281,8 +357,7 @@ "deep-is": { "version": "0.1.3", "resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.3.tgz", - "integrity": "sha1-s2nW+128E+7PUk+RsHD+7cNXzzQ=", - "dev": true + "integrity": "sha1-s2nW+128E+7PUk+RsHD+7cNXzzQ=" }, "define-properties": { "version": "1.1.3", @@ -329,6 +404,14 @@ "esutils": "^2.0.2" } }, + "domexception": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/domexception/-/domexception-1.0.1.tgz", + "integrity": "sha512-raigMkn7CJNNo6Ihro1fzG7wr3fHuYVytzquZKX5n0yizGsTcYgzdIUwj1X9pK0VvjeihV+XiclP+DjwbsSKug==", + "requires": { + "webidl-conversions": "^4.0.2" + } + }, "ecc-jsbn": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/ecc-jsbn/-/ecc-jsbn-0.1.2.tgz", @@ -388,6 +471,25 @@ "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=", "dev": true }, + "escodegen": { + "version": "1.12.0", + "resolved": "https://registry.npmjs.org/escodegen/-/escodegen-1.12.0.tgz", + "integrity": "sha512-TuA+EhsanGcme5T3R0L80u4t8CpbXQjegRmf7+FPTJrtCTErXFeelblRgHQa1FofEzqYYJmJ/OqjTwREp9qgmg==", + "requires": { + "esprima": "^3.1.3", + "estraverse": "^4.2.0", + "esutils": "^2.0.2", + "optionator": "^0.8.1", + "source-map": "~0.6.1" + }, + "dependencies": { + "esprima": { + "version": "3.1.3", + "resolved": "https://registry.npmjs.org/esprima/-/esprima-3.1.3.tgz", + "integrity": "sha1-/cpRzuYTOJXjyI1TXOSdv/YqRjM=" + } + } + }, "eslint": { "version": "6.4.0", "resolved": "https://registry.npmjs.org/eslint/-/eslint-6.4.0.tgz", @@ -714,14 +816,12 @@ "estraverse": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-4.3.0.tgz", - "integrity": "sha512-39nnKffWz8xN1BU/2c79n9nB9HDzo0niYUqx6xyqUnyoAnQyyWpOTdZEeiCch8BBu515t4wp9ZmgVfVhn9EBpw==", - "dev": true + "integrity": "sha512-39nnKffWz8xN1BU/2c79n9nB9HDzo0niYUqx6xyqUnyoAnQyyWpOTdZEeiCch8BBu515t4wp9ZmgVfVhn9EBpw==" }, "esutils": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.3.tgz", - "integrity": "sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==", - "dev": true + "integrity": "sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==" }, "extend": { "version": "3.0.2", @@ -757,8 +857,7 @@ "fast-levenshtein": { "version": "2.0.6", "resolved": "https://registry.npmjs.org/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz", - "integrity": "sha1-PYpcZog6FqMMqGQ+hR8Zuqd5eRc=", - "dev": true + "integrity": "sha1-PYpcZog6FqMMqGQ+hR8Zuqd5eRc=" }, "figures": { "version": "2.0.0", @@ -955,6 +1054,14 @@ "integrity": "sha512-pzXIvANXEFrc5oFFXRMkbLPQ2rXRoDERwDLyrcUxGhaZhgP54BBSl9Oheh7Vv0T090cszWBxPjkQQ5Sq1PbBRQ==", "dev": true }, + "html-encoding-sniffer": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/html-encoding-sniffer/-/html-encoding-sniffer-1.0.2.tgz", + "integrity": "sha512-71lZziiDnsuabfdYiUeWdCVyKuqwWi23L8YeIgV9jSSZHCtb6wB1BKWooH7L3tn4/FuZJMVWyNaIDr4RGmaSYw==", + "requires": { + "whatwg-encoding": "^1.0.1" + } + }, "http-signature": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/http-signature/-/http-signature-1.2.0.tgz", @@ -969,7 +1076,6 @@ "version": "0.4.24", "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", "integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==", - "dev": true, "requires": { "safer-buffer": ">= 2.1.2 < 3" } @@ -1139,6 +1245,46 @@ "resolved": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz", "integrity": "sha1-peZUwuWi3rXyAdls77yoDA7y9RM=" }, + "jsdom": { + "version": "11.12.0", + "resolved": "https://registry.npmjs.org/jsdom/-/jsdom-11.12.0.tgz", + "integrity": "sha512-y8Px43oyiBM13Zc1z780FrfNLJCXTL40EWlty/LXUtcjykRBNgLlCjWXpfSPBl2iv+N7koQN+dvqszHZgT/Fjw==", + "requires": { + "abab": "^2.0.0", + "acorn": "^5.5.3", + "acorn-globals": "^4.1.0", + "array-equal": "^1.0.0", + "cssom": ">= 0.3.2 < 0.4.0", + "cssstyle": "^1.0.0", + "data-urls": "^1.0.0", + "domexception": "^1.0.1", + "escodegen": "^1.9.1", + "html-encoding-sniffer": "^1.0.2", + "left-pad": "^1.3.0", + "nwsapi": "^2.0.7", + "parse5": "4.0.0", + "pn": "^1.1.0", + "request": "^2.87.0", + "request-promise-native": "^1.0.5", + "sax": "^1.2.4", + "symbol-tree": "^3.2.2", + "tough-cookie": "^2.3.4", + "w3c-hr-time": "^1.0.1", + "webidl-conversions": "^4.0.2", + "whatwg-encoding": "^1.0.3", + "whatwg-mimetype": "^2.1.0", + "whatwg-url": "^6.4.1", + "ws": "^5.2.0", + "xml-name-validator": "^3.0.0" + }, + "dependencies": { + "acorn": { + "version": "5.7.3", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-5.7.3.tgz", + "integrity": "sha512-T/zvzYRfbVojPWahDsE5evJdHb3oJoQfFbsrKM7w5Zcs++Tr257tia3BmMP8XYVjp1S9RZXQMh7gao96BlqZOw==" + } + } + }, "json-parse-better-errors": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/json-parse-better-errors/-/json-parse-better-errors-1.0.2.tgz", @@ -1211,11 +1357,15 @@ "resolved": "https://registry.npmjs.org/ld-query/-/ld-query-2.0.0.tgz", "integrity": "sha512-9+lV7uYDfdokDkd1iQVunLQvpwW0kEoJVhBDFqDwTq5b2ScJcqz/8vXygZ9CEWRVpw1gElfNXYeb4mluEGAb6Q==" }, + "left-pad": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/left-pad/-/left-pad-1.3.0.tgz", + "integrity": "sha512-XI5MPzVNApjAyhQzphX8BkmKsKUxD4LdyK24iZeQGinBN9yTQT3bFlCBy/aVx2HrNcqQGsdot8ghrjyrvMCoEA==" + }, "levn": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/levn/-/levn-0.3.0.tgz", "integrity": "sha1-OwmSTt+fCDwEkP3UwLxEIeBHZO4=", - "dev": true, "requires": { "prelude-ls": "~1.1.2", "type-check": "~0.3.2" @@ -1246,8 +1396,12 @@ "lodash": { "version": "4.17.15", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz", - "integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==", - "dev": true + "integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==" + }, + "lodash.sortby": { + "version": "4.7.0", + "resolved": "https://registry.npmjs.org/lodash.sortby/-/lodash.sortby-4.7.0.tgz", + "integrity": "sha1-7dFMgk4sycHgsKG0K7UhBRakJDg=" }, "loose-envify": { "version": "1.4.0", @@ -1354,6 +1508,11 @@ "validate-npm-package-license": "^3.0.1" } }, + "nwsapi": { + "version": "2.1.4", + "resolved": "https://registry.npmjs.org/nwsapi/-/nwsapi-2.1.4.tgz", + "integrity": "sha512-iGfd9Y6SFdTNldEy2L0GUhcarIutFmk+MPWIn9dmj8NMIup03G08uUF2KGbbmv/Ux4RT0VZJoP/sVbWA6d/VIw==" + }, "oauth-sign": { "version": "0.9.0", "resolved": "https://registry.npmjs.org/oauth-sign/-/oauth-sign-0.9.0.tgz", @@ -1447,7 +1606,6 @@ "version": "0.8.2", "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.8.2.tgz", "integrity": "sha1-NkxeQJ0/TWMB1sC0wFu6UBgK62Q=", - "dev": true, "requires": { "deep-is": "~0.1.3", "fast-levenshtein": "~2.0.4", @@ -1505,6 +1663,11 @@ "error-ex": "^1.2.0" } }, + "parse5": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/parse5/-/parse5-4.0.0.tgz", + "integrity": "sha512-VrZ7eOd3T1Fk4XWNXMgiGBK/z0MG48BWG2uQNU4I72fkQuKUTZpl+u9k+CxEG0twMVzSmXEEz12z5Fnw1jIQFA==" + }, "path-exists": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-3.0.0.tgz", @@ -1653,11 +1816,15 @@ "find-up": "^2.1.0" } }, + "pn": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/pn/-/pn-1.1.0.tgz", + "integrity": "sha512-2qHaIQr2VLRFoxe2nASzsV6ef4yOOH+Fi9FBOVH6cqeSgUnoyySPZkxzLuzd+RYOQTRpROA0ztTMqxROKSb/nA==" + }, "prelude-ls": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.1.2.tgz", - "integrity": "sha1-IZMqVJ9eUv/ZqCf1cOBL5iqX2lQ=", - "dev": true + "integrity": "sha1-IZMqVJ9eUv/ZqCf1cOBL5iqX2lQ=" }, "progress": { "version": "2.0.3", @@ -1760,6 +1927,24 @@ "uuid": "^3.3.2" } }, + "request-promise-core": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/request-promise-core/-/request-promise-core-1.1.2.tgz", + "integrity": "sha512-UHYyq1MO8GsefGEt7EprS8UrXsm1TxEvFUX1IMTuSLU2Rh7fTIdFtl8xD7JiEYiWU2dl+NYAjCTksTehQUxPag==", + "requires": { + "lodash": "^4.17.11" + } + }, + "request-promise-native": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/request-promise-native/-/request-promise-native-1.0.7.tgz", + "integrity": "sha512-rIMnbBdgNViL37nZ1b3L/VfPOpSi0TqVDQPAvO6U14lMzOLrt5nilxCQqtDKhZeDiW0/hkCXGoQjhgJd/tCh6w==", + "requires": { + "request-promise-core": "1.1.2", + "stealthy-require": "^1.1.1", + "tough-cookie": "^2.3.3" + } + }, "resolve": { "version": "1.12.0", "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.12.0.tgz", @@ -1828,6 +2013,11 @@ "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" }, + "sax": { + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/sax/-/sax-1.2.4.tgz", + "integrity": "sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw==" + }, "semver": { "version": "5.7.1", "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", @@ -1865,6 +2055,12 @@ "is-fullwidth-code-point": "^2.0.0" } }, + "source-map": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", + "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", + "optional": true + }, "spdx-correct": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/spdx-correct/-/spdx-correct-3.1.0.tgz", @@ -1948,6 +2144,11 @@ "pkg-conf": "^3.1.0" } }, + "stealthy-require": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/stealthy-require/-/stealthy-require-1.1.1.tgz", + "integrity": "sha1-NbCYdbT/SfJqd35QmzCQoyJr8ks=" + }, "string-width": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz", @@ -2027,6 +2228,11 @@ "has-flag": "^3.0.0" } }, + "symbol-tree": { + "version": "3.2.4", + "resolved": "https://registry.npmjs.org/symbol-tree/-/symbol-tree-3.2.4.tgz", + "integrity": "sha512-9QNk5KwDF+Bvz+PyObkmSYjI5ksVUYtjW7AU22r2NKcfLJcXp96hkDWU3+XndOsUb+AQ9QhfzfCT2O+CNWT5Tw==" + }, "table": { "version": "5.4.6", "resolved": "https://registry.npmjs.org/table/-/table-5.4.6.tgz", @@ -2101,6 +2307,14 @@ } } }, + "tr46": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/tr46/-/tr46-1.0.1.tgz", + "integrity": "sha1-qLE/1r/SSJUZZ0zN5VujaTtwbQk=", + "requires": { + "punycode": "^2.1.0" + } + }, "tslib": { "version": "1.10.0", "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.10.0.tgz", @@ -2115,6 +2329,19 @@ "safe-buffer": "^5.0.1" } }, + "turndown": { + "version": "5.0.3", + "resolved": "https://registry.npmjs.org/turndown/-/turndown-5.0.3.tgz", + "integrity": "sha512-popfGXEiedpq6F5saRIAThKxq/bbEPVFnsDnUdjaDGIre9f3/OL9Yi/yPbPcZ7RYUDpekghr666bBfZPrwNnhQ==", + "requires": { + "jsdom": "^11.9.0" + } + }, + "turndown-plugin-gfm": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/turndown-plugin-gfm/-/turndown-plugin-gfm-1.0.2.tgz", + "integrity": "sha512-vwz9tfvF7XN/jE0dGoBei3FXWuvll78ohzCZQuOb+ZjWrs3a0XhQVomJEb2Qh4VHTPNRO4GPZh0V7VRbiWwkRg==" + }, "tweetnacl": { "version": "0.14.5", "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-0.14.5.tgz", @@ -2124,7 +2351,6 @@ "version": "0.3.2", "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.3.2.tgz", "integrity": "sha1-WITKtRLPHTVeP7eE8wgEsrUg23I=", - "dev": true, "requires": { "prelude-ls": "~1.1.2" } @@ -2185,6 +2411,42 @@ "extsprintf": "^1.2.0" } }, + "w3c-hr-time": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/w3c-hr-time/-/w3c-hr-time-1.0.1.tgz", + "integrity": "sha1-gqwr/2PZUOqeMYmlimViX+3xkEU=", + "requires": { + "browser-process-hrtime": "^0.1.2" + } + }, + "webidl-conversions": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-4.0.2.tgz", + "integrity": "sha512-YQ+BmxuTgd6UXZW3+ICGfyqRyHXVlD5GtQr5+qjiNW7bF0cqrzX500HVXPBOvgXb5YnzDd+h0zqyv61KUD7+Sg==" + }, + "whatwg-encoding": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/whatwg-encoding/-/whatwg-encoding-1.0.5.tgz", + "integrity": "sha512-b5lim54JOPN9HtzvK9HFXvBma/rnfFeqsic0hSpjtDbVxR3dJKLc+KB4V6GgiGOvl7CY/KNh8rxSo9DKQrnUEw==", + "requires": { + "iconv-lite": "0.4.24" + } + }, + "whatwg-mimetype": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/whatwg-mimetype/-/whatwg-mimetype-2.3.0.tgz", + "integrity": "sha512-M4yMwr6mAnQz76TbJm914+gPpB/nCwvZbJU28cUD6dR004SAxDLOOSUaB1JDRqLtaOV/vi0IC5lEAGFgrjGv/g==" + }, + "whatwg-url": { + "version": "6.5.0", + "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-6.5.0.tgz", + "integrity": "sha512-rhRZRqx/TLJQWUpQ6bmrt2UV4f0HCQ463yQuONJqC6fO2VoEb1pTYddbe59SkYq87aoM5A3bdhMZiUiVws+fzQ==", + "requires": { + "lodash.sortby": "^4.7.0", + "tr46": "^1.0.1", + "webidl-conversions": "^4.0.2" + } + }, "which": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz", @@ -2197,8 +2459,7 @@ "wordwrap": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-1.0.0.tgz", - "integrity": "sha1-J1hIEIkUVqQXHI0CJkQa3pDLyus=", - "dev": true + "integrity": "sha1-J1hIEIkUVqQXHI0CJkQa3pDLyus=" }, "wrappy": { "version": "1.0.2", @@ -2215,6 +2476,19 @@ "mkdirp": "^0.5.1" } }, + "ws": { + "version": "5.2.2", + "resolved": "https://registry.npmjs.org/ws/-/ws-5.2.2.tgz", + "integrity": "sha512-jaHFD6PFv6UgoIVda6qZllptQsMlDEJkTQcybzzXDYM1XO9Y8em691FGMPmM46WGyLU4z9KMgQN+qrux/nhlHA==", + "requires": { + "async-limiter": "~1.0.0" + } + }, + "xml-name-validator": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/xml-name-validator/-/xml-name-validator-3.0.0.tgz", + "integrity": "sha512-A5CUptxDsvxKJEU3yO6DuWBSJz/qizqzJKOMIfUJHETbBw/sFaDxgd6fxm1ewUaM0jZ444Fc5vC5ROYurg/4Pw==" + }, "xmldom": { "version": "0.1.19", "resolved": "https://registry.npmjs.org/xmldom/-/xmldom-0.1.19.tgz", diff --git a/package.json b/package.json index e617d92..f297d31 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,9 @@ "jsonld": "^1.7.0", "ld-query": "^2.0.0", "minimist": "^1.2.0", - "mustache": "^3.0.1" + "mustache": "^3.0.1", + "turndown": "^5.0.3", + "turndown-plugin-gfm": "^1.0.2" }, "scripts": { "aml2html": "node src/index.js" diff --git a/src/utils.js b/src/utils.js index 0bf5b07..12d3b05 100644 --- a/src/utils.js +++ b/src/utils.js @@ -71,6 +71,14 @@ function renderTemplate (data, tmplPath, outPath) { fs.writeFileSync(outPath, renderedStr) } +function convertToMarkdown (htmlStr) { + const TurndownService = require('turndown') + const turndownPluginGfm = require('turndown-plugin-gfm') + const turndownService = new TurndownService() + turndownService.use(turndownPluginGfm.tables) + return turndownService.turndown(htmlStr) +} + function nameSorter (a, b) { if (a.name > b.name) { return 1 From bc14a54e3ecea745aae28704941634af9933e6d0 Mon Sep 17 00:00:00 2001 From: Artem Kostiuk Date: Tue, 1 Oct 2019 12:19:44 +0300 Subject: [PATCH 03/16] Fix plugins usage --- src/utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils.js b/src/utils.js index 12d3b05..2aca0ab 100644 --- a/src/utils.js +++ b/src/utils.js @@ -75,7 +75,7 @@ function convertToMarkdown (htmlStr) { const TurndownService = require('turndown') const turndownPluginGfm = require('turndown-plugin-gfm') const turndownService = new TurndownService() - turndownService.use(turndownPluginGfm.tables) + turndownService.use(turndownPluginGfm.gfm) return turndownService.turndown(htmlStr) } From 114cee26058debd9191ed5f57b93ac5a66fdd76b Mon Sep 17 00:00:00 2001 From: Artem Kostiuk Date: Tue, 1 Oct 2019 12:20:22 +0300 Subject: [PATCH 04/16] Dont render tables, uls when lists are empty --- templates/node.mustache | 98 +++++++++++++++++++++-------------------- 1 file changed, 51 insertions(+), 47 deletions(-) diff --git a/templates/node.mustache b/templates/node.mustache index 33e9611..32c9278 100644 --- a/templates/node.mustache +++ b/templates/node.mustache @@ -60,62 +60,65 @@

{{^linkedSchemas}}No {{/linkedSchemas}}Linked schemas

-
    - {{#linkedSchemas}} -
  • - {{#rangePageUrl}} - {{rangeName}} - {{/rangePageUrl}} - {{^rangePageUrl}} - {{rangeName}} - {{/rangePageUrl}} -
  • - {{/linkedSchemas}} -
+ {{#linkedSchemas.length}} +
    + {{#linkedSchemas}} +
  • + {{#rangePageUrl}} + {{rangeName}} + {{/rangePageUrl}} + {{^rangePageUrl}} + {{rangeName}} + {{/rangePageUrl}} +
  • + {{/linkedSchemas}} +
+ {{/linkedSchemas.length}} - - - {{#scalarProperties.length}} + {{^scalarProperties}}

No Scalar Properties

{{/scalarProperties}} + {{#scalarProperties.length}} +
{{^scalarProperties}}No {{/scalarProperties}}Scalar Properties
+ - {{/scalarProperties.length}} - - {{#scalarProperties}} - - - - - {{/scalarProperties}} - -
Scalar Properties
Name Details
{{name}} -
    -
  • Term ID: {{id}}
  • -
  • Range: {{range}}
  • - {{#propDesc}} -
  • Description: {{propDesc}}
  • - {{/propDesc}} - {{#constraints}} -
  • {{name}}: {{value}}
  • - {{/constraints}} -
-
+ + {{#scalarProperties}} + + {{name}} + +
    +
  • Term ID: {{id}}
  • +
  • Range: {{range}}
  • + {{#propDesc}} +
  • Description: {{propDesc}}
  • + {{/propDesc}} + {{#constraints}} +
  • {{name}}: {{value}}
  • + {{/constraints}} +
+ + + {{/scalarProperties}} + + + {{/scalarProperties.length}} - No Link Properties

{{/linkProperties}} + {{#linkProperties.length}} +
- - {{#linkProperties.length}} - - - - - - - {{/linkProperties.length}} + + + + + + + {{#linkProperties}} @@ -150,6 +153,7 @@ {{/linkProperties}}
{{^linkProperties}}No {{/linkProperties}}Link Properties
NameDetails
Link Properties
NameDetails
+ {{/linkProperties.length}} From 7dc0ea7a07d776636c47a4320e81696822c46fbc Mon Sep 17 00:00:00 2001 From: Artem Kostiuk Date: Wed, 2 Oct 2019 10:45:17 +0300 Subject: [PATCH 05/16] Remove turndown --- package-lock.json | 310 +++------------------------------------------- package.json | 4 +- src/utils.js | 8 -- 3 files changed, 19 insertions(+), 303 deletions(-) diff --git a/package-lock.json b/package-lock.json index f170785..8ebeb8e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -24,44 +24,18 @@ "js-tokens": "^4.0.0" } }, - "abab": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/abab/-/abab-2.0.2.tgz", - "integrity": "sha512-2scffjvioEmNz0OyDSLGWDfKCVwaKc6l9Pm9kOIREU13ClXZvHpg/nRL5xyjSSSLhOnXqft2HpsAzNEEA8cFFg==" - }, "acorn": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/acorn/-/acorn-7.0.0.tgz", "integrity": "sha512-PaF/MduxijYYt7unVGRuds1vBC9bFxbNf+VWqhOClfdgy7RlVkQqt610ig1/yxTgsDIfW1cWDel5EBbOy3jdtQ==", "dev": true }, - "acorn-globals": { - "version": "4.3.4", - "resolved": "https://registry.npmjs.org/acorn-globals/-/acorn-globals-4.3.4.tgz", - "integrity": "sha512-clfQEh21R+D0leSbUdWf3OcfqyaCSAQ8Ryq00bofSekfr9W8u1jyYZo6ir0xu9Gtcf7BjcHJpnbZH7JOCpP60A==", - "requires": { - "acorn": "^6.0.1", - "acorn-walk": "^6.0.1" - }, - "dependencies": { - "acorn": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-6.3.0.tgz", - "integrity": "sha512-/czfa8BwS88b9gWQVhc8eknunSA2DoJpJyTQkhheIf5E48u1N0R4q/YxxsAeqRrmK9TQ/uYfgLDfZo91UlANIA==" - } - } - }, "acorn-jsx": { "version": "5.0.2", "resolved": "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-5.0.2.tgz", "integrity": "sha512-tiNTrP1MP0QrChmD2DdupCr6HWSFeKVw5d/dHTu4Y7rkAkRhU/Dt7dphAfIUyxtHpl/eBVip5uTNSpQJHylpAw==", "dev": true }, - "acorn-walk": { - "version": "6.2.0", - "resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-6.2.0.tgz", - "integrity": "sha512-7evsyfH1cLOCdAzZAd43Cic04yKydNx0cF+7tiA19p1XnLLPU4dpCQOqpjqwokFe//vS0QqfqqjCS2JkiIs0cA==" - }, "ajv": { "version": "6.5.2", "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.5.2.tgz", @@ -117,11 +91,6 @@ "sprintf-js": "~1.0.2" } }, - "array-equal": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/array-equal/-/array-equal-1.0.0.tgz", - "integrity": "sha1-jCpe8kcv2ep0KwTHenUJO6J1fJM=" - }, "array-includes": { "version": "3.0.3", "resolved": "https://registry.npmjs.org/array-includes/-/array-includes-3.0.3.tgz", @@ -151,11 +120,6 @@ "integrity": "sha512-+Ryf6g3BKoRc7jfp7ad8tM4TtMiaWvbF/1/sQcZPkkS7ag3D5nMBCe2UfOTONtAkaG0tO0ij3C5Lwmf1EiyjHg==", "dev": true }, - "async-limiter": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/async-limiter/-/async-limiter-1.0.1.tgz", - "integrity": "sha512-csOlWGAcRFJaI6m+F2WKdnMKr4HhdhFVBk0H/QbJFMCr+uO2kwohwXQPxw/9OCxp05r5ghVBFSyioixx3gfkNQ==" - }, "asynckit": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", @@ -195,11 +159,6 @@ "concat-map": "0.0.1" } }, - "browser-process-hrtime": { - "version": "0.1.3", - "resolved": "https://registry.npmjs.org/browser-process-hrtime/-/browser-process-hrtime-0.1.3.tgz", - "integrity": "sha512-bRFnI4NnjO6cnyLmOV/7PVoDEMJChlcfN0z4s1YMBY989/SvlfMI1lgCnkFUs53e9gQF+w7qu7XdllSTiSl8Aw==" - }, "callsites": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz", @@ -296,19 +255,6 @@ "which": "^1.2.9" } }, - "cssom": { - "version": "0.3.8", - "resolved": "https://registry.npmjs.org/cssom/-/cssom-0.3.8.tgz", - "integrity": "sha512-b0tGHbfegbhPJpxpiBPU2sCkigAqtM9O121le6bbOlgyV+NyGyCmVfJ6QW9eRjz8CpNfWEOYBIMIGRYkLwsIYg==" - }, - "cssstyle": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/cssstyle/-/cssstyle-1.4.0.tgz", - "integrity": "sha512-GBrLZYZ4X4x6/QEoBnIrqb8B/f5l4+8me2dkom/j1Gtbxy0kBv6OGzKuAsGM75bkGwGAFkt56Iwg28S3XTZgSA==", - "requires": { - "cssom": "0.3.x" - } - }, "dashdash": { "version": "1.14.1", "resolved": "https://registry.npmjs.org/dashdash/-/dashdash-1.14.1.tgz", @@ -317,28 +263,6 @@ "assert-plus": "^1.0.0" } }, - "data-urls": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/data-urls/-/data-urls-1.1.0.tgz", - "integrity": "sha512-YTWYI9se1P55u58gL5GkQHW4P6VJBJ5iBT+B5a7i2Tjadhv52paJG0qHX4A0OR6/t52odI64KP2YvFpkDOi3eQ==", - "requires": { - "abab": "^2.0.0", - "whatwg-mimetype": "^2.2.0", - "whatwg-url": "^7.0.0" - }, - "dependencies": { - "whatwg-url": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-7.0.0.tgz", - "integrity": "sha512-37GeVSIJ3kn1JgKyjiYNmSLP1yzbpb29jdmwBSgkD9h40/hyrR/OifpVUndji3tmwGgD8qpw7iQu3RSbCrBpsQ==", - "requires": { - "lodash.sortby": "^4.7.0", - "tr46": "^1.0.1", - "webidl-conversions": "^4.0.2" - } - } - } - }, "debug": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz", @@ -357,7 +281,8 @@ "deep-is": { "version": "0.1.3", "resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.3.tgz", - "integrity": "sha1-s2nW+128E+7PUk+RsHD+7cNXzzQ=" + "integrity": "sha1-s2nW+128E+7PUk+RsHD+7cNXzzQ=", + "dev": true }, "define-properties": { "version": "1.1.3", @@ -404,14 +329,6 @@ "esutils": "^2.0.2" } }, - "domexception": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/domexception/-/domexception-1.0.1.tgz", - "integrity": "sha512-raigMkn7CJNNo6Ihro1fzG7wr3fHuYVytzquZKX5n0yizGsTcYgzdIUwj1X9pK0VvjeihV+XiclP+DjwbsSKug==", - "requires": { - "webidl-conversions": "^4.0.2" - } - }, "ecc-jsbn": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/ecc-jsbn/-/ecc-jsbn-0.1.2.tgz", @@ -471,25 +388,6 @@ "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=", "dev": true }, - "escodegen": { - "version": "1.12.0", - "resolved": "https://registry.npmjs.org/escodegen/-/escodegen-1.12.0.tgz", - "integrity": "sha512-TuA+EhsanGcme5T3R0L80u4t8CpbXQjegRmf7+FPTJrtCTErXFeelblRgHQa1FofEzqYYJmJ/OqjTwREp9qgmg==", - "requires": { - "esprima": "^3.1.3", - "estraverse": "^4.2.0", - "esutils": "^2.0.2", - "optionator": "^0.8.1", - "source-map": "~0.6.1" - }, - "dependencies": { - "esprima": { - "version": "3.1.3", - "resolved": "https://registry.npmjs.org/esprima/-/esprima-3.1.3.tgz", - "integrity": "sha1-/cpRzuYTOJXjyI1TXOSdv/YqRjM=" - } - } - }, "eslint": { "version": "6.4.0", "resolved": "https://registry.npmjs.org/eslint/-/eslint-6.4.0.tgz", @@ -816,12 +714,14 @@ "estraverse": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-4.3.0.tgz", - "integrity": "sha512-39nnKffWz8xN1BU/2c79n9nB9HDzo0niYUqx6xyqUnyoAnQyyWpOTdZEeiCch8BBu515t4wp9ZmgVfVhn9EBpw==" + "integrity": "sha512-39nnKffWz8xN1BU/2c79n9nB9HDzo0niYUqx6xyqUnyoAnQyyWpOTdZEeiCch8BBu515t4wp9ZmgVfVhn9EBpw==", + "dev": true }, "esutils": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.3.tgz", - "integrity": "sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==" + "integrity": "sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==", + "dev": true }, "extend": { "version": "3.0.2", @@ -857,7 +757,8 @@ "fast-levenshtein": { "version": "2.0.6", "resolved": "https://registry.npmjs.org/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz", - "integrity": "sha1-PYpcZog6FqMMqGQ+hR8Zuqd5eRc=" + "integrity": "sha1-PYpcZog6FqMMqGQ+hR8Zuqd5eRc=", + "dev": true }, "figures": { "version": "2.0.0", @@ -1054,14 +955,6 @@ "integrity": "sha512-pzXIvANXEFrc5oFFXRMkbLPQ2rXRoDERwDLyrcUxGhaZhgP54BBSl9Oheh7Vv0T090cszWBxPjkQQ5Sq1PbBRQ==", "dev": true }, - "html-encoding-sniffer": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/html-encoding-sniffer/-/html-encoding-sniffer-1.0.2.tgz", - "integrity": "sha512-71lZziiDnsuabfdYiUeWdCVyKuqwWi23L8YeIgV9jSSZHCtb6wB1BKWooH7L3tn4/FuZJMVWyNaIDr4RGmaSYw==", - "requires": { - "whatwg-encoding": "^1.0.1" - } - }, "http-signature": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/http-signature/-/http-signature-1.2.0.tgz", @@ -1076,6 +969,7 @@ "version": "0.4.24", "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", "integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==", + "dev": true, "requires": { "safer-buffer": ">= 2.1.2 < 3" } @@ -1245,46 +1139,6 @@ "resolved": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz", "integrity": "sha1-peZUwuWi3rXyAdls77yoDA7y9RM=" }, - "jsdom": { - "version": "11.12.0", - "resolved": "https://registry.npmjs.org/jsdom/-/jsdom-11.12.0.tgz", - "integrity": "sha512-y8Px43oyiBM13Zc1z780FrfNLJCXTL40EWlty/LXUtcjykRBNgLlCjWXpfSPBl2iv+N7koQN+dvqszHZgT/Fjw==", - "requires": { - "abab": "^2.0.0", - "acorn": "^5.5.3", - "acorn-globals": "^4.1.0", - "array-equal": "^1.0.0", - "cssom": ">= 0.3.2 < 0.4.0", - "cssstyle": "^1.0.0", - "data-urls": "^1.0.0", - "domexception": "^1.0.1", - "escodegen": "^1.9.1", - "html-encoding-sniffer": "^1.0.2", - "left-pad": "^1.3.0", - "nwsapi": "^2.0.7", - "parse5": "4.0.0", - "pn": "^1.1.0", - "request": "^2.87.0", - "request-promise-native": "^1.0.5", - "sax": "^1.2.4", - "symbol-tree": "^3.2.2", - "tough-cookie": "^2.3.4", - "w3c-hr-time": "^1.0.1", - "webidl-conversions": "^4.0.2", - "whatwg-encoding": "^1.0.3", - "whatwg-mimetype": "^2.1.0", - "whatwg-url": "^6.4.1", - "ws": "^5.2.0", - "xml-name-validator": "^3.0.0" - }, - "dependencies": { - "acorn": { - "version": "5.7.3", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-5.7.3.tgz", - "integrity": "sha512-T/zvzYRfbVojPWahDsE5evJdHb3oJoQfFbsrKM7w5Zcs++Tr257tia3BmMP8XYVjp1S9RZXQMh7gao96BlqZOw==" - } - } - }, "json-parse-better-errors": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/json-parse-better-errors/-/json-parse-better-errors-1.0.2.tgz", @@ -1357,15 +1211,11 @@ "resolved": "https://registry.npmjs.org/ld-query/-/ld-query-2.0.0.tgz", "integrity": "sha512-9+lV7uYDfdokDkd1iQVunLQvpwW0kEoJVhBDFqDwTq5b2ScJcqz/8vXygZ9CEWRVpw1gElfNXYeb4mluEGAb6Q==" }, - "left-pad": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/left-pad/-/left-pad-1.3.0.tgz", - "integrity": "sha512-XI5MPzVNApjAyhQzphX8BkmKsKUxD4LdyK24iZeQGinBN9yTQT3bFlCBy/aVx2HrNcqQGsdot8ghrjyrvMCoEA==" - }, "levn": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/levn/-/levn-0.3.0.tgz", "integrity": "sha1-OwmSTt+fCDwEkP3UwLxEIeBHZO4=", + "dev": true, "requires": { "prelude-ls": "~1.1.2", "type-check": "~0.3.2" @@ -1396,12 +1246,8 @@ "lodash": { "version": "4.17.15", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz", - "integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==" - }, - "lodash.sortby": { - "version": "4.7.0", - "resolved": "https://registry.npmjs.org/lodash.sortby/-/lodash.sortby-4.7.0.tgz", - "integrity": "sha1-7dFMgk4sycHgsKG0K7UhBRakJDg=" + "integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==", + "dev": true }, "loose-envify": { "version": "1.4.0", @@ -1508,11 +1354,6 @@ "validate-npm-package-license": "^3.0.1" } }, - "nwsapi": { - "version": "2.1.4", - "resolved": "https://registry.npmjs.org/nwsapi/-/nwsapi-2.1.4.tgz", - "integrity": "sha512-iGfd9Y6SFdTNldEy2L0GUhcarIutFmk+MPWIn9dmj8NMIup03G08uUF2KGbbmv/Ux4RT0VZJoP/sVbWA6d/VIw==" - }, "oauth-sign": { "version": "0.9.0", "resolved": "https://registry.npmjs.org/oauth-sign/-/oauth-sign-0.9.0.tgz", @@ -1606,6 +1447,7 @@ "version": "0.8.2", "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.8.2.tgz", "integrity": "sha1-NkxeQJ0/TWMB1sC0wFu6UBgK62Q=", + "dev": true, "requires": { "deep-is": "~0.1.3", "fast-levenshtein": "~2.0.4", @@ -1663,11 +1505,6 @@ "error-ex": "^1.2.0" } }, - "parse5": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/parse5/-/parse5-4.0.0.tgz", - "integrity": "sha512-VrZ7eOd3T1Fk4XWNXMgiGBK/z0MG48BWG2uQNU4I72fkQuKUTZpl+u9k+CxEG0twMVzSmXEEz12z5Fnw1jIQFA==" - }, "path-exists": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-3.0.0.tgz", @@ -1816,15 +1653,11 @@ "find-up": "^2.1.0" } }, - "pn": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/pn/-/pn-1.1.0.tgz", - "integrity": "sha512-2qHaIQr2VLRFoxe2nASzsV6ef4yOOH+Fi9FBOVH6cqeSgUnoyySPZkxzLuzd+RYOQTRpROA0ztTMqxROKSb/nA==" - }, "prelude-ls": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.1.2.tgz", - "integrity": "sha1-IZMqVJ9eUv/ZqCf1cOBL5iqX2lQ=" + "integrity": "sha1-IZMqVJ9eUv/ZqCf1cOBL5iqX2lQ=", + "dev": true }, "progress": { "version": "2.0.3", @@ -1927,24 +1760,6 @@ "uuid": "^3.3.2" } }, - "request-promise-core": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/request-promise-core/-/request-promise-core-1.1.2.tgz", - "integrity": "sha512-UHYyq1MO8GsefGEt7EprS8UrXsm1TxEvFUX1IMTuSLU2Rh7fTIdFtl8xD7JiEYiWU2dl+NYAjCTksTehQUxPag==", - "requires": { - "lodash": "^4.17.11" - } - }, - "request-promise-native": { - "version": "1.0.7", - "resolved": "https://registry.npmjs.org/request-promise-native/-/request-promise-native-1.0.7.tgz", - "integrity": "sha512-rIMnbBdgNViL37nZ1b3L/VfPOpSi0TqVDQPAvO6U14lMzOLrt5nilxCQqtDKhZeDiW0/hkCXGoQjhgJd/tCh6w==", - "requires": { - "request-promise-core": "1.1.2", - "stealthy-require": "^1.1.1", - "tough-cookie": "^2.3.3" - } - }, "resolve": { "version": "1.12.0", "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.12.0.tgz", @@ -2013,11 +1828,6 @@ "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" }, - "sax": { - "version": "1.2.4", - "resolved": "https://registry.npmjs.org/sax/-/sax-1.2.4.tgz", - "integrity": "sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw==" - }, "semver": { "version": "5.7.1", "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", @@ -2055,12 +1865,6 @@ "is-fullwidth-code-point": "^2.0.0" } }, - "source-map": { - "version": "0.6.1", - "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", - "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", - "optional": true - }, "spdx-correct": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/spdx-correct/-/spdx-correct-3.1.0.tgz", @@ -2144,11 +1948,6 @@ "pkg-conf": "^3.1.0" } }, - "stealthy-require": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/stealthy-require/-/stealthy-require-1.1.1.tgz", - "integrity": "sha1-NbCYdbT/SfJqd35QmzCQoyJr8ks=" - }, "string-width": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz", @@ -2228,11 +2027,6 @@ "has-flag": "^3.0.0" } }, - "symbol-tree": { - "version": "3.2.4", - "resolved": "https://registry.npmjs.org/symbol-tree/-/symbol-tree-3.2.4.tgz", - "integrity": "sha512-9QNk5KwDF+Bvz+PyObkmSYjI5ksVUYtjW7AU22r2NKcfLJcXp96hkDWU3+XndOsUb+AQ9QhfzfCT2O+CNWT5Tw==" - }, "table": { "version": "5.4.6", "resolved": "https://registry.npmjs.org/table/-/table-5.4.6.tgz", @@ -2307,14 +2101,6 @@ } } }, - "tr46": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/tr46/-/tr46-1.0.1.tgz", - "integrity": "sha1-qLE/1r/SSJUZZ0zN5VujaTtwbQk=", - "requires": { - "punycode": "^2.1.0" - } - }, "tslib": { "version": "1.10.0", "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.10.0.tgz", @@ -2329,19 +2115,6 @@ "safe-buffer": "^5.0.1" } }, - "turndown": { - "version": "5.0.3", - "resolved": "https://registry.npmjs.org/turndown/-/turndown-5.0.3.tgz", - "integrity": "sha512-popfGXEiedpq6F5saRIAThKxq/bbEPVFnsDnUdjaDGIre9f3/OL9Yi/yPbPcZ7RYUDpekghr666bBfZPrwNnhQ==", - "requires": { - "jsdom": "^11.9.0" - } - }, - "turndown-plugin-gfm": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/turndown-plugin-gfm/-/turndown-plugin-gfm-1.0.2.tgz", - "integrity": "sha512-vwz9tfvF7XN/jE0dGoBei3FXWuvll78ohzCZQuOb+ZjWrs3a0XhQVomJEb2Qh4VHTPNRO4GPZh0V7VRbiWwkRg==" - }, "tweetnacl": { "version": "0.14.5", "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-0.14.5.tgz", @@ -2351,6 +2124,7 @@ "version": "0.3.2", "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.3.2.tgz", "integrity": "sha1-WITKtRLPHTVeP7eE8wgEsrUg23I=", + "dev": true, "requires": { "prelude-ls": "~1.1.2" } @@ -2411,42 +2185,6 @@ "extsprintf": "^1.2.0" } }, - "w3c-hr-time": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/w3c-hr-time/-/w3c-hr-time-1.0.1.tgz", - "integrity": "sha1-gqwr/2PZUOqeMYmlimViX+3xkEU=", - "requires": { - "browser-process-hrtime": "^0.1.2" - } - }, - "webidl-conversions": { - "version": "4.0.2", - "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-4.0.2.tgz", - "integrity": "sha512-YQ+BmxuTgd6UXZW3+ICGfyqRyHXVlD5GtQr5+qjiNW7bF0cqrzX500HVXPBOvgXb5YnzDd+h0zqyv61KUD7+Sg==" - }, - "whatwg-encoding": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/whatwg-encoding/-/whatwg-encoding-1.0.5.tgz", - "integrity": "sha512-b5lim54JOPN9HtzvK9HFXvBma/rnfFeqsic0hSpjtDbVxR3dJKLc+KB4V6GgiGOvl7CY/KNh8rxSo9DKQrnUEw==", - "requires": { - "iconv-lite": "0.4.24" - } - }, - "whatwg-mimetype": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/whatwg-mimetype/-/whatwg-mimetype-2.3.0.tgz", - "integrity": "sha512-M4yMwr6mAnQz76TbJm914+gPpB/nCwvZbJU28cUD6dR004SAxDLOOSUaB1JDRqLtaOV/vi0IC5lEAGFgrjGv/g==" - }, - "whatwg-url": { - "version": "6.5.0", - "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-6.5.0.tgz", - "integrity": "sha512-rhRZRqx/TLJQWUpQ6bmrt2UV4f0HCQ463yQuONJqC6fO2VoEb1pTYddbe59SkYq87aoM5A3bdhMZiUiVws+fzQ==", - "requires": { - "lodash.sortby": "^4.7.0", - "tr46": "^1.0.1", - "webidl-conversions": "^4.0.2" - } - }, "which": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz", @@ -2459,7 +2197,8 @@ "wordwrap": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-1.0.0.tgz", - "integrity": "sha1-J1hIEIkUVqQXHI0CJkQa3pDLyus=" + "integrity": "sha1-J1hIEIkUVqQXHI0CJkQa3pDLyus=", + "dev": true }, "wrappy": { "version": "1.0.2", @@ -2476,19 +2215,6 @@ "mkdirp": "^0.5.1" } }, - "ws": { - "version": "5.2.2", - "resolved": "https://registry.npmjs.org/ws/-/ws-5.2.2.tgz", - "integrity": "sha512-jaHFD6PFv6UgoIVda6qZllptQsMlDEJkTQcybzzXDYM1XO9Y8em691FGMPmM46WGyLU4z9KMgQN+qrux/nhlHA==", - "requires": { - "async-limiter": "~1.0.0" - } - }, - "xml-name-validator": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/xml-name-validator/-/xml-name-validator-3.0.0.tgz", - "integrity": "sha512-A5CUptxDsvxKJEU3yO6DuWBSJz/qizqzJKOMIfUJHETbBw/sFaDxgd6fxm1ewUaM0jZ444Fc5vC5ROYurg/4Pw==" - }, "xmldom": { "version": "0.1.19", "resolved": "https://registry.npmjs.org/xmldom/-/xmldom-0.1.19.tgz", diff --git a/package.json b/package.json index f297d31..e617d92 100644 --- a/package.json +++ b/package.json @@ -9,9 +9,7 @@ "jsonld": "^1.7.0", "ld-query": "^2.0.0", "minimist": "^1.2.0", - "mustache": "^3.0.1", - "turndown": "^5.0.3", - "turndown-plugin-gfm": "^1.0.2" + "mustache": "^3.0.1" }, "scripts": { "aml2html": "node src/index.js" diff --git a/src/utils.js b/src/utils.js index 2aca0ab..0bf5b07 100644 --- a/src/utils.js +++ b/src/utils.js @@ -71,14 +71,6 @@ function renderTemplate (data, tmplPath, outPath) { fs.writeFileSync(outPath, renderedStr) } -function convertToMarkdown (htmlStr) { - const TurndownService = require('turndown') - const turndownPluginGfm = require('turndown-plugin-gfm') - const turndownService = new TurndownService() - turndownService.use(turndownPluginGfm.gfm) - return turndownService.turndown(htmlStr) -} - function nameSorter (a, b) { if (a.name > b.name) { return 1 From c53bb67d396f8fa08354b4b1bd10835bca072c8b Mon Sep 17 00:00:00 2001 From: Artem Kostiuk Date: Wed, 2 Oct 2019 13:36:35 +0300 Subject: [PATCH 06/16] Switch from minimist to commander --- README.md | 18 +++++++++++--- package-lock.json | 8 +++++- package.json | 2 +- src/index.js | 62 +++++++++++++++++++++++++++++------------------ src/utils.js | 13 ++++++++-- 5 files changed, 72 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index cc61733..f559d6d 100644 --- a/README.md +++ b/README.md @@ -11,17 +11,27 @@ $ npm install ## Usage CLI command notation (*note the required `--` before arguments*): ``` -npm run aml2html -- ... --outdir=DIR --css=https://foo.bar/some.css --css=/another.css +Usage: npm run aml2html -- [options] + +Convert AML Vocabularies & Dialects to HTML + +Options: + -d, --indir Path to input directory to convert. Takes precedence over --infile. + -f, --infile Path to input file to convert (default: []) + -s, --syntax Output syntax (html or md) (default: "html") + -c, --css Custom css file path (default: []) + -g, --cfg Configuration file path + -h, --help output usage information ``` E.g.: ```sh -$ npm run aml2html -- test_data/amf/dialects/canonical_webapi.yaml test_data/amf/dialects/oas20.yaml test_data/amf/dialects/validation.yaml test_data/music/dialect/playlist.yaml --outdir=./outdir/ +$ npm run aml2html -- ./outdir --infile=test_data/amf/dialects/canonical_webapi.yaml --infile=test_data/amf/dialects/oas20.yaml --infile=test_data/amf/dialects/validation.yaml --infile=test_data/music/dialect/playlist.yaml ``` Or using `--indir` option: ```sh -$ npm run aml2html -- --indir=./test_data/ --outdir=./outdir/ +$ npm run aml2html -- ./outdir --indir=./test_data ``` @@ -58,7 +68,7 @@ This file can be used when invoking the HTML generator in the following way: E.g. ```sh -$ npm run aml2html -- test_data/amf/dialects/canonical_webapi.yaml test_data/amf/dialects/oas20.yaml test_data/amf/dialects/validation.yaml test_data/music/dialect/playlist.yaml --outdir=./outdir/ --cfg=cfg.js +$ npm run aml2html -- ./outdir --indir=./test_data --cfg=cfg.js ``` Configuration files will be searched relative to the working directory of the node interpreter. diff --git a/package-lock.json b/package-lock.json index 8ebeb8e..060882f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -225,6 +225,11 @@ "delayed-stream": "~1.0.0" } }, + "commander": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/commander/-/commander-3.0.2.tgz", + "integrity": "sha512-Gar0ASD4BDyKC4hl4DwHqDrmvjoxWKZigVnAbn5H1owvm4CxCPdb0HQDehwNYMJpla5+M2tPmPARzhtYuwpHow==" + }, "concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", @@ -1289,7 +1294,8 @@ "minimist": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", - "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=" + "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=", + "dev": true }, "mkdirp": { "version": "0.5.1", diff --git a/package.json b/package.json index e617d92..2d37af4 100644 --- a/package.json +++ b/package.json @@ -5,10 +5,10 @@ "license": "MIT", "dependencies": { "amf-client-js": "^3.5.0", + "commander": "^3.0.2", "fs-extra": "^7.0.1", "jsonld": "^1.7.0", "ld-query": "^2.0.0", - "minimist": "^1.2.0", "mustache": "^3.0.1" }, "scripts": { diff --git a/src/index.js b/src/index.js index d14458e..9a9d8a3 100644 --- a/src/index.js +++ b/src/index.js @@ -1,5 +1,5 @@ const amf = require('amf-client-js') -const parseArgs = require('minimist') +const program = require('commander') const ldquery = require('ld-query') const path = require('path') const fs = require('fs-extra') @@ -8,9 +8,6 @@ const utils = require('./utils') const collect = require('./data_collectors') const jsonld = require('jsonld') -/** Mustache dialects templates directory path. */ -const TMPL_DIR = path.join(utils.TMPL_DIR) - /** * Process a file as a vocabulary */ @@ -52,32 +49,50 @@ async function processDialect (dialectPath, graph, ctx, acc, ontologyTerms) { } } +function defineAndParseArgv () { + program + .arguments('') + .action((outputDir) => { + program.outputDir = outputDir + }) + .name('aml2html') + .description('Convert AML Vocabularies & Dialects to HTML') + .option('-d, --indir ', 'Path to input directory to convert. Takes precedence over --infile.') + .option('-f, --infile ', 'Path to input file to convert', utils.collectOpt, []) + .option('-s, --syntax ', 'Output syntax (html or md)', 'html') + .option('-c, --css ', 'Custom css file path', utils.collectOpt, []) + .option('-g, --cfg ', 'Configuration file path') + .parse(process.argv) + + if (!program.outputDir) { + console.error('Missing output directory path (outputDir).\n') + program.help() + } + if (!(program.infile.length > 0 || program.indir)) { + console.error('Missing input (--infile or --indir).\n') + program.help() + } +} + /** Runs all the logic. */ async function main () { + defineAndParseArgv() let ctx = utils.getDefaultContext() - await amf.AMF.init() - const argv = parseArgs(process.argv.slice(2)) // Ensure output directory exists - if (!argv.outdir) { - console.error(`Missing mandatory output directory. - Syntax: aml2html -- --outdir= [--indir=] [--css=] [--cfg=]`) - return - } - const outDir = path.resolve(argv.outdir) + const outDir = path.resolve(program.outputDir) fs.emptyDirSync(outDir) // Add custom configuration elements - if (argv.cfg) { - ctx = utils.loadConfig(argv.cfg, ctx) + if (program.cfg) { + ctx = utils.loadConfig(program.cfg, ctx) } // Collects dialects data into an array - var dialectsPaths = Array.isArray(argv._) ? argv._ : [argv._] - if (argv.indir) { - dialectsPaths = utils.walkSync(argv.indir) - } + const dialectsPaths = program.indir + ? utils.walkSync(program.indir) + : program.infile const acc = {} const ontology = {} @@ -123,12 +138,12 @@ async function main () { // Collect navigation data and render dialect template dialectsData.forEach(dialectData => { dialectData.navData = collect.navData(dialectData, commonNavData) - dialectData.css = argv.css + dialectData.css = program.css // Render dialect overview template utils.renderTemplate( { ...dialectData, ...ctx.config }, - path.join(TMPL_DIR, 'dialect.mustache'), + 'html', 'dialect.mustache', path.join(outDir, dialectData.pageUrl)) // Render nodeMappings item data @@ -137,10 +152,10 @@ async function main () { nodeData.navData.nodeMappings = utils.markActive( nodeData.navData.nodeMappings, nodeData.name) - nodeData.css = argv.css + nodeData.css = program.css utils.renderTemplate( { ...nodeData, ...ctx.config }, - path.join(TMPL_DIR, 'node.mustache'), + 'html', 'node.mustache', path.join(outDir, nodeData.pageUrl)) }) }) @@ -148,13 +163,14 @@ async function main () { // Render index page utils.renderTemplate( { + css: program.css, dialects: dialectsData, navData: { dialects: utils.markActive(commonNavData.dialects) }, ...ctx.config }, - path.join(TMPL_DIR, 'index.mustache'), + 'html', 'index.mustache', path.join(outDir, utils.makePageUrl('index', 'html'))) utils.copyStaticFiles(outDir) diff --git a/src/utils.js b/src/utils.js index 0bf5b07..ea9afb4 100644 --- a/src/utils.js +++ b/src/utils.js @@ -3,6 +3,7 @@ const path = require('path') const fs = require('fs-extra') const Mustache = require('mustache') +/** Mustache dialects templates directory path. */ const TMPL_DIR = path.join(__dirname, '..', 'templates') /** Converts AML Document to resolved JSON-LD AMF Graph. @@ -59,10 +60,13 @@ function parseHashValue (id) { /** Renders Mustache template with data and writes it to a file. * * @param data Data to be renreder in a template. + * @param tmplType Template type. Must match type-specific template + folders names. * @param tmplPath Mustache template path. * @param outPath Output file path. */ -function renderTemplate (data, tmplPath, outPath) { +function renderTemplate (data, tmplType, tmplName, outPath) { + const tmplPath = path.join(TMPL_DIR, tmplType, tmplName) console.log( `Rendering "${tmplPath}" template`, data.id ? `for ${data.id}` : '') @@ -155,6 +159,10 @@ function walkSync (dir, filelist) { return filelist } +function collectOpt (value, previous) { + return previous.concat([value]); +} + module.exports = { walkSync: walkSync, getJsonLdGraph: getJsonLdGraph, @@ -169,5 +177,6 @@ module.exports = { makePageUrl: makePageUrl, markActive: markActive, getDefaultContext: getDefaultContext, - loadConfig: loadConfig + loadConfig: loadConfig, + collectOpt: collectOpt } From 29698fe7543cbbe95e9a3f602aaef5767188d1f0 Mon Sep 17 00:00:00 2001 From: Artem Kostiuk Date: Wed, 2 Oct 2019 13:49:38 +0300 Subject: [PATCH 07/16] Fix linting and descriptions --- README.md | 4 ++-- package.json | 1 + src/index.js | 2 +- src/utils.js | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 10f526c..ec79ffc 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # aml2doc -Convert AML Vocabularies & Dialects to HTML. +Convert AML Vocabularies & Dialects to documentation. ## Installation ```sh @@ -13,7 +13,7 @@ CLI command notation (*note the required `--` before arguments*): ``` Usage: npm run aml2doc -- [options] -Convert AML Vocabularies & Dialects to HTML +Convert AML Vocabularies & Dialects to documentation. Options: -d, --indir Path to input directory to convert. Takes precedence over --infile. diff --git a/package.json b/package.json index 96f0a35..05f8c8e 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,6 @@ { "name": "aml2doc", + "description": "Convert AML Vocabularies & Dialects to documentation", "version": "0.1.0", "main": "src/index.js", "license": "MIT", diff --git a/src/index.js b/src/index.js index e0850c4..1a01d85 100644 --- a/src/index.js +++ b/src/index.js @@ -56,7 +56,7 @@ function defineAndParseArgv () { program.outputDir = outputDir }) .name('aml2doc') - .description('Convert AML Vocabularies & Dialects to HTML') + .description('Convert AML Vocabularies & Dialects to documentation.') .option('-d, --indir ', 'Path to input directory to convert. Takes precedence over --infile.') .option('-f, --infile ', 'Path to input file to convert', utils.collectOpt, []) .option('-s, --syntax ', 'Output syntax (html or md)', 'html') diff --git a/src/utils.js b/src/utils.js index ea9afb4..af7d1fe 100644 --- a/src/utils.js +++ b/src/utils.js @@ -160,7 +160,7 @@ function walkSync (dir, filelist) { } function collectOpt (value, previous) { - return previous.concat([value]); + return previous.concat([value]) } module.exports = { From 06a805fd82e9f9d6c115acd176bd6a84973adb64 Mon Sep 17 00:00:00 2001 From: Artem Kostiuk Date: Wed, 2 Oct 2019 14:20:43 +0300 Subject: [PATCH 08/16] Use syntax option --- src/data_collectors.js | 25 ++++++++++++------------- src/index.js | 12 ++++++------ src/utils.js | 19 +++++-------------- templates/html/dialect.mustache | 6 +++--- templates/html/index.mustache | 2 +- templates/html/node.mustache | 24 ++++++++++++------------ 6 files changed, 39 insertions(+), 49 deletions(-) diff --git a/src/data_collectors.js b/src/data_collectors.js index 9327a65..cf3c100 100644 --- a/src/data_collectors.js +++ b/src/data_collectors.js @@ -15,7 +15,7 @@ function collectVocabularyData (doc, ctx, acc) { vocabularyData.usage = usage[0]['@value'] } vocabularyData.slug = utils.slugify(vocabularyData.name + '_vocab') - vocabularyData.pageUrl = utils.makePageUrl(vocabularyData.slug, 'html') + vocabularyData.pageName = vocabularyData.slug console.log(`Collecting nodes info for vocabulary ${id}`) vocabularyData.nodeMappings = collectVocabularyNodesData( doc, vocabularyData, ctx).sort(utils.nameSorter) @@ -41,7 +41,7 @@ function collectDialectData (doc, ctx, acc, ontologyTerms) { dialectData.usage = usage[0]['@value'] } dialectData.slug = utils.slugify(dialectData.name) - dialectData.pageUrl = utils.makePageUrl(dialectData.slug, 'html') + dialectData.pageName = dialectData.slug console.log(`Collecting nodes info for dialect ${id}`) dialectData.nodeMappings = collectNodesData( doc, dialectData, ctx, ontologyTerms) @@ -83,10 +83,10 @@ function collectVocabularyNodesData (doc, dialectData, ctx) { id: ctx.config.idMapping(node.query('@id')), dialectName: dialectData.name } - // pageUrl + // pageName nodeData.slug = utils.slugify(`${nodeData.name}_${cred.type}`) - nodeData.pageUrl = utils.makeSchemaPageUrl( - dialectData.slug, nodeData.slug, 'html') + nodeData.pageName = utils.makeSchemaPageName( + dialectData.slug, nodeData.slug) // save acc[nodeId] = nodeData } @@ -109,10 +109,10 @@ function collectNodesData (doc, dialectData, ctx, ontologyTerms) { id: ctx.config.idMapping(node.query('@id')), dialectName: dialectData.name } - // pageUrl + // pageName nodeData.slug = utils.slugify(nodeData.name) - nodeData.pageUrl = utils.makeSchemaPageUrl( - dialectData.slug, nodeData.slug, 'html') + nodeData.pageName = utils.makeSchemaPageName( + dialectData.slug, nodeData.slug) const isUnion = node.query('@type') .indexOf(`${ctx.meta}UnionNodeMapping`) > -1 @@ -183,10 +183,9 @@ function collectLinkPropsData (doc, node, dialectSlug, ontologyTerms) { } const decl = doc.query(`amldoc:declares[@id=${rangeId}]`) if (decl) { - data.rangePageUrl = utils.makeSchemaPageUrl( + data.rangePageName = utils.makeSchemaPageName( utils.slugify(decl.parent().query('> schema:name @value')), - utils.slugify(data.rangeName), - 'html') + utils.slugify(data.rangeName)) } return data }) @@ -254,7 +253,7 @@ function collectCommonNavData (dialectsData) { dialects: dialectsData.map(data => { return { name: data.name, - pageUrl: data.pageUrl, + pageName: data.pageName, active: false } }), @@ -270,7 +269,7 @@ function collectNavData (dialectData, commonNavData) { nodeMappings: dialectData.nodeMappings.map(data => { return { name: data.name, - pageUrl: data.pageUrl, + pageName: data.pageName, active: false } }) diff --git a/src/index.js b/src/index.js index 1a01d85..9cddb71 100644 --- a/src/index.js +++ b/src/index.js @@ -143,8 +143,8 @@ async function main () { // Render dialect overview template utils.renderTemplate( { ...dialectData, ...ctx.config }, - 'html', 'dialect.mustache', - path.join(outDir, dialectData.pageUrl)) + path.join(utils.TMPL_DIR, program.syntax, 'dialect.mustache'), + path.join(outDir, `${dialectData.pageName}.${program.syntax}`)) // Render nodeMappings item data dialectData.nodeMappings.forEach(nodeData => { @@ -155,8 +155,8 @@ async function main () { nodeData.css = program.css utils.renderTemplate( { ...nodeData, ...ctx.config }, - 'html', 'node.mustache', - path.join(outDir, nodeData.pageUrl)) + path.join(utils.TMPL_DIR, program.syntax, 'node.mustache'), + path.join(outDir, `${nodeData.pageName}.${program.syntax}`)) }) }) @@ -170,8 +170,8 @@ async function main () { }, ...ctx.config }, - 'html', 'index.mustache', - path.join(outDir, utils.makePageUrl('index', 'html'))) + path.join(utils.TMPL_DIR, program.syntax, 'index.mustache'), + path.join(outDir, `index.${program.syntax}`)) utils.copyStaticFiles(outDir) } diff --git a/src/utils.js b/src/utils.js index af7d1fe..164c713 100644 --- a/src/utils.js +++ b/src/utils.js @@ -60,13 +60,10 @@ function parseHashValue (id) { /** Renders Mustache template with data and writes it to a file. * * @param data Data to be renreder in a template. - * @param tmplType Template type. Must match type-specific template - folders names. * @param tmplPath Mustache template path. * @param outPath Output file path. */ -function renderTemplate (data, tmplType, tmplName, outPath) { - const tmplPath = path.join(TMPL_DIR, tmplType, tmplName) +function renderTemplate (data, tmplPath, outPath) { console.log( `Rendering "${tmplPath}" template`, data.id ? `for ${data.id}` : '') @@ -90,14 +87,9 @@ function slugify (val) { return val.split(' ').join('').toLowerCase() } -/* Creates a schema page url for nodeMappings item. */ -function makeSchemaPageUrl (dialectSlug, schemaName, ext) { - return makePageUrl(`schema_${dialectSlug}_${schemaName}`, ext) -} - -/* Creates page url using name and extension. */ -function makePageUrl (name, ext) { - return `${name}.${ext}` +/* Creates a schema page name for nodeMappings item. */ +function makeSchemaPageName (dialectSlug, schemaName) { + return `schema_${dialectSlug}_${schemaName}` } /* Marks item with matching name as active/selected. */ @@ -173,8 +165,7 @@ module.exports = { TMPL_DIR: TMPL_DIR, nameSorter: nameSorter, slugify: slugify, - makeSchemaPageUrl: makeSchemaPageUrl, - makePageUrl: makePageUrl, + makeSchemaPageName: makeSchemaPageName, markActive: markActive, getDefaultContext: getDefaultContext, loadConfig: loadConfig, diff --git a/templates/html/dialect.mustache b/templates/html/dialect.mustache index de9f22e..37ba435 100644 --- a/templates/html/dialect.mustache +++ b/templates/html/dialect.mustache @@ -27,7 +27,7 @@
{{#navData.dialects}}

- {{name}} + {{name}}

{{/navData.dialects}} @@ -36,7 +36,7 @@
{{#navData.nodeMappings}}

- {{name}} + {{name}}

{{/navData.nodeMappings}} @@ -65,7 +65,7 @@ diff --git a/templates/html/index.mustache b/templates/html/index.mustache index 01ff4a7..f1c27e4 100644 --- a/templates/html/index.mustache +++ b/templates/html/index.mustache @@ -26,7 +26,7 @@
{{#navData.dialects}}

- {{name}} + {{name}}

{{/navData.dialects}} diff --git a/templates/html/node.mustache b/templates/html/node.mustache index 32c9278..588469b 100644 --- a/templates/html/node.mustache +++ b/templates/html/node.mustache @@ -26,7 +26,7 @@
{{#navData.dialects}}

- {{name}} + {{name}}

{{/navData.dialects}} @@ -35,7 +35,7 @@
{{#navData.nodeMappings}}

- {{name}} + {{name}}

{{/navData.nodeMappings}} @@ -64,12 +64,12 @@
    {{#linkedSchemas}}
  • - {{#rangePageUrl}} - {{rangeName}} - {{/rangePageUrl}} - {{^rangePageUrl}} + {{#rangePageName}} + {{rangeName}} + {{/rangePageName}} + {{^rangePageName}} {{rangeName}} - {{/rangePageUrl}} + {{/rangePageName}}
  • {{/linkedSchemas}}
@@ -131,12 +131,12 @@
    {{#range}}
  • - {{#rangePageUrl}} - {{rangeName}} - {{/rangePageUrl}} - {{^rangePageUrl}} + {{#rangePageName}} + {{rangeName}} + {{/rangePageName}} + {{^rangePageName}} {{rangeName}} - {{/rangePageUrl}} + {{/rangePageName}}
  • {{/range}}
From e24a1abdd1c5ed20a704a2e6e4a650268145939a Mon Sep 17 00:00:00 2001 From: Artem Kostiuk Date: Thu, 3 Oct 2019 09:44:19 +0300 Subject: [PATCH 09/16] Add index md template --- src/utils.js | 20 ++++++++++++++++++-- templates/md/index.mustache | 36 +++++++++++++++++++++++++++++++++++- 2 files changed, 53 insertions(+), 3 deletions(-) diff --git a/src/utils.js b/src/utils.js index 164c713..8aecf2f 100644 --- a/src/utils.js +++ b/src/utils.js @@ -68,7 +68,7 @@ function renderTemplate (data, tmplPath, outPath) { `Rendering "${tmplPath}" template`, data.id ? `for ${data.id}` : '') const tmplStr = fs.readFileSync(tmplPath, 'utf-8') - const renderedStr = Mustache.render(tmplStr, data) + const renderedStr = Mustache.render(tmplStr, addTmplUtils(data)) fs.writeFileSync(outPath, renderedStr) } @@ -151,10 +151,25 @@ function walkSync (dir, filelist) { return filelist } +/* Collects program options */ function collectOpt (value, previous) { return previous.concat([value]) } +/* Adds template utility functions */ +function addTmplUtils (data) { + return { + ...data, + // Strips newlines + stripn: () => { + return (text, render) => { + const rendered = render(text) + return rendered ? rendered.split('\n').join(' ') : rendered + } + } + } +} + module.exports = { walkSync: walkSync, getJsonLdGraph: getJsonLdGraph, @@ -169,5 +184,6 @@ module.exports = { markActive: markActive, getDefaultContext: getDefaultContext, loadConfig: loadConfig, - collectOpt: collectOpt + collectOpt: collectOpt, + addTmplUtils: addTmplUtils } diff --git a/templates/md/index.mustache b/templates/md/index.mustache index 18461d2..9b61d70 100644 --- a/templates/md/index.mustache +++ b/templates/md/index.mustache @@ -1 +1,35 @@ -markdown will be here \ No newline at end of file +# Index + +## Navigation + +### Index +[Index](index.md) + +### {{dialectsHeader}} +{{#navData.dialects}} +{{#active}}{{name}}{{/active}} • +{{^active}}[{{name}}]({{pageName}}.md){{/active}} +{{/navData.dialects}} + +## {{mainHeader}} +{{#indexHeader}}Title: {{indexHeader}}{{/indexHeader}} +{{#indexVersion}}Version: {{indexVersion}}{{/indexVersion}} +{{#indexDescription}}Description: {{indexDescription}}{{/indexDescription}} + +## {{dialectsHeader}} +Dialect | Usage +------- | ----- +{{#dialects}} +{{name}} | {{usage}} +{{/dialects}} + +## {{schemasHeader}} +{{#dialects}} + +### {{name}} +Schema | Description +------ | ----------- +{{#nodeMappings}} +{{name}} | {{#stripn}}{{description}}{{/stripn}} +{{/nodeMappings}} +{{/dialects}} From 7fe476197795ef25702bb7725be12079f2806f36 Mon Sep 17 00:00:00 2001 From: Artem Kostiuk Date: Thu, 3 Oct 2019 10:17:31 +0300 Subject: [PATCH 10/16] Add dialect.md template. Fix index.md template --- templates/md/dialect.mustache | 33 ++++++++++++++++++++++++++++++++- templates/md/index.mustache | 19 +++++++++++++------ 2 files changed, 45 insertions(+), 7 deletions(-) diff --git a/templates/md/dialect.mustache b/templates/md/dialect.mustache index 18461d2..a273278 100644 --- a/templates/md/dialect.mustache +++ b/templates/md/dialect.mustache @@ -1 +1,32 @@ -markdown will be here \ No newline at end of file +# {{name}} + +## Navigation + +### Index +[Index](index.md) + +### {{dialectsHeader}} +{{#navData.dialects}} +• {{#active}}*{{name}}*{{/active}}{{^active}}[{{name}}]({{pageName}}.md){{/active}} +{{/navData.dialects}} + +### {{schemasHeader}} +{{#navData.nodeMappings}} +• {{#active}}*{{name}}*{{/active}}{{^active}}[{{name}}]({{pageName}}.md){{/active}} +{{/navData.nodeMappings}} + +## {{name}} +URL: {{id}} + +{{#usage}} +Description: {{#stripn}}{{usage}}{{/stripn}} +{{/usage}} + +{{#version}} +Version: {{version}} +{{/version}} + +Schemas: +{{#nodeMappings}} + * [{{name}}]({{pageName}}.md) +{{/nodeMappings}} diff --git a/templates/md/index.mustache b/templates/md/index.mustache index 9b61d70..e08fb9e 100644 --- a/templates/md/index.mustache +++ b/templates/md/index.mustache @@ -3,18 +3,25 @@ ## Navigation ### Index -[Index](index.md) +*Index* ### {{dialectsHeader}} {{#navData.dialects}} -{{#active}}{{name}}{{/active}} • -{{^active}}[{{name}}]({{pageName}}.md){{/active}} +• [{{name}}]({{pageName}}.md) {{/navData.dialects}} ## {{mainHeader}} -{{#indexHeader}}Title: {{indexHeader}}{{/indexHeader}} -{{#indexVersion}}Version: {{indexVersion}}{{/indexVersion}} -{{#indexDescription}}Description: {{indexDescription}}{{/indexDescription}} +{{#indexHeader}} +Title: {{indexHeader}} +{{/indexHeader}} + +{{#indexVersion}} +Version: {{indexVersion}} +{{/indexVersion}} + +{{#indexDescription}} +Description: {{indexDescription}} +{{/indexDescription}} ## {{dialectsHeader}} Dialect | Usage From 4a8a95582d49ecec16596541c6063f7448a958e5 Mon Sep 17 00:00:00 2001 From: Artem Kostiuk Date: Thu, 3 Oct 2019 11:03:12 +0300 Subject: [PATCH 11/16] Add node.md template --- templates/md/node.mustache | 83 +++++++++++++++++++++++++++++++++++++- 1 file changed, 82 insertions(+), 1 deletion(-) diff --git a/templates/md/node.mustache b/templates/md/node.mustache index 18461d2..89e81fb 100644 --- a/templates/md/node.mustache +++ b/templates/md/node.mustache @@ -1 +1,82 @@ -markdown will be here \ No newline at end of file +# {{dialectName}} :: {{name}} + +## Navigation + +### Index +[Index](index.md) + +### {{dialectsHeader}} +{{#navData.dialects}} +• {{#active}}*{{name}}*{{/active}}{{^active}}[{{name}}]({{pageName}}.md){{/active}} +{{/navData.dialects}} + +### {{schemasHeader}} +{{#navData.nodeMappings}} +• {{#active}}*{{name}}*{{/active}}{{^active}}[{{name}}]({{pageName}}.md){{/active}} +{{/navData.nodeMappings}} + +## {{dialectName}} :: {{name}} +Term ID: {{targetClassId}} + +{{#description}} +Description: {{#stripn}}{{description}}{{/stripn}} +{{/description}} + +{{^linkedSchemas}}No {{/linkedSchemas}} Linked Schemas +{{#linkedSchemas}} +{{#rangePageName}} + * [{{rangeName}}]({{rangePageName}}.md) +{{/rangePageName}} +{{^rangePageName}} + * {{rangeName}} +{{/rangePageName}} +{{/linkedSchemas}} + +### Scalar Properties +{{^scalarProperties}}No Scalar Properties {{/scalarProperties}} + +{{#scalarProperties}} + +#### {{name}} + +Field | Value +----- | ----- +Term ID | {{id}} +Range | {{range}} +{{#propDesc}} +Description | {{#stripn}}{{propDesc}}{{/stripn}} +{{/propDesc}} + +{{#constraints.length}} +Constraint | Value +---------- | ----- +{{#constraints}} +{{name}} | {{#stripn}}{{value}}{{/stripn}} +{{/constraints}} +{{/constraints.length}} +{{/scalarProperties}} + + +### Link Properties +{{^linkProperties}}No Link Properties {{/linkProperties}} + +{{#linkProperties}} + +#### {{name}} + +Field | Value +----- | ----- +Term ID | {{id}} +Range | {{#range}} • {{#rangePageName}}[{{rangeName}}]({{rangePageName}}.md){{/rangePageName}}{{^rangePageName}}{{rangeName}}{{/rangePageName}}{{/range}} +{{#propDesc}} +Description | {{#stripn}}{{propDesc}}{{/stripn}} +{{/propDesc}} + +{{#constraints.length}} +Constraint | Value +---------- | ----- +{{#constraints}} +{{name}} | {{#stripn}}{{value}}{{/stripn}} +{{/constraints}} +{{/constraints.length}} +{{/linkProperties}} From 6b2e6d340fe80aec418213544781f59f0b1e6071 Mon Sep 17 00:00:00 2001 From: Artem Kostiuk Date: Thu, 3 Oct 2019 11:13:19 +0300 Subject: [PATCH 12/16] Simplify markdown navigation --- templates/md/dialect.mustache | 17 +++++------------ templates/md/index.mustache | 8 ++------ templates/md/node.mustache | 17 +++++------------ 3 files changed, 12 insertions(+), 30 deletions(-) diff --git a/templates/md/dialect.mustache b/templates/md/dialect.mustache index a273278..8af683c 100644 --- a/templates/md/dialect.mustache +++ b/templates/md/dialect.mustache @@ -2,18 +2,11 @@ ## Navigation -### Index -[Index](index.md) - -### {{dialectsHeader}} -{{#navData.dialects}} -• {{#active}}*{{name}}*{{/active}}{{^active}}[{{name}}]({{pageName}}.md){{/active}} -{{/navData.dialects}} - -### {{schemasHeader}} -{{#navData.nodeMappings}} -• {{#active}}*{{name}}*{{/active}}{{^active}}[{{name}}]({{pageName}}.md){{/active}} -{{/navData.nodeMappings}} +**Index:** • [Index](index.md) + +**{{dialectsHeader}}:**{{#navData.dialects}} • {{#active}}*{{name}}*{{/active}}{{^active}}[{{name}}]({{pageName}}.md){{/active}}{{/navData.dialects}} + +**{{schemasHeader}}:**{{#navData.nodeMappings}} • {{#active}}*{{name}}*{{/active}}{{^active}}[{{name}}]({{pageName}}.md){{/active}}{{/navData.nodeMappings}} ## {{name}} URL: {{id}} diff --git a/templates/md/index.mustache b/templates/md/index.mustache index e08fb9e..51687b9 100644 --- a/templates/md/index.mustache +++ b/templates/md/index.mustache @@ -2,13 +2,9 @@ ## Navigation -### Index -*Index* +**Index:** • *Index* -### {{dialectsHeader}} -{{#navData.dialects}} -• [{{name}}]({{pageName}}.md) -{{/navData.dialects}} +**{{dialectsHeader}}:**{{#navData.dialects}} • [{{name}}]({{pageName}}.md){{/navData.dialects}} ## {{mainHeader}} {{#indexHeader}} diff --git a/templates/md/node.mustache b/templates/md/node.mustache index 89e81fb..a99dc21 100644 --- a/templates/md/node.mustache +++ b/templates/md/node.mustache @@ -2,18 +2,11 @@ ## Navigation -### Index -[Index](index.md) - -### {{dialectsHeader}} -{{#navData.dialects}} -• {{#active}}*{{name}}*{{/active}}{{^active}}[{{name}}]({{pageName}}.md){{/active}} -{{/navData.dialects}} - -### {{schemasHeader}} -{{#navData.nodeMappings}} -• {{#active}}*{{name}}*{{/active}}{{^active}}[{{name}}]({{pageName}}.md){{/active}} -{{/navData.nodeMappings}} +**Index:** • [Index](index.md) + +**{{dialectsHeader}}:**{{#navData.dialects}} • {{#active}}*{{name}}*{{/active}}{{^active}}[{{name}}]({{pageName}}.md){{/active}}{{/navData.dialects}} + +**{{schemasHeader}}:**{{#navData.nodeMappings}} • {{#active}}*{{name}}*{{/active}}{{^active}}[{{name}}]({{pageName}}.md){{/active}}{{/navData.nodeMappings}} ## {{dialectName}} :: {{name}} Term ID: {{targetClassId}} From 0a12b8ad512ed1cbb55fd11fed70ab7ee7a7e7ef Mon Sep 17 00:00:00 2001 From: Artem Kostiuk Date: Wed, 29 Jan 2020 11:10:03 +0200 Subject: [PATCH 13/16] Add index, primary, secondary links to md templates --- templates/md/dialect.mustache | 14 ++++++++++++++ templates/md/index.mustache | 8 ++++++++ 2 files changed, 22 insertions(+) diff --git a/templates/md/dialect.mustache b/templates/md/dialect.mustache index 8af683c..c578a27 100644 --- a/templates/md/dialect.mustache +++ b/templates/md/dialect.mustache @@ -19,7 +19,21 @@ Description: {{#stripn}}{{usage}}{{/stripn}} Version: {{version}} {{/version}} +{{#hasPrimaryLinks}} +Download: +{{#primaryLinks}} + * [{{text}}]({{{href}}}) +{{/primaryLinks}} +{{/hasPrimaryLinks}} + Schemas: {{#nodeMappings}} * [{{name}}]({{pageName}}.md) {{/nodeMappings}} + +{{#hasSecondaryLinks}} +Download in other formats: +{{#secondaryLinks}} + * [{{text}}]({{{href}}}) +{{/secondaryLinks}} +{{/hasSecondaryLinks}} diff --git a/templates/md/index.mustache b/templates/md/index.mustache index 51687b9..d541186 100644 --- a/templates/md/index.mustache +++ b/templates/md/index.mustache @@ -19,6 +19,14 @@ Version: {{indexVersion}} Description: {{indexDescription}} {{/indexDescription}} +{{#hasIndexLinks}} +Download as a single file in the following formats: +{{#indexLinks}} + * [{{text}}]({{{href}}}) +{{/indexLinks}} +{{/hasIndexLinks}} + + ## {{dialectsHeader}} Dialect | Usage ------- | ----- From c81d566f27ea1f9c35b044ad90d4e14062e8e47d Mon Sep 17 00:00:00 2001 From: Artem Kostiuk Date: Wed, 29 Jan 2020 11:48:26 +0200 Subject: [PATCH 14/16] Add tests. Fix labels --- README.md | 1 + src/utils.js | 16 +++++---- templates/md/dialect.mustache | 6 ++-- templates/md/index.mustache | 8 ++--- templates/md/node.mustache | 6 ++-- test/integration.test.js | 67 +++++++++++++++++++++++++++++++++++ test/utils.test.js | 27 ++++++++++++++ 7 files changed, 114 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index fb09321..45030c2 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ # aml2doc [![Build Status](https://travis-ci.org/aml-org/aml2doc.svg?branch=master)](https://travis-ci.org/aml-org/aml2doc) + Convert AML Vocabularies & Dialects to documentation. ## Installation diff --git a/src/utils.js b/src/utils.js index 155c22f..df18bfc 100644 --- a/src/utils.js +++ b/src/utils.js @@ -239,13 +239,15 @@ function getOntologyTerms (ontologyObj) { function addTmplUtils (data) { return { ...data, - // Strips newlines - stripn: () => { - return (text, render) => { - const rendered = render(text) - return rendered ? rendered.split('\n').join(' ') : rendered - } - } + stripn: stripn + } +} + +/* Strips newlines */ +function stripn () { + return (text, render) => { + const rendered = render(text) + return rendered ? rendered.split('\n').join(' ') : rendered } } diff --git a/templates/md/dialect.mustache b/templates/md/dialect.mustache index c578a27..6f6f23d 100644 --- a/templates/md/dialect.mustache +++ b/templates/md/dialect.mustache @@ -1,4 +1,4 @@ -# {{name}} +# {{label}} ## Navigation @@ -8,7 +8,7 @@ **{{schemasHeader}}:**{{#navData.nodeMappings}} • {{#active}}*{{name}}*{{/active}}{{^active}}[{{name}}]({{pageName}}.md){{/active}}{{/navData.nodeMappings}} -## {{name}} +## {{label}} URL: {{id}} {{#usage}} @@ -28,7 +28,7 @@ Download: Schemas: {{#nodeMappings}} - * [{{name}}]({{pageName}}.md) + * [{{label}}]({{pageName}}.md) {{/nodeMappings}} {{#hasSecondaryLinks}} diff --git a/templates/md/index.mustache b/templates/md/index.mustache index d541186..a024b41 100644 --- a/templates/md/index.mustache +++ b/templates/md/index.mustache @@ -2,7 +2,7 @@ ## Navigation -**Index:** • *Index* +**Index:** • Index **{{dialectsHeader}}:**{{#navData.dialects}} • [{{name}}]({{pageName}}.md){{/navData.dialects}} @@ -31,16 +31,16 @@ Download as a single file in the following formats: Dialect | Usage ------- | ----- {{#dialects}} -{{name}} | {{usage}} +{{label}} | {{usage}} {{/dialects}} ## {{schemasHeader}} {{#dialects}} -### {{name}} +### {{label}} Schema | Description ------ | ----------- {{#nodeMappings}} -{{name}} | {{#stripn}}{{description}}{{/stripn}} +{{label}} | {{#stripn}}{{description}}{{/stripn}} {{/nodeMappings}} {{/dialects}} diff --git a/templates/md/node.mustache b/templates/md/node.mustache index a99dc21..16a8440 100644 --- a/templates/md/node.mustache +++ b/templates/md/node.mustache @@ -1,4 +1,4 @@ -# {{dialectName}} :: {{name}} +# {{dialectName}} :: {{label}} ## Navigation @@ -8,14 +8,14 @@ **{{schemasHeader}}:**{{#navData.nodeMappings}} • {{#active}}*{{name}}*{{/active}}{{^active}}[{{name}}]({{pageName}}.md){{/active}}{{/navData.nodeMappings}} -## {{dialectName}} :: {{name}} +## {{dialectName}} :: {{label}} Term ID: {{targetClassId}} {{#description}} Description: {{#stripn}}{{description}}{{/stripn}} {{/description}} -{{^linkedSchemas}}No {{/linkedSchemas}} Linked Schemas +{{^linkedSchemas}}No {{/linkedSchemas}}Linked schemas {{#linkedSchemas}} {{#rangePageName}} * [{{rangeName}}]({{rangePageName}}.md) diff --git a/test/integration.test.js b/test/integration.test.js index 2678f2a..ae09b38 100644 --- a/test/integration.test.js +++ b/test/integration.test.js @@ -85,3 +85,70 @@ describe('aml2doc html integration test', function () { .to.contain('No Link Properties') }) }) + +describe('aml2doc md integration test', function () { + let outDir + before(async function () { + outDir = tmp.dirSync() + const program = { + outputDir: outDir.name, + cfg: path.join(FIXTURES_DIR, 'cfg.js'), + infile: [ + path.join(FIXTURES_DIR, 'musicDialect.yaml') + ], + css: ['inexisting/css/file.css'], + templates: path.join(__dirname, '..', 'templates'), + syntax: 'md' + } + await aml2doc(program) + }) + after(function () { + try { fs.removeSync(outDir.name) } catch (e) {} + }) + it('should render templates', function () { + expect(fs.readdirSync(outDir.name)).to.deep.equal([ + 'index.md', + 'playlist.md', + 'schema_playlist_artistnode.md', + 'static' + ]) + expect(fs.readdirSync(path.join(outDir.name, 'static'))) + .to.deep.equal(['css']) + expect(fs.readdirSync(path.join(outDir.name, 'static', 'css'))) + .to.deep.equal([ + 'bootstrap.min.css', + 'custom.css' + ]) + }) + it('should render proper data at index page', function () { + const fpath = path.join(outDir.name, 'index.md') + const md = fs.readFileSync(fpath).toString() + expect(md) + .to.contain('playlist.md').and + .to.contain('Playlist_modified').and + .to.contain('ArtistNode_modified').and + .to.contain('hi://test.else/vocabulary.aml').and + .to.contain('hi://test.com/vocabulary.pdf').and + .to.contain('hi://test.com/vocabulary.txt') + }) + it('should render proper data at dialect page', function () { + const fpath = path.join(outDir.name, 'playlist.md') + const md = fs.readFileSync(fpath).toString() + expect(md) + .to.contain('index.md').and + .to.contain('schema_playlist_artistnode.md').and + .to.contain('Version:').and + .to.contain('ArtistNode_modified').and + .to.contain('musicDialect.yaml_modified') + }) + it('should render proper data at schema page', function () { + const fpath = path.join(outDir.name, 'schema_playlist_artistnode.md') + const md = fs.readFileSync(fpath).toString() + expect(md) + .to.contain('index.md').and + .to.contain('No Linked schemas').and + .to.contain('schema.org').and + .to.contain('string').and + .to.contain('No Link Properties') + }) +}) diff --git a/test/utils.test.js b/test/utils.test.js index bf73fef..bda5ad3 100644 --- a/test/utils.test.js +++ b/test/utils.test.js @@ -347,3 +347,30 @@ describe('utils.getOntologyTerms', function () { }) }) }) + +describe('utils.addTmplUtils', function () { + const addTmplUtils = utils.__get__('addTmplUtils') + it('should add template utility functions to an object', function () { + const obj = addTmplUtils({ foo: 1 }) + expect(obj).to.have.property('foo', 1) + expect(obj).to.have.property('stripn') + }) +}) + +describe('utils.stripn', function () { + const stripn = utils.__get__('stripn') + it('should rendex text and remove newlines from it', function () { + const fn = stripn() + const stripped = fn( + 'hello\nworld\nagain', + x => x + '\nmore') + expect(stripped).to.equal('hello world again more') + }) + context('when it fails to renders text', function () { + it('should returned render results as is', function () { + const fn = stripn() + const stripped = fn('hello\nworld\nagain', x => null) + expect(stripped).to.equal(null) + }) + }) +}) From d2bd94f3b0f5f670a336df44f39ed531acf8b0bb Mon Sep 17 00:00:00 2001 From: Artem Kostiuk Date: Wed, 29 Jan 2020 11:54:44 +0200 Subject: [PATCH 15/16] Add tests for md union page --- test/integration.test.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/integration.test.js b/test/integration.test.js index 2c25044..1b7e244 100644 --- a/test/integration.test.js +++ b/test/integration.test.js @@ -118,6 +118,7 @@ describe('aml2doc md integration test', function () { 'index.md', 'playlist.md', 'schema_playlist_artistnode.md', + 'schema_playlist_artistunion.md', 'static' ]) expect(fs.readdirSync(path.join(outDir.name, 'static'))) @@ -145,6 +146,7 @@ describe('aml2doc md integration test', function () { expect(md) .to.contain('index.md').and .to.contain('schema_playlist_artistnode.md').and + .to.contain('schema_playlist_artistunion.md').and .to.contain('Version:').and .to.contain('ArtistNode_modified').and .to.contain('musicDialect.yaml_modified') @@ -159,4 +161,9 @@ describe('aml2doc md integration test', function () { .to.contain('string').and .to.contain('No Link Properties') }) + it('should render proper data at union schema page', function () { + const fpath = path.join(outDir.name, 'schema_playlist_artistunion.md') + const md = fs.readFileSync(fpath).toString() + expect(md).to.contain('Union of ArtistNode, ArtistNode') + }) }) From d68120b72e69e20271025fc8e6710ae02d8f8e5c Mon Sep 17 00:00:00 2001 From: Artem Kostiuk Date: Tue, 3 Mar 2020 11:00:47 +0200 Subject: [PATCH 16/16] Rename export --- src/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index dbb45fa..229f402 100644 --- a/src/index.js +++ b/src/index.js @@ -9,7 +9,7 @@ const collect = require('./data_collectors') let TMPL_DIR = path.join(utils.TMPL_DIR) /** Runs all the logic. */ -async function aml2html (program) { +async function aml2doc (program) { let ctx = utils.getDefaultContext() await amf.AMF.init() @@ -119,4 +119,4 @@ async function aml2html (program) { utils.copyStaticFiles(outDir) } -module.exports = aml2html +module.exports = aml2doc