docs-license/scripts/ejs.js

37 lines
914 B
JavaScript
Raw Permalink Normal View History

2024-08-12 13:08:06 +00:00
/*
* md2html
* Copyright 2019 2SC1815J, MIT license
*/
'use strict';
if (process.argv.length < 4) {
console.error('Usage: node ejs.js template.html output.html');
process.exit(1);
}
const { promisify } = require('util');
const ejs = require('ejs');
const tidy = require('htmltidy2');
const fs = require('fs');
(async () => {
const text = await promisify(ejs.renderFile)(process.argv[2]);
const options = {
doctype: 'html5',
indent: 'auto',
wrap: 0,
tidyMark: false,
quoteAmpersand: false,
hideComments: true,
dropEmptyElements: false,
newline: 'LF'
};
const tidied = await promisify(tidy.tidy)(text, options);
await promisify(fs.writeFile)(process.argv[3], tidied, 'utf8');
})()
.then(() => {
console.log('Done.');
})
.catch((err) => {
console.error(err);
process.exit(1);
});