-
Notifications
You must be signed in to change notification settings - Fork 102
/
babelmark.js
29 lines (24 loc) · 892 Bytes
/
babelmark.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
const express = require('express');
const SimpleMarkdown = require('./simple-markdown');
const app = express();
const packagejson = require('./package.json');
// Use <p> tags instead of <div class="paragraph"> for compatibility
const rules = Object.assign({}, SimpleMarkdown.defaultRules, {
paragraph: Object.assign({}, SimpleMarkdown.defaultRules.paragraph, {
html: (node, output, state) => {
return SimpleMarkdown.htmlTag('p', output(node.content, state));
},
}),
});
const parse = SimpleMarkdown.parserFor(rules);
const output = SimpleMarkdown.outputFor(rules, 'html');
app.get('/api/babelmark', (req, res) => {
const source = req.query.text || "please provide a \\?text= param";
const result = output(parse(source));
res.json({
name: 'simple-markdown.js',
version: packagejson.version,
html: result
});
});
app.listen(process.env.PORT || 3000);