generated from r-ca/md2pdf-meow
Initial commit
This commit is contained in:
commit
1413570518
15 files changed
+7044
No files matched your search
@@ -0,0 +1,29 @@
|
||||
import PuppeteerHTMLPDF from 'puppeteer-html-pdf';
|
||||
|
||||
async function generatePDF() {
|
||||
const htmlPdf = new PuppeteerHTMLPDF();
|
||||
|
||||
htmlPdf.setOptions({
|
||||
format: "A4",
|
||||
margin: {
|
||||
top: "16mm",
|
||||
right: "16mm",
|
||||
bottom: "16mm",
|
||||
left: "16mm"
|
||||
},
|
||||
});
|
||||
|
||||
try {
|
||||
const html = await htmlPdf.readFile(`${__dirname}/../dist/all.html`, "utf8");
|
||||
|
||||
const pdfBuffer = await htmlPdf.create(html);
|
||||
const path = `${__dirname}/../dist/result.pdf`;
|
||||
await htmlPdf.writeFile(pdfBuffer, path);
|
||||
|
||||
console.log("PDF created successfully");
|
||||
} catch (error) {
|
||||
console.error("Error creating PDF", error);
|
||||
}
|
||||
}
|
||||
|
||||
generatePDF();
|
||||
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