From abedc7371d995de9c8ccbe571e5ee63d128fa3b3 Mon Sep 17 00:00:00 2001 From: Adam Misiorny Date: Sun, 29 Nov 2015 21:11:54 +0100 Subject: [PATCH] add ability to set up markup for bold and italic --- README.md | 3 +++ src/js/simplemde.js | 12 ++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b432157..1ff0306 100644 --- a/README.md +++ b/README.md @@ -82,6 +82,9 @@ simplemde.value("This text will appear in the editor"); - image - link - table +- **blockStyles**: Customize how certain buttons that style blocks of text behave. + - **bold** Can be set to `**` or `__`. Defaults to `**` + - **italic** Can be set to `*` or `_`. Defaults to `*` - **lineWrapping**: If set to `false`, disable line wrapping. Defaults to `true`. - **parsingConfig**: Adjust settings for parsing the Markdown during editing (not previewing). - **allowAtxHeaderWithoutSpace**: If set to `true`, will render headers without a space after the `#`. Defaults to `false`. diff --git a/src/js/simplemde.js b/src/js/simplemde.js index 555af9d..d48ecda 100644 --- a/src/js/simplemde.js +++ b/src/js/simplemde.js @@ -171,7 +171,7 @@ function toggleFullScreen(editor) { * Action for toggling bold. */ function toggleBold(editor) { - _toggleBlock(editor, "bold", "**"); + _toggleBlock(editor, "bold", editor.options.blockStyles.bold); } @@ -179,7 +179,7 @@ function toggleBold(editor) { * Action for toggling italic. */ function toggleItalic(editor) { - _toggleBlock(editor, "italic", "*"); + _toggleBlock(editor, "italic", editor.options.blockStyles.italic); } @@ -802,6 +802,10 @@ var insertTexts = { horizontalRule: ["", "\n\n-----\n\n"] }; +var blockStyles = { + "bold": "**", + "italic": "*" +}; /** * Interface of SimpleMDE. @@ -878,6 +882,10 @@ function SimpleMDE(options) { options.insertTexts = extend({}, insertTexts, options.insertTexts || {}); + // Merging the blockStyles, with the given options + options.blockStyles = extend({}, blockStyles, options.blockStyles || {}); + + // Change unique_id to uniqueId for backwards compatibility if(options.autosave.unique_id != undefined && options.autosave.unique_id != "") options.autosave.uniqueId = options.autosave.unique_id;