A thin and simple pandoc wrapper function
simple-pandoc
provides probably the thinest and simplest Node.js binding for
pandoc. It just wraps the pandoc
command into JavaScript APIs.
It focuses on a very simple use case, and may not provide complicated functionalities. If they are needed, please check out other libraries on npm.
simple-pandoc
doesn't provide pandoc
in itself. Please be sure to install
pandoc in your machine and place the binary in $PATH
. To install pandoc,
please refer to the Installing section
in the pandoc documentation.
To install simple-pandoc
, use npm.
$ npm install simple-pandoc
Please import simple-pandoc
with ES Modules or CommonJS.
const pandoc = require('simple-pandoc');
pandoc(from, to)
-
from
:String
a format specified in the pandoc documentation -
to
:String
a format specified in the pandoc documentation -
return:
Function
a converter function
Example:
const htmlToMarkdown = pandoc('html', 'markdown');
converter(content)
-
content
:String|Buffer
content in thefrom
format to be converted -
return:
Promise<Buffer>
promised content in theto
format
Example:
const htmlToMarkdown = pandoc('html', 'markdown');
htmlToMarkdown(fs.readFileSync('index.html'))
.then(md => {
console.log(md.toString());
});
Even better with async/await:
const htmlToMarkdown = pandoc('html', 'markdown');
async function convert() {
const html = fs.readFileSync('index.html');
const md = await htmlToMarkdown(html);
console.log(md.toString());
}
convert();
converter.stream(readStream)
-
readStream
:Readable
a stream conveying content in thefrom
format -
return:
Readable
a stream conveying converted content in theto
format
Example:
const htmlToMarkdown = pandoc('html', 'markdown');
const inputStream = fs.createReadStream('index.html');
const outputStream = fs.createWriteStream('index.md');
htmlToMarkdown.stream(inputStream).pipe(outputStream);
MIT © Jun