From ad57dedecb0064fe4fe08a2b1b0bad140cbec1c1 Mon Sep 17 00:00:00 2001 From: Blade Barringer Date: Fri, 22 Apr 2016 17:27:27 -0500 Subject: [PATCH] refactor: Swap out remarkable for habitica flavored markdown-it --- bower.json | 4 +- common/script/public/directives.js | 61 +----------------------------- karma.conf.js | 2 +- package.json | 2 +- website/public/manifest.json | 2 +- website/src/routes/pages.js | 3 +- 6 files changed, 8 insertions(+), 66 deletions(-) diff --git a/bower.json b/bower.json index 1ace990cfe..df38ce9f63 100644 --- a/bower.json +++ b/bower.json @@ -37,11 +37,11 @@ "jquery-ui": "1.10.3", "jquery.cookie": "1.4.0", "js-emoji": "snicker/js-emoji#f25d8a303f", - "remarkable": "^1.6.2", "ngInfiniteScroll": "1.0.0", "pnotify": "1.3.1", "sticky": "*", - "swagger-ui": "wordnik/swagger-ui#v2.0.24" + "swagger-ui": "wordnik/swagger-ui#v2.0.24", + "habitica-markdown": "^1.0.0" }, "devDependencies": { "angular-mocks": "1.3.9" diff --git a/common/script/public/directives.js b/common/script/public/directives.js index 93459812ea..507dcd6925 100644 --- a/common/script/public/directives.js +++ b/common/script/public/directives.js @@ -6,11 +6,7 @@ */ (function(){ var md = function () { - var remarkable = new Remarkable({ - // TODO: Add in code highlighting? - // highlight: function (#<{(|str, lang|)}>#) { return ''; } - linkify: true - }); + var mdown = window.habiticaMarkdown; emoji.img_path = 'common/img/emoji/unicode/'; @@ -18,63 +14,13 @@ if (markdown == undefined) return ''; - markdown = remarkable.render(markdown); + markdown = mdown.render(markdown); markdown = emoji.replace_colons(markdown); markdown = emoji.replace_unified(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, '&') - // .replace(//g, '>') - // .replace(/"/g, '"') - // .replace(/'/g, '''); - // }; - // if (cap[0].charAt(0) !== '!') { - // return '' - // + this.output(cap[1]) - // + ''; - // } else { - // return ''
-    //       + escape(cap[1])
-    //       + ''; - // } - // } - - //hljs.tabReplace = ' '; - return { toHtml:toHtml }; @@ -99,7 +45,6 @@ html = html.replace(userHighlight, "@"+userName+""); - html = html.replace(' href',' target="'+linktarget+'" href'); element.html(html); if(MOBILE_APP) { @@ -140,8 +85,6 @@ return function(input){ var html = md.toHtml(input); - html = html.replace(' href',' target="_blank" href'); - return html; }; }); diff --git a/karma.conf.js b/karma.conf.js index 5da4cd8dfe..bab5e0c186 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -31,7 +31,7 @@ module.exports = function karmaConfig (config) { 'website/public/bower_components/ngInfiniteScroll/build/ng-infinite-scroll.js', 'website/public/bower_components/select2/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', 'common/dist/scripts/habitrpg-shared.js', diff --git a/package.json b/package.json index d78171c529..dd9f2ba866 100644 --- a/package.json +++ b/package.json @@ -52,6 +52,7 @@ "js2xmlparser": "~1.0.0", "lodash": "^3.10.1", "loggly": "~1.0.8", + "markdown-it": "^6.0.1", "merge-stream": "^1.0.0", "method-override": "^2.3.5", "moment": "~2.10.6", @@ -71,7 +72,6 @@ "ps-tree": "^1.0.0", "push-notify": "^1.1.1", "q": "^1.4.1", - "remarkable": "^1.6.2", "request": "~2.44.0", "s3-upload-stream": "^1.0.6", "serve-favicon": "^2.3.0", diff --git a/website/public/manifest.json b/website/public/manifest.json index cb1f29071e..68dccb3944 100644 --- a/website/public/manifest.json +++ b/website/public/manifest.json @@ -8,7 +8,7 @@ "bower_components/bootstrap-tour/build/js/bootstrap-tour.js", "bower_components/angular/angular.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-resource/angular-resource.min.js", "bower_components/angular-ui-utils/ui-utils.min.js", diff --git a/website/src/routes/pages.js b/website/src/routes/pages.js index e11e836e53..21bece6cfd 100644 --- a/website/src/routes/pages.js +++ b/website/src/routes/pages.js @@ -4,8 +4,7 @@ var router = express.Router(); var _ = require('lodash'); var locals = require('../middlewares/locals'); var i18n = require('../libs/i18n'); -var Remarkable = require('remarkable'); -var md = new Remarkable({ +var md = require('markdown-it')({ html: true, });