1. Load the needed Marked.js library and the Markdown WYSIWYG Editor’s files in the document.
<!-- Required --> <script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script> <!-- Markdown WYSIWYG Editor --> <link rel="stylesheet" href="/dist/editor.css"> <script src="/dist/editor.js"></script>
2. Create an empty DIV element for the editor.
<div id="myEditor"></div>
3. Create a new instance of MarkdownWYSIWYG and pass the ID of your container element.
const editor = new MarkdownWYSIWYG('myEditor', {
// options here
}); 4. Available options to customize the editor.
const editor = new MarkdownWYSIWYG('myEditor', {
initialValue: '',
showToolbar: true,
buttons: [
{ id: 'h1', label: ICON_HEADING, title: 'Heading 1', type: 'block', mdPrefix: '# ', execCommand: 'formatBlock', value: 'H1' },
{ id: 'h2', label: ICON_HEADING, title: 'Heading 2', type: 'block', mdPrefix: '## ', execCommand: 'formatBlock', value: 'H2' },
{ id: 'h3', label: ICON_HEADING, title: 'Heading 3', type: 'block', mdPrefix: '### ', execCommand: 'formatBlock', value: 'H3' },
{ id: 'bold', label: ICON_BOLD, title: 'Bold', execCommand: 'bold', type: 'inline', mdPrefix: '**', mdSuffix: '**' },
{ id: 'italic', label: ICON_ITALIC, title: 'Italic', execCommand: 'italic', type: 'inline', mdPrefix: '*', mdSuffix: '*' },
{ id: 'strikethrough', label: ICON_STRIKETHROUGH, title: 'Strikethrough', execCommand: 'strikeThrough', type: 'inline', mdPrefix: '~~', mdSuffix: '~~' },
{ id: 'link', label: ICON_LINK, title: 'Link', action: '_insertLink', type: 'inline' },
{ id: 'ul', label: ICON_UL, title: 'Unordered List', execCommand: 'insertUnorderedList', type: 'block', mdPrefix: '- ' },
{ id: 'ol', label: ICON_OL, title: 'Ordered List', execCommand: 'insertOrderedList', type: 'block', mdPrefix: '1. ' },
{ id: 'outdent', label: ICON_OUTDENT, title: 'Outdent', action: '_handleOutdent', type: 'list-format' },
{ id: 'indent', label: ICON_INDENT, title: 'Indent', action: '_handleIndent', type: 'list-format' },
{ id: 'blockquote', label: ICON_BLOCKQUOTE, title: 'Blockquote', execCommand: 'formatBlock', value: 'BLOCKQUOTE', type: 'block', mdPrefix: '> ' },
{ id: 'hr', label: ICON_HR, title: 'HR', action: '_insertHorizontalRuleAction', type: 'block-insert' },
{ id: 'image', label: ICON_IMAGE, title: 'Insert Image', action: '_insertImageAction', type: 'block-insert' },
{ id: 'table', label: ICON_TABLE, title: 'Insert Table', action: '_insertTableAction', type: 'block-insert' },
{ id: 'codeblock', label: ICON_CODEBLOCK, title: 'Code Block', action: '_insertCodeBlock', type: 'block-wrap', mdPrefix: '```n', mdSuffix: 'n```' },
{ id: 'inlinecode', label: ICON_INLINECODE, title: 'Inline Code', action: '_insertInlineCode', type: 'inline', mdPrefix: '`', mdSuffix: '`' }
],
onUpdate: null,
initialMode: 'wysiwyg',
tableGridMaxRows: 10,
tableGridMaxCols: 10,
}); 5. API methods.
getValue(): Returns the current content as a Markdown string.setValue(markdownString): Programmatically sets the editor’s content.switchToMode(mode): Switches the view to 'wysiwyg' or 'markdown'.destroy(): Removes the editor and its event listeners from the DOM.The post Dual-Mode WYSIWYG Rich Text & Markdown Editor in JavaScript appeared first on CSS Script.
Medical technology giant Stryker Corporation confirmed on March 11, 2026, that it suffered a significant…
GREELEY, Colo. (AP) — Thousands of workers for the world’s largest meatpacking company began a…
One of the state’s most unusual colleges, the aviation-heavy Daniel Webster College that lasted next…
Curled wood shavings sprinkled across Jim McLaughlin’s workspace, filling the cabin connected to the garage…
For more than 150 years, a small band of Loudon property owners who live along…
A Warner man was arrested on Saturday after crashing into a highway sign for the…
This website uses cookies.