/*! * Includes modified code from GitHub Markdown Toolbar Element * https://github.com/github/markdown-toolbar-element/ * * Original Copyright GitHub, Inc. * Released under the MIT license * https://github.com/github/markdown-toolbar-element/blob/master/LICENSE */ import { extend } from 'flarum/extend'; import TextEditor from 'flarum/components/TextEditor'; import MarkdownArea from 'mdarea'; import MarkdownToolbar from './components/MarkdownToolbar'; import MarkdownButton from './components/MarkdownButton'; app.initializers.add('flarum-markdown', function(app) { let index = 1; extend(TextEditor.prototype, 'oninit', function() { this.textareaId = 'textarea'+(index++); }); extend(TextEditor.prototype, 'view', function(vdom) { vdom.children[0].attrs.id = this.textareaId; }); extend(TextEditor.prototype, 'oncreate', function() { this.editor = new MarkdownArea(this.$('textarea')[0], { keyMap: { indent: ['Ctrl+m'], outdent: ['Ctrl+M'], inline: [] } }); }); extend(TextEditor.prototype, 'onremove', function () { this.editor.destroy(); }); extend(TextEditor.prototype, 'toolbarItems', function(items) { const tooltip = name => app.translator.trans(`flarum-markdown.forum.composer.${name}_tooltip`); items.add('markdown', ( ', multiline: true, surroundWithNewlines: true }} /> ), 100); }); });