From 443a58cc2811b571b9256db8bcd473ff1dd106ee Mon Sep 17 00:00:00 2001 From: Wes Cossick Date: Fri, 25 Sep 2015 16:47:24 -0500 Subject: [PATCH] New option: renderingConfig which includes syntax highlighting --- README.md | 9 +++++++-- src/js/simplemde.js | 24 +++++++++++++++++++----- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index effeaf9..ec5e4d5 100644 --- a/README.md +++ b/README.md @@ -75,7 +75,9 @@ simplemde.value("This text will appear in the editor"); - **strikethrough**: If set to `false`, will not process GFM strikethrough syntax. Defaults to `true`. - **underscoresBreakWords**: If set to `true`, let underscores be a delimiter for separating words. Defaults to `false`. - **previewRender**: Custom function for parsing the plaintext Markdown and returning HTML. Used when user previews. -- **singleLineBreaks**: If set to `false`, disable parsing GFM single line breaks. Defaults to `true`. +- **renderingConfig**: Adjust settings for parsing the Markdown during previewing (not editing). + - **singleLineBreaks**: If set to `false`, disable parsing GFM single line breaks. Defaults to `true`. + - **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: `` and `` - **spellChecker**: If set to `false`, disable the spell checker. Defaults to `true`. - **status**: If set to `false`, hide the status bar. Defaults to `true`. - Optionally, you can set an array of status bar elements to include, and in what order. @@ -111,7 +113,10 @@ var simplemde = new SimpleMDE({ return "Loading..."; } - singleLineBreaks: false, + renderingConfig: { + singleLineBreaks: false, + codeSyntaxHighlighting: true, + }, spellChecker: false, status: false, status: ['autosave', 'lines', 'words', 'cursor'], // Optional usage diff --git a/src/js/simplemde.js b/src/js/simplemde.js index 28e5849..8057f32 100644 --- a/src/js/simplemde.js +++ b/src/js/simplemde.js @@ -827,13 +827,27 @@ SimpleMDE.toolbar = toolbar; */ SimpleMDE.prototype.markdown = function(text) { if(window.marked) { + // Initialize + var markedOptions = {}; + + // Update options - if(this.options && this.options.singleLineBreaks !== false) { - marked.setOptions({ - breaks: true - }); + if(this.options && this.options.renderingConfig && this.options.renderingConfig.singleLineBreaks !== false) { + markedOptions.breaks = true; } - + + if(this.options && this.options.renderingConfig && this.options.renderingConfig.codeSyntaxHighlighting === true && window.hljs) { + markedOptions.highlight = function(code) { + return hljs.highlightAuto(code).value; + } + } + + + // Set options + marked.setOptions(markedOptions); + + + // Return return marked(text); } };