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

v1.18.x
Julian Lam 12 years ago
parent 104dbea3f2
commit f40bf46656

@ -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"

@ -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));

@ -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) {

Loading…
Cancel
Save