Skip to content
This repository was archived by the owner on Jul 26, 2020. It is now read-only.

Commit eedbd03

Browse files
committed
API - Add /html method to Page model, use showdown to parse markdown to html
1 parent add88c4 commit eedbd03

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

Diff for: common/models/page.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
var Showdown = require('showdown');
2+
3+
module.exports = function (Page) {
4+
5+
var converter = new Showdown.converter();
6+
7+
Page.html = function (id, cb) {
8+
Page.findById(id, function (err, page) {
9+
if (err) return cb(err);
10+
var result = page;
11+
result.html = converter.makeHtml(page.content);
12+
cb(err, result);
13+
});
14+
};
15+
16+
Page.remoteMethod('html', {
17+
accepts: {arg: 'id', type: 'string'},
18+
returns: {arg: 'content', type: 'string'},
19+
http: {path: '/html', verb: 'get'}
20+
});
21+
22+
};

Diff for: package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
"loopback-boot": "^2.1.0",
2828
"loopback-component-storage": "^1.0.5",
2929
"loopback-connector-mongodb": "^1.4.4",
30-
"serve-favicon": "^2.1.5"
30+
"serve-favicon": "^2.1.5",
31+
"showdown": "^0.3.1"
3132
},
3233
"optionalDependencies": {
3334
"loopback-explorer": "^1.3.0"

0 commit comments

Comments
 (0)