Merge a23fd3b40afc6a2fd607b7a67aecae8411a89a39 into 6abda7ab68cc20f4aca870eb243747951b90ab04

This commit is contained in:
wisetwo 2016-09-22 04:05:29 +00:00 committed by GitHub
commit 12607ff4a4
3 changed files with 31 additions and 6 deletions

View File

@ -328,4 +328,4 @@ simplemde.clearAutosavedValue(); // no returned value
## How it works
SimpleMDE began as an improvement of [lepture's Editor project](https://github.com/lepture/editor), but has now taken on an identity of its own. It is bundled with [CodeMirror](https://github.com/codemirror/codemirror) and depends on [Font Awesome](http://fontawesome.io).
CodeMirror is the backbone of the project and parses much of the Markdown syntax as it's being written. This allows us to add styles to the Markdown that's being written. Additionally, a toolbar and status bar have been added to the top and bottom, respectively. Previews are rendered by [Marked](https://github.com/chjj/marked) using GFM.
CodeMirror is the backbone of the project and parses much of the Markdown syntax as it's being written. This allows us to add styles to the Markdown that's being written. Additionally, a toolbar and status bar have been added to the top and bottom, respectively. Previews are rendered by [Remarkable](https://github.com/jonschlinkert/remarkable) using GFM, but with HTML disabled to prevent xss content, which is different from [marked](https://github.com/chjj/marked).

View File

@ -23,7 +23,8 @@
"dependencies": {
"codemirror": "*",
"codemirror-spell-checker": "*",
"marked": "*"
"marked": "*",
"remarkable": "^1.6.2"
},
"devDependencies": {
"browserify": "*",

View File

@ -11,7 +11,8 @@ require("codemirror/addon/selection/mark-selection.js");
require("codemirror/mode/gfm/gfm.js");
require("codemirror/mode/xml/xml.js");
var CodeMirrorSpellChecker = require("codemirror-spell-checker");
var marked = require("marked");
//var marked = require("marked");
var Remarkable = require("remarkable");
// Some variables
@ -1390,7 +1391,7 @@ function SimpleMDE(options) {
* Default markdown render.
*/
SimpleMDE.prototype.markdown = function(text) {
if(marked) {
/*if(marked) {
// Initialize
var markedOptions = {};
@ -1415,7 +1416,30 @@ SimpleMDE.prototype.markdown = function(text) {
// Return
return marked(text);
}
}*/
if(Remarkable) {
var md = new Remarkable({
html: false,
xhtmlOut: true,
breaks: false,
highlight: function(str, lang) {
if(typeof window.hljs != undefined && lang && window.hljs.getLanguage(lang)) {
try {
return window.hljs.highlight(lang, str).value;
} catch(err) {
//continue
}
}
try {
return window.hljs.highlightAuto(str).value;
} catch(err) {
//continue
}
return;
}
});
return md.render(text);
}
};
/**
@ -2025,4 +2049,4 @@ SimpleMDE.prototype.toTextArea = function() {
}
};
module.exports = SimpleMDE;
module.exports = SimpleMDE;