refactor: Swap out remarkable for habitica flavored markdown-it

This commit is contained in:
Blade Barringer
2016-04-22 17:27:27 -05:00
parent 2cdb30bd5b
commit ad57dedecb
6 changed files with 8 additions and 66 deletions

View File

@@ -37,11 +37,11 @@
"jquery-ui": "1.10.3", "jquery-ui": "1.10.3",
"jquery.cookie": "1.4.0", "jquery.cookie": "1.4.0",
"js-emoji": "snicker/js-emoji#f25d8a303f", "js-emoji": "snicker/js-emoji#f25d8a303f",
"remarkable": "^1.6.2",
"ngInfiniteScroll": "1.0.0", "ngInfiniteScroll": "1.0.0",
"pnotify": "1.3.1", "pnotify": "1.3.1",
"sticky": "*", "sticky": "*",
"swagger-ui": "wordnik/swagger-ui#v2.0.24" "swagger-ui": "wordnik/swagger-ui#v2.0.24",
"habitica-markdown": "^1.0.0"
}, },
"devDependencies": { "devDependencies": {
"angular-mocks": "1.3.9" "angular-mocks": "1.3.9"

View File

@@ -6,11 +6,7 @@
*/ */
(function(){ (function(){
var md = function () { var md = function () {
var remarkable = new Remarkable({ var mdown = window.habiticaMarkdown;
// TODO: Add in code highlighting?
// highlight: function (#<{(|str, lang|)}>#) { return ''; }
linkify: true
});
emoji.img_path = 'common/img/emoji/unicode/'; emoji.img_path = 'common/img/emoji/unicode/';
@@ -18,63 +14,13 @@
if (markdown == undefined) if (markdown == undefined)
return ''; return '';
markdown = remarkable.render(markdown); markdown = mdown.render(markdown);
markdown = emoji.replace_colons(markdown); markdown = emoji.replace_colons(markdown);
markdown = emoji.replace_unified(markdown); markdown = emoji.replace_unified(markdown);
return markdown; return markdown;
}; };
// This was applie to marked, the old markdown library which has an xss exploit.
// If we want this behavior again, we'll need to rewrite it.
// ---
// [nickgordon20131123] this hacky override wraps images with a link to the image in a new window, and also adds some classes in case we want to style
// marked.InlineLexer.prototype.outputLink = function(cap, link) {
// var escape = function(html, encode) {
// return html
// .replace(!encode ? /&(?!#?\w+;)/g : /&/g, '&amp;')
// .replace(/</g, '&lt;')
// .replace(/>/g, '&gt;')
// .replace(/"/g, '&quot;')
// .replace(/'/g, '&#39;');
// };
// if (cap[0].charAt(0) !== '!') {
// return '<a class="markdown-link" target="_blank" href="'
// + escape(link.href)
// + '"'
// + (link.title
// ? ' title="'
// + escape(link.title)
// + '"'
// : '')
// + '>'
// + this.output(cap[1])
// + '</a>';
// } else {
// return '<a class="markdown-img-link" target="_blank" href="'
// + escape(link.href)
// + '"'
// + (link.title
// ? ' title="'
// + escape(link.title)
// + '"'
// : '')
// + '><img class="markdown-img" src="'
// + escape(link.href)
// + '" alt="'
// + escape(cap[1])
// + '"'
// + (link.title
// ? ' title="'
// + escape(link.title)
// + '"'
// : '')
// + '></a>';
// }
// }
//hljs.tabReplace = ' ';
return { return {
toHtml:toHtml toHtml:toHtml
}; };
@@ -99,7 +45,6 @@
html = html.replace(userHighlight, "<u>@"+userName+"</u>"); html = html.replace(userHighlight, "<u>@"+userName+"</u>");
html = html.replace(' href',' target="'+linktarget+'" href');
element.html(html); element.html(html);
if(MOBILE_APP) { if(MOBILE_APP) {
@@ -140,8 +85,6 @@
return function(input){ return function(input){
var html = md.toHtml(input); var html = md.toHtml(input);
html = html.replace(' href',' target="_blank" href');
return html; return html;
}; };
}); });

View File

@@ -31,7 +31,7 @@ module.exports = function karmaConfig (config) {
'website/public/bower_components/ngInfiniteScroll/build/ng-infinite-scroll.js', 'website/public/bower_components/ngInfiniteScroll/build/ng-infinite-scroll.js',
'website/public/bower_components/select2/select2.js', 'website/public/bower_components/select2/select2.js',
'website/public/bower_components/angular-ui-select2/src/select2.js', 'website/public/bower_components/angular-ui-select2/src/select2.js',
'website/public/bower_components/remarkable/dist/remarkable.min.js', 'website/public/bower_components/habitica-markdown/dist/habitica-markdown.min.js',
'website/public/bower_components/js-emoji/emoji.js', 'website/public/bower_components/js-emoji/emoji.js',
'common/dist/scripts/habitrpg-shared.js', 'common/dist/scripts/habitrpg-shared.js',

View File

@@ -52,6 +52,7 @@
"js2xmlparser": "~1.0.0", "js2xmlparser": "~1.0.0",
"lodash": "^3.10.1", "lodash": "^3.10.1",
"loggly": "~1.0.8", "loggly": "~1.0.8",
"markdown-it": "^6.0.1",
"merge-stream": "^1.0.0", "merge-stream": "^1.0.0",
"method-override": "^2.3.5", "method-override": "^2.3.5",
"moment": "~2.10.6", "moment": "~2.10.6",
@@ -71,7 +72,6 @@
"ps-tree": "^1.0.0", "ps-tree": "^1.0.0",
"push-notify": "^1.1.1", "push-notify": "^1.1.1",
"q": "^1.4.1", "q": "^1.4.1",
"remarkable": "^1.6.2",
"request": "~2.44.0", "request": "~2.44.0",
"s3-upload-stream": "^1.0.6", "s3-upload-stream": "^1.0.6",
"serve-favicon": "^2.3.0", "serve-favicon": "^2.3.0",

View File

@@ -8,7 +8,7 @@
"bower_components/bootstrap-tour/build/js/bootstrap-tour.js", "bower_components/bootstrap-tour/build/js/bootstrap-tour.js",
"bower_components/angular/angular.js", "bower_components/angular/angular.js",
"bower_components/angular-sanitize/angular-sanitize.js", "bower_components/angular-sanitize/angular-sanitize.js",
"bower_components/remarkable/dist/remarkable.min.js", "bower_components/habitica-markdown/dist/habitica-markdown.min.js",
"bower_components/angular-ui-router/release/angular-ui-router.js", "bower_components/angular-ui-router/release/angular-ui-router.js",
"bower_components/angular-resource/angular-resource.min.js", "bower_components/angular-resource/angular-resource.min.js",
"bower_components/angular-ui-utils/ui-utils.min.js", "bower_components/angular-ui-utils/ui-utils.min.js",

View File

@@ -4,8 +4,7 @@ var router = express.Router();
var _ = require('lodash'); var _ = require('lodash');
var locals = require('../middlewares/locals'); var locals = require('../middlewares/locals');
var i18n = require('../libs/i18n'); var i18n = require('../libs/i18n');
var Remarkable = require('remarkable'); var md = require('markdown-it')({
var md = new Remarkable({
html: true, html: true,
}); });