module.exports = { friendlyName: 'To HTML', description: 'Compile a Markdown string into an HTML string.', extendedDescription: 'Expects GitHub-flavored Markdown syntax. Uses [`marked`](https://github.com/chjj/marked)@v0.3.5. '+ 'Inspired by https://github.com/mikermcneil/machinepack-markdown/tree/5d8cee127e8ce45c702ec9bbb2b4f9bc4b7fafac', moreInfoUrl: 'https://help.github.com/articles/basic-writing-and-formatting-syntax/', sideEffects: 'cacheable', inputs: { mdString: { description: 'Markdown string to convert', example: '# hello world\n it\'s me, some markdown string \n\n ```js\n//but maybe i have code snippets too...\n```', required: true }, allowHtml: { friendlyName: 'Allow HTML?', description: 'Whether or not to allow HTML tags in the Markdown input. Defaults to `true`.', extendedDescription: 'If `false`, any input that contains HTML tags will trigger the `unsafeMarkdown` exit.', example: true, defaultsTo: true }, addIdsToHeadings: { friendlyName: 'Add IDs to headings?', description: 'Whether or not to add an ID attribute to rendered heading tags like
it's me, some markdown string
\n//but maybe i have code snippets too...\n'
},
unsafeMarkdown: {
friendlyName: 'Unsafe Markdown detected',
description: 'The provided input contained unsafe content (like HTML tags).'
}
},
fn: function(inputs, exits) {
const { marked } = require('marked');
// For full list of options, see:
// • https://github.com/chjj/marked
var markedOpts = {
gfm: true,
tables: true,
breaks: false,
pedantic: false,
smartLists: true,
smartypants: false,
};
let customRenderer = new marked.Renderer();
if (inputs.addIdsToHeadings === true) {
var headingsRenderedOnThisPage = [];
customRenderer.heading = function (text, level) {
// If the heading has underscores and no spaces (e.g. osquery_async_host_collect_log_stats_interval) we'll add optional linebreaks before each underscore
var textWithLineBreaks;
if(text.match(/\S(\w+\_\S)+(\w\S)+/g) && !text.match(/\s/g)){
textWithLineBreaks = text.replace(/(\_)/g, '_');
}
var headingID = _.kebabCase(_.unescape(text.toLowerCase()).replace(/[\’\']/g, ''));
if(!_.contains(headingsRenderedOnThisPage, headingID)){
headingsRenderedOnThisPage.push(headingID);
} else {
headingID = sails.helpers.strings.ensureUniq(headingID, headingsRenderedOnThisPage);
headingsRenderedOnThisPage.push(headingID);
}
return ' tags.
customRenderer.code = function(code, infostring) {
if(infostring === 'mermaid') {
return `${_.escape(code)}`;
} else if(infostring === 'js') {// Interpret `js` as `javascript`
return `${_.escape(code)}
`;
} else if(infostring === 'bash' || infostring === 'sh') {// Interpret `sh` and `bash` as `bash`
return `${_.escape(code)}
`;
} else if(infostring !== '') {// leaving the code language as-is if the infoString is anything else.
return `${_.escape(code)}
`;
} else {// When unspecified, default to `text`
return `${_.escape(code)}
`;
}
};
// Creating a custom blockquote renderer function to render blockquotes as tip blockquotes.
customRenderer.blockquote = function(blockquoteHtml) {
return `
\n${blockquoteHtml}\n
`;
};
// Custom renderer function to enable checkboxes in Markdown lists.
customRenderer.listitem = function(innerHtml, hasCheckbox, isChecked) {
if(!hasCheckbox){ // « If a list item does not have a checkbox, we'll render it normally.
return `