Skip to content

Node.js based forum software built for the modern web

closed #104 - anchors now have rel="nofollow" and open in a new window

Julian Lamf40bf46656f3
diff --git a/package.json b/package.json
index 054d3bd315..9927699e79 100644
--- a/package.json
+++ b/package.json
@@ -31,7 +31,8 @@
"node-rss": "1.0.1",
"gravatar": "1.0.6",
"nconf": "~0.6.7",
- "sitemap": "~0.6.0"
+ "sitemap": "~0.6.0",
+ "cheerio": "~0.12.0"
},
"bugs": {
"url": "https://github.com/designcreateplay/NodeBB/issues"
diff --git a/src/postTools.js b/src/postTools.js
index 6434a3cc22..4797e3dc65 100644
--- a/src/postTools.js
+++ b/src/postTools.js
@@ -4,13 +4,9 @@ var RDB = require('./redis.js'),
threadTools = require('./threadTools.js'),
user = require('./user.js'),
async = require('async'),
- marked = require('marked'),
+
utils = require('../public/src/utils');
-marked.setOptions({
- breaks: true
-});
-
(function(PostTools) {
PostTools.isMain = function(pid, tid, callback) {
RDB.lrange('tid:' + tid + ':posts', 0, 0, function(err, pids) {
@@ -142,5 +138,22 @@ marked.setOptions({
});
}
+ PostTools.markdownToHTML = function(md) {
+ var marked = require('marked'),
+ cheerio = require('cheerio');
+
+ marked.setOptions({
+ breaks: true
+ });
+
+ if (md.length > 0) {
+ var parsedContentDOM = cheerio.load(marked(md));
+ parsedContentDOM('a').attr('rel', 'nofollow').attr('target', '_blank');
+ html = parsedContentDOM.html();
+ } else html = '<p></p>';
+
+ return html;
+ }
+
}(exports));
\ No newline at end of file
diff --git a/src/posts.js b/src/posts.js
index d8b0079a30..5fd45b4f67 100644
--- a/src/posts.js
+++ b/src/posts.js
@@ -6,6 +6,7 @@ var RDB = require('./redis.js'),
topics = require('./topics.js'),
favourites = require('./favourites.js'),
threadTools = require('./threadTools.js'),
+ postTools = require('./postTools'),
feed = require('./feed.js'),
async = require('async');
@@ -116,7 +117,9 @@ marked.setOptions({
postData.post_rep = postData.reputation;
postData['edited-class'] = postData.editor !== '' ? '' : 'none';
postData['relativeEditTime'] = postData.edited !== '0' ? utils.relativeTime(postData.edited) : '';
- postData.content = marked(postData.content || '');
+
+ postData.content = postTools.markdownToHTML(postData.content);
+
if(postData.uploadedImages) {
postData.uploadedImages = JSON.parse(postData.uploadedImages);
} else {
@@ -218,9 +221,9 @@ marked.setOptions({
Posts.create(uid, tid, content, images, function(postData) {
if (postData) {
- topics.addPostToTopic(tid, postData.pid);
+ RDB.rpush('tid:' + tid + ':posts', postData.pid);
- topics.markUnRead(tid);
+ RDB.del('tid:' + tid + ':read_by_uid');
Posts.get_cid_by_pid(postData.pid, function(cid) {
RDB.del('cid:' + cid + ':read_by_uid', function(err, data) {