FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

WIP: Add markdown to article body and comments · alainyog/JavaScript.com@7e3220e · GitHub

Repository navigation

Commit 7e3220e

Browse files
joeltaylor
committed
WIP: Add markdown to article body and comments
1 parent ad3fad3 commit 7e3220e

2 files changed

Lines changed: 14 additions & 5 deletions

File tree

‎server/controllers/news.js‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ var cookieParser = require('cookie-parser')();
66
var moment = require('moment');
77
var pluralize = require('pluralize');
88
var expressValidator = require('express-validator');
9+
var marked = require('marked');
910
var Articles = require(path.join(__dirname, '..', 'models', 'articles'));
1011
var Users = require(path.join(__dirname, '..', 'models', 'users'));
1112
var Akismetor = require(path.join(__dirname, '..', 'services', 'akismetor'));
@@ -94,15 +95,16 @@ router.
9495

9596
Articles.findBySlug(req.params.slug, function(err, doc) {
9697
if(doc){
97-
res.render('news/show', { doc: doc, user: user, token: req.csrfToken(), moment: moment, pluralize: pluralize });
98+
// doc.body = marked(doc.body); // This sync compiling can become costly
99+
res.render('news/show', { doc: doc, user: user, token: req.csrfToken(), moment: moment, pluralize: pluralize, marked: marked });
98100
}else{
99101
res.render('404');
100102
}
101103
});
102104
}).
103105

104106
post('/:slug([a-zA-Z0-9_.-]+)/comment', cookieParser, authenticator.authorize, parseForm, expressValidator(), csrfProtection, buildComment, function(req, res) {
105-
req.sanitize('body').trim();
107+
req.sanitize('body').escape().trim();
106108
req.check('body').notEmpty();
107109

108110
var errors = req.validationErrors();
@@ -118,7 +120,10 @@ router.
118120
}
119121
}).
120122

121-
put('/:slug([a-zA-Z0-9_.-]+)/comment/:id([a-zA-Z0-9_.-]+)', cookieParser, authenticator.authorize, parseForm, csrfProtection, function(req, res) {
123+
put('/:slug([a-zA-Z0-9_.-]+)/comment/:id([a-zA-Z0-9_.-]+)', cookieParser, authenticator.authorize, parseForm, expressValidator(), csrfProtection, function(req, res) {
124+
req.sanitize('body').escape().trim();
125+
req.check('body').notEmpty();
126+
122127
var args = {
123128
updatedComment : req.body.body,
124129
commentId : req.params.id,
@@ -151,6 +156,9 @@ router.
151156

152157
post('/', cookieParser, authenticator.authorize, parseForm, addhttp, expressValidator(), csrfProtection, function(req, res) {
153158

159+
req.sanitize('body').escape().trim();
160+
req.check('body').notEmpty();
161+
154162
// Validations
155163
req.check('title','Title is required' ).notEmpty();
156164
req.check('url', 'URL is required').notEmpty();

‎server/views/news/show.jade‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ block content
3333
li.list-item
3434
a.dib.js-createComment-number.js-editComment-number(href='#comments')= pluralize('Comment', doc.comment_count, true)
3535

36-
p.well.well--l.tsl= doc.body
36+
p.well.well--l.tsl!= marked(doc.body)
3737

3838
- commentsClass = doc.comment_count == 0 ? 'is-empty' : ''
3939
aside#comments.js-createComment-container(role='complementary' class=commentsClass)
@@ -59,7 +59,8 @@ block content
5959
.split-cell
6060
button.link.js-editComment-editBtn Edit
6161

62-
p.mbf.js-editComment-comment= comment.body
62+
.mbf.js-editComment-comment
63+
!= marked(comment.body)
6364

6465
if comment.user.id == user.id
6566

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL