use marked instead of showdown, it's more performant and allows us to

sanitize the content
This commit is contained in:
Tyler Renelle 2013-09-09 14:06:36 -04:00
parent 6e800ea2d9
commit 774fa4f645
7 changed files with 54 additions and 8 deletions

View file

@ -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',

View file

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

View file

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

View file

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

View file

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

View file

@ -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'}}

View file

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