UNPKG

xops-pat

Version:

Procedure generator for on space operations

51 lines (40 loc) 1.36 kB
#!/usr/bin/env node /** * This helper converts markdown to html. */ 'use strict'; const showdown = require('showdown'); const wiky = require('wiky'); /** * Convert markdown to HTML and replace special indicators (like {{CHECKBOX}}) * with unicode symbols * * @param {string} markdown Markdown input * @return {string} HTML with unicode characters, or an empty string if * an error occurs */ exports.convert = function(markdown) { var regex; if (markdown === null || (typeof markdown !== 'string')) { return ''; } // Find and replace check marks markdown = markdown.replace(/{{CHECK}}/gi, '✓'); // Find and replace check boxes markdown = markdown.replace(/{{CHECKBOX}}/gi, '❏'); markdown = markdown.replace(/{{CHECK BOX}}/gi, '❏'); // TODO: Why does checmkark actually mean checkbox? markdown = markdown.replace(/{{CHECKMARK}}/gi, '❏'); markdown = markdown.replace(/{{CHECK MARK}}/gi, '❏'); // Find and replace emphasis markdown? if (markdown.includes("'''")) { regex = /(['])+/gi; markdown = markdown.replace(regex, '*'); } if (markdown.includes('**')) { regex = /([*])+/gi; markdown = markdown.replace(regex, '*'); } const text = wiky.toHtml(markdown); return new showdown.Converter().makeHtml(text); };