/*
* This file is part of moemark-renderer.
*
* Copyright (c) 2016 Menci
' + result + '
'; else maths[id] = result; if (cacheOption.math) cache.set('M_' + display + '_' + str, maths[id]); if (!--mathPending) finish(); } const id = mathCnt; mathCnt++, mathPending++; try { let x = cache.get('M_' + display + '_' + str); if (x !== undefined) process.nextTick(() => mathFinish(null, x)); else { let res = katex.renderToString(str, { displayMode: display }); process.nextTick(() => mathFinish(null, '' + res + '')); } } catch (e) { mj.typeset({ math: str, format: display ? 'TeX' : 'inline-TeX', svg: true, width: 0 }, data => { mathFinish(data.errors, data.svg); }); } return mathID[id] = uuid(); } }); function finish() { if (finished || !res || mathPending || hlPending) return; finished = true; if (maths.length || hls.length) { for (let i = 0; i < maths.length; i++) { res = res.replace(mathID[i], maths[i]); } for (let i = 0; i < hls.length; i++) { res = res.replace(hlID[i], hls[i]); } } if (cacheOption.result) cache.set('RES_' + s, res); cb(res); } try { let XSS = require('xss'); let CSSFilter = require('cssfilter'); let whiteList = Object.assign({}, require('xss/lib/default').whiteList); delete whiteList.audio; delete whiteList.video; for (let tag in whiteList) whiteList[tag] = whiteList[tag].concat(['style', 'class']); let xss = new XSS.FilterXSS({ whiteList: whiteList, stripIgnoreTag: true, onTagAttr: (tag, name, value, isWhiteAttr) => { if (tag.toLowerCase() === 'img' && name.toLowerCase() === 'src' && value.startsWith('data:image/')) return name + '="' + XSS.escapeAttrValue(value) + '"'; } }); let replaceXSS = s => { s = xss.process(s); if (s) { s = ` `; } return s; }; res = replaceXSS(MoeMark(s)); if (mathPending == 0 && hlPending == 0) { finish(); } } catch(e) { cb(e); } }; render.moemark = MoeMark; render.cache = defaultCache; render.cacheOption = { highlight: true, math: true, result: false }; render.config = config; module.exports = render;