const fs = require('fs'); const path = require('path'); const showdown = require('showdown'); module.exports = (config) => { const converter = new showdown.Converter(config['showdown']); /** * get parts outside of codes/scripts * @param {string} data * @returns {{index:number, end:number, text:string}[]} parts */ const getParts = (data) => { let parts = []; let match; let i = 0; while ((match = /```/m.exec(data.slice(i)))) { parts.push({ index: i, text: data.slice(i, i + match.index), }); i += match.index + match[0].length; } if (i < data.length) { parts.push({ index: i, text: data.slice(i, data.length), }); } parts = parts.filter((p, i) => i % 2 === 0); //filter out code parts // detect scripts outside of code parts.forEach((p, pi) => { let i = 0; const subParts = []; while ((match = /(