@inyur/markdown-to-html
Install
npm i -S @inyur/markdown-to-html
Usage
import md2html from '@inyur/markdown-to-html';
const someMdFileContent = require('fs').readFileSync('./some.md', 'utf8');
const html = await md2html(someMdFileContent);
const someMdFileContentPromised = import('./some.md')
.then(module=> module.defult);
const html = await md2html(someMdFileContentPromised);
const someMdFileContentPromised = import('./some.md');
const html = await md2html(someMdFileContentPromised);
const html = await md2html(import('./some.md'));
In general cases markdown-to-html return html string, except this called with special parameter extended
Advanced usage:
const options = {
}
const html = await md2html('Md text or promise or esmodule', options);
options
this is object of some props (see next)
options.links
Can be Array of (Objects of Strings or Functions)
Can be Array of Functions
Can be Object of Strings or Functions
Can be Function
const options = {
links: [{
alfaUrl: 'https://alfa.net',
betaUrl: (url, node) => {
if (url.host !== 'internal.site') {
node.properties.target = '_blank'
}
return 'https://beta.com'
},
}]
}
options.variables
Can be Object
const options = {
variables: {
someTextVariable: 'Some Value'
}
}
const html = await md2html('Md text ${someTextVariable}', options);
options.extended
markdown-to-html return Object of:
const {
markdown,
title,
template,
html,
data,
headings,
toString,
} = await md2html('Md text or promise or esmodule', options);
options.splitTitle
Boolean, default false
In extended version returned object with html without title and title prop.