Template
mirror of
https://github.com/r-ca/md2pdf-meow.git
synced 2026-11-08 19:37:36 +00:00
copy
This commit is contained in:
commit
8d8b3251da
11 files changed
+5003
No files matched your search
Executable
+37
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* 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);
|
||||
});
|
||||
Executable
+46
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* md2html
|
||||
* Copyright 2019 2SC1815J, MIT license
|
||||
*/
|
||||
'use strict';
|
||||
if (process.argv.length < 4) {
|
||||
console.error('Usage: node mdit.js input.md output.html');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const header_instances = {};
|
||||
const anchor = require('anchor-markdown-header');
|
||||
const mdit = require('markdown-it')(
|
||||
{
|
||||
html: true
|
||||
})
|
||||
.use(require('markdown-it-named-headers'), {
|
||||
slugify: function(header) {
|
||||
if (header_instances[header] !== void 0) {
|
||||
header_instances[header]++;
|
||||
} else {
|
||||
header_instances[header] = 0;
|
||||
}
|
||||
const match = anchor(header, 'github.com', header_instances[header]).match(/]\(#(.+?)\)$/);
|
||||
return match ? decodeURI(match[1]) : header;
|
||||
}
|
||||
})
|
||||
.use(require('markdown-it-implicit-figures'), {
|
||||
figcaption: true
|
||||
});
|
||||
|
||||
const { promisify } = require('util');
|
||||
const fs = require('fs');
|
||||
|
||||
(async () => {
|
||||
const md = await promisify(fs.readFile)(process.argv[2], 'utf8');
|
||||
const html = mdit.render(md);
|
||||
await promisify(fs.writeFile)(process.argv[3], html, 'utf8');
|
||||
})()
|
||||
.then(() => {
|
||||
console.log('Done.');
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(err);
|
||||
process.exit(1);
|
||||
});
|
||||
Reference in new issue
Block a user