diff --git a/modules/api_v2.js b/modules/api_v2.js index 4c74818..9109328 100644 --- a/modules/api_v2.js +++ b/modules/api_v2.js @@ -59,3 +59,13 @@ app.get('/api/v2/hitokoto', async (req, res) => { res.status(500).send({ e: e }); } }); + +app.post('/api/v2/markdown', async (req, res) => { + try { + let s = await syzoj.utils.markdown(req.body.s.toString(), null, req.body.noReplaceUI === 'true'); + res.send(s); + } catch (e) { + syzoj.log(e); + res.send(e); + } +}); diff --git a/utility.js b/utility.js index f176508..ae5def6 100644 --- a/utility.js +++ b/utility.js @@ -48,7 +48,7 @@ function highlightPygmentize(code, lang, cb) { format: 'html', options: { nowrap: true, - classprefix: 'pl-' + classprefix: 'pl-' } }, code, (err, res) => { if (err || res.toString() === 'undefined') { @@ -67,8 +67,9 @@ module.exports = { a.unshift(__dirname); return path.resolve.apply(null, a); }, - markdown(obj, keys) { + markdown(obj, keys, noReplaceUI) { let replaceUI = s => { + if (noReplaceUI) return s; return s.split('
').join('
').split('
').join('
') .split('').join('
') .split('
').join('
').split('
').join('');