mirror of
https://github.com/sudoxnym/habitica.git
synced 2026-07-13 15:38:59 +00:00
use marked instead of showdown, it's more performant and allows us to
sanitize the content
This commit is contained in:
parent
6e800ea2d9
commit
774fa4f645
7 changed files with 54 additions and 8 deletions
|
|
@ -16,8 +16,7 @@ module.exports = function(grunt) {
|
|||
'public/bower_components/bootstrap-growl/jquery.bootstrap-growl.min.js',
|
||||
'public/bower_components/angular/angular.min.js',
|
||||
'public/bower_components/angular-sanitize/angular-sanitize.min.js',
|
||||
'public/bower_components/showdown/compressed/showdown.js',
|
||||
'public/bower_components/angular-markdown-directive/markdown.js',
|
||||
'public/bower_components/marked/lib/marked.js',
|
||||
'public/bower_components/angular-route/angular-route.min.js',
|
||||
'public/bower_components/angular-resource/angular-resource.min.js',
|
||||
'public/bower_components/angular-ui/build/angular-ui.min.js',
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@
|
|||
"angular-route": "1.2.0-rc.1",
|
||||
"angular-ui-utils": "~0.0.4",
|
||||
"angular-sanitize": "1.2.0-rc.1",
|
||||
"angular-markdown-directive": "~0.1.0"
|
||||
"marked": "~0.2.9"
|
||||
},
|
||||
"resolutions": {
|
||||
"jquery": "~2.0.3",
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"use strict";
|
||||
|
||||
window.habitrpg = angular.module('habitrpg',
|
||||
['ngRoute', 'ngResource', 'ngSanitize', 'userServices', 'groupServices', 'memberServices', 'sharedServices', 'authServices', 'notificationServices', 'ui.bootstrap', 'ui.keypress', 'btford.markdown'])
|
||||
['ngRoute', 'ngResource', 'ngSanitize', 'userServices', 'groupServices', 'memberServices', 'sharedServices', 'authServices', 'notificationServices', 'ui.bootstrap', 'ui.keypress'])
|
||||
|
||||
.constant("API_URL", "")
|
||||
.constant("STORAGE_USER_ID", 'habitrpg-user')
|
||||
|
|
|
|||
|
|
@ -60,3 +60,51 @@ habitrpg.directive('habitrpgSortable', ['User', function(User) {
|
|||
});
|
||||
}
|
||||
}]);
|
||||
|
||||
/**
|
||||
* Markdown
|
||||
* See http://www.heikura.me/#!/angularjs-markdown-directive
|
||||
*/
|
||||
(function(){
|
||||
var md = function () {
|
||||
marked.setOptions({
|
||||
gfm:true,
|
||||
pedantic:false,
|
||||
sanitize:true
|
||||
// callback for code highlighter
|
||||
// Uncomment this (and htljs.tabReplace below) if we add in highlight.js (http://www.heikura.me/#!/angularjs-markdown-directive)
|
||||
// highlight:function (code, lang) {
|
||||
// if (lang != undefined)
|
||||
// return hljs.highlight(lang, code).value;
|
||||
//
|
||||
// return hljs.highlightAuto(code).value;
|
||||
// }
|
||||
});
|
||||
|
||||
var toHtml = function (markdown) {
|
||||
if (markdown == undefined)
|
||||
return '';
|
||||
|
||||
return marked(markdown);
|
||||
};
|
||||
|
||||
//hljs.tabReplace = ' ';
|
||||
|
||||
return {
|
||||
toHtml:toHtml
|
||||
};
|
||||
}();
|
||||
|
||||
habitrpg.directive('markdown', function() {
|
||||
return {
|
||||
restrict: 'E',
|
||||
link: function(scope, element, attrs) {
|
||||
scope.$watch(attrs.ngModel, function(value, oldValue) {
|
||||
var markdown = value;
|
||||
var html = md.toHtml(markdown);
|
||||
element.html(html);
|
||||
});
|
||||
}
|
||||
};
|
||||
});
|
||||
})()
|
||||
|
|
|
|||
|
|
@ -31,8 +31,7 @@ html
|
|||
script(type='text/javascript', src='/bower_components/angular/angular.min.js')
|
||||
|
||||
script(type='text/javascript', src='/bower_components/angular-sanitize/angular-sanitize.min.js')
|
||||
script(type='text/javascript', src='/bower_components/showdown/compressed/showdown.js')
|
||||
script(type='text/javascript', src='/bower_components/angular-markdown-directive/markdown.js')
|
||||
script(type='text/javascript', src='/bower_components/marked/lib/marked.js')
|
||||
|
||||
script(type='text/javascript', src='/bower_components/angular-route/angular-route.min.js')
|
||||
script(type='text/javascript', src='/bower_components/angular-resource/angular-resource.min.js')
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@
|
|||
span.muted(ng-hide='profile.profile.imageUrl') - None -
|
||||
|
||||
h4 Blurb
|
||||
p(ng-show='profile.profile.blurb', btf-markdown='profile.profile.blurb')
|
||||
markdown(ng-show='profile.profile.blurb', ng-model='profile.profile.blurb')
|
||||
span.muted(ng-hide='profile.profile.blurb') - None -
|
||||
//{{profile.profile.blurb | linky:'_blank'}}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ div(ng-controller='MemberModalCtrl')
|
|||
.row-fluid
|
||||
.span6
|
||||
img(ng-show='profile.profile.imageUrl', ng-src='{{profile.profile.imageUrl}}')
|
||||
p(ng-show='profile.profile.blurb', btf-markdown='profile.profile.blurb')
|
||||
markdown(ng-show='profile.profile.blurb', ng-model='profile.profile.blurb')
|
||||
ul(ng-show='profile.profile.websites')
|
||||
li(ng-repeat='website in profile.profile.websites')
|
||||
a(href='{{website}}', target='_blank') {{website}}
|
||||
|
|
|
|||
Loading…
Reference in a new issue