2017-02-09 11:45:42 +00:00
|
|
|
import fm from '../app';
|
|
|
|
import $ from 'jquery';
|
|
|
|
import marked from 'marked';
|
2014-12-26 03:05:07 +00:00
|
|
|
|
2017-02-09 11:45:42 +00:00
|
|
|
fm.app.factory("fmMarked", function() {
|
|
|
|
marked.setOptions({
|
|
|
|
breaks: true,
|
|
|
|
sanitize: true
|
2014-12-26 03:05:07 +00:00
|
|
|
});
|
|
|
|
|
2017-02-09 11:45:42 +00:00
|
|
|
return {
|
|
|
|
block: function(string, options) {
|
|
|
|
var ret = $("<div/>").html(marked(string, options));
|
|
|
|
$("a[href]", ret).attr("target", "_blank");
|
|
|
|
return ret.html();
|
|
|
|
},
|
|
|
|
inline: function(string, options) {
|
|
|
|
var ret = $("<div/>").html(marked(string, options));
|
|
|
|
$("p", ret).replaceWith(function() { return $(this).contents(); });
|
|
|
|
$("a[href]", ret).attr("target", "_blank");
|
|
|
|
return ret.html();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|