add ability to set up markup for bold and italic

This commit is contained in:
Adam Misiorny 2015-11-29 21:11:54 +01:00
parent 42c4a0bbef
commit abedc7371d
2 changed files with 13 additions and 2 deletions

View file

@ -82,6 +82,9 @@ simplemde.value("This text will appear in the editor");
- image - image
- link - link
- table - 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`. - **lineWrapping**: If set to `false`, disable line wrapping. Defaults to `true`.
- **parsingConfig**: Adjust settings for parsing the Markdown during editing (not previewing). - **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`. - **allowAtxHeaderWithoutSpace**: If set to `true`, will render headers without a space after the `#`. Defaults to `false`.

View file

@ -171,7 +171,7 @@ function toggleFullScreen(editor) {
* Action for toggling bold. * Action for toggling bold.
*/ */
function toggleBold(editor) { function toggleBold(editor) {
_toggleBlock(editor, "bold", "**"); _toggleBlock(editor, "bold", editor.options.blockStyles.bold);
} }
@ -179,7 +179,7 @@ function toggleBold(editor) {
* Action for toggling italic. * Action for toggling italic.
*/ */
function toggleItalic(editor) { function toggleItalic(editor) {
_toggleBlock(editor, "italic", "*"); _toggleBlock(editor, "italic", editor.options.blockStyles.italic);
} }
@ -802,6 +802,10 @@ var insertTexts = {
horizontalRule: ["", "\n\n-----\n\n"] horizontalRule: ["", "\n\n-----\n\n"]
}; };
var blockStyles = {
"bold": "**",
"italic": "*"
};
/** /**
* Interface of SimpleMDE. * Interface of SimpleMDE.
@ -878,6 +882,10 @@ function SimpleMDE(options) {
options.insertTexts = extend({}, insertTexts, options.insertTexts || {}); 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 // Change unique_id to uniqueId for backwards compatibility
if(options.autosave.unique_id != undefined && options.autosave.unique_id != "") if(options.autosave.unique_id != undefined && options.autosave.unique_id != "")
options.autosave.uniqueId = options.autosave.unique_id; options.autosave.uniqueId = options.autosave.unique_id;