Browse Source

Add noReplaceUI option for markdown API

master
Menci 8 years ago
parent
commit
cec300e7b6
  1. 10
      modules/api_v2.js
  2. 5
      utility.js

10
modules/api_v2.js

@ -59,3 +59,13 @@ app.get('/api/v2/hitokoto', async (req, res) => {
res.status(500).send({ e: e }); 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);
}
});

5
utility.js

@ -48,7 +48,7 @@ function highlightPygmentize(code, lang, cb) {
format: 'html', format: 'html',
options: { options: {
nowrap: true, nowrap: true,
classprefix: 'pl-' classprefix: 'pl-'
} }
}, code, (err, res) => { }, code, (err, res) => {
if (err || res.toString() === 'undefined') { if (err || res.toString() === 'undefined') {
@ -67,8 +67,9 @@ module.exports = {
a.unshift(__dirname); a.unshift(__dirname);
return path.resolve.apply(null, a); return path.resolve.apply(null, a);
}, },
markdown(obj, keys) { markdown(obj, keys, noReplaceUI) {
let replaceUI = s => { let replaceUI = s => {
if (noReplaceUI) return s;
return s.split('<pre>').join('<div class="ui existing segment"><pre style="margin-top: 0; margin-bottom: 0; ">').split('</pre>').join('</pre></div>') return s.split('<pre>').join('<div class="ui existing segment"><pre style="margin-top: 0; margin-bottom: 0; ">').split('</pre>').join('</pre></div>')
.split('<table>').join('<table class="ui table">') .split('<table>').join('<table class="ui table">')
.split('<blockquote>').join('<div class="ui message">').split('</blockquote>').join('</div>'); .split('<blockquote>').join('<div class="ui message">').split('</blockquote>').join('</div>');

Loading…
Cancel
Save