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

Commit

Permalink
API - Add /html method to Page model, use showdown to parse markdown …
Browse files Browse the repository at this point in the history
…to html
  • Loading branch information
beeman committed Oct 19, 2014
1 parent add88c4 commit eedbd03
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
22 changes: 22 additions & 0 deletions common/models/page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
var Showdown = require('showdown');

module.exports = function (Page) {

var converter = new Showdown.converter();

Page.html = function (id, cb) {
Page.findById(id, function (err, page) {
if (err) return cb(err);
var result = page;
result.html = converter.makeHtml(page.content);
cb(err, result);
});
};

Page.remoteMethod('html', {
accepts: {arg: 'id', type: 'string'},
returns: {arg: 'content', type: 'string'},
http: {path: '/html', verb: 'get'}
});

};
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
"loopback-boot": "^2.1.0",
"loopback-component-storage": "^1.0.5",
"loopback-connector-mongodb": "^1.4.4",
"serve-favicon": "^2.1.5"
"serve-favicon": "^2.1.5",
"showdown": "^0.3.1"
},
"optionalDependencies": {
"loopback-explorer": "^1.3.0"
Expand Down

0 comments on commit eedbd03

Please sign in to comment.