@inyur/markdown-to-html
v1.0.5
Published
```bash npm i -S @inyur/markdown-to-html ```
Downloads
10
Readme
@inyur/markdown-to-html
Install
npm i -S @inyur/markdown-to-html
Usage
import md2html from '@inyur/markdown-to-html';
// Variant 1
const someMdFileContent = require('fs').readFileSync('./some.md', 'utf8');
const html = await md2html(someMdFileContent);
// Variant 2
// Internaly md2html has promise resolver if promise found and
// has object default getter.
const someMdFileContentPromised = import('./some.md')
.then(module=> module.defult);
const html = await md2html(someMdFileContentPromised);
// Or This simplified works too
const someMdFileContentPromised = import('./some.md');
const html = await md2html(someMdFileContentPromised);
// Or This simplified works too
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, // initial markdown source
title, // returns if splitTitle prop is true
template, // Handlebars template, useful for reuse template
html, // Compiled template as === template(variables)
data, // Returned data from frontMatter
headings, // Returned H1-6 structure
toString, // Function for usage as text === toString() { return template(variables); }
} = 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.