Skip to content

Commit 443a58c

Browse files
author
Wes Cossick
committed
New option: renderingConfig which includes syntax highlighting
1 parent a52a9a0 commit 443a58c

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ simplemde.value("This text will appear in the editor");
7575
- **strikethrough**: If set to `false`, will not process GFM strikethrough syntax. Defaults to `true`.
7676
- **underscoresBreakWords**: If set to `true`, let underscores be a delimiter for separating words. Defaults to `false`.
7777
- **previewRender**: Custom function for parsing the plaintext Markdown and returning HTML. Used when user previews.
78-
- **singleLineBreaks**: If set to `false`, disable parsing GFM single line breaks. Defaults to `true`.
78+
- **renderingConfig**: Adjust settings for parsing the Markdown during previewing (not editing).
79+
- **singleLineBreaks**: If set to `false`, disable parsing GFM single line breaks. Defaults to `true`.
80+
- **codeSyntaxHighlighting**: If set to `true`, will highlight using [highlight.js](https://github.com/isagalaev/highlight.js). Defaults to `false`. To use this feature you must include highlight.js on your page. For example, include the script and the CSS files like: `<script src="https://cdn.jsdelivr.net/highlight.js/latest/highlight.min.js"></script>` and `<link rel="stylesheet" href="https://cdn.jsdelivr.net/highlight.js/latest/styles/github.min.css">`
7981
- **spellChecker**: If set to `false`, disable the spell checker. Defaults to `true`.
8082
- **status**: If set to `false`, hide the status bar. Defaults to `true`.
8183
- Optionally, you can set an array of status bar elements to include, and in what order.
@@ -111,7 +113,10 @@ var simplemde = new SimpleMDE({
111113

112114
return "Loading...";
113115
}
114-
singleLineBreaks: false,
116+
renderingConfig: {
117+
singleLineBreaks: false,
118+
codeSyntaxHighlighting: true,
119+
},
115120
spellChecker: false,
116121
status: false,
117122
status: ['autosave', 'lines', 'words', 'cursor'], // Optional usage

src/js/simplemde.js

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -827,13 +827,27 @@ SimpleMDE.toolbar = toolbar;
827827
*/
828828
SimpleMDE.prototype.markdown = function(text) {
829829
if(window.marked) {
830+
// Initialize
831+
var markedOptions = {};
832+
833+
830834
// Update options
831-
if(this.options && this.options.singleLineBreaks !== false) {
832-
marked.setOptions({
833-
breaks: true
834-
});
835+
if(this.options && this.options.renderingConfig && this.options.renderingConfig.singleLineBreaks !== false) {
836+
markedOptions.breaks = true;
835837
}
836-
838+
839+
if(this.options && this.options.renderingConfig && this.options.renderingConfig.codeSyntaxHighlighting === true && window.hljs) {
840+
markedOptions.highlight = function(code) {
841+
return hljs.highlightAuto(code).value;
842+
}
843+
}
844+
845+
846+
// Set options
847+
marked.setOptions(markedOptions);
848+
849+
850+
// Return
837851
return marked(text);
838852
}
839853
};

0 commit comments

Comments
 (0)