Merge pull request #185 from adam187/feature/block-styles

add ability to set up markup for bold and italic
pull/189/head
Wes Cossick 9 years ago
commit 170cbd0b2f

@ -73,6 +73,9 @@ simplemde.value("This text will appear in the editor");
- **enabled**: If set to `true`, autosave the text. Defaults to `false`. - **enabled**: If set to `true`, autosave the text. Defaults to `false`.
- **delay**: Delay between saves, in milliseconds. Defaults to `10000` (10s). - **delay**: Delay between saves, in milliseconds. Defaults to `10000` (10s).
- **uniqueId**: You must set a unique string identifier so that SimpleMDE can autosave. Something that separates this from other instances of SimpleMDE elsewhere on your website. - **uniqueId**: You must set a unique string identifier so that SimpleMDE can autosave. Something that separates this from other instances of SimpleMDE elsewhere on your website.
- **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 `*`.
- **element**: The DOM element for the textarea to use. Defaults to the first textarea on the page. - **element**: The DOM element for the textarea to use. Defaults to the first textarea on the page.
- **hideIcons**: An array of icon names to hide. Can be used to hide specific icons without completely customizing the toolbar. - **hideIcons**: An array of icon names to hide. Can be used to hide specific icons without completely customizing the toolbar.
- **indentWithTabs**: If set to `false`, indent using spaces instead of tabs. Defaults to `true`. - **indentWithTabs**: If set to `false`, indent using spaces instead of tabs. Defaults to `true`.
@ -107,6 +110,10 @@ var simplemde = new SimpleMDE({
uniqueId: "MyUniqueID", uniqueId: "MyUniqueID",
delay: 1000, delay: 1000,
}, },
blockStyles: {
bold: "__",
italic: "_"
},
element: document.getElementById("MyID"), element: document.getElementById("MyID"),
hideIcons: ["guide", "heading"], hideIcons: ["guide", "heading"],
indentWithTabs: false, indentWithTabs: false,

@ -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 != undefined && options.autosave.unique_id != undefined && options.autosave.unique_id != "") if(options.autosave != undefined && options.autosave.unique_id != undefined && options.autosave.unique_id != "")
options.autosave.uniqueId = options.autosave.unique_id; options.autosave.uniqueId = options.autosave.unique_id;

Loading…
Cancel
Save