1 import {MarkdownEditor} from "./index.mjs";
3 export interface HtmlOrMarkdown {
8 function getContentToInsert({html, markdown}: {html: string, markdown: string}): string {
9 return markdown || html;
12 export function listenToCommonEvents(editor: MarkdownEditor): void {
13 window.$events.listen('editor::replace', (eventContent: HtmlOrMarkdown) => {
14 const markdown = getContentToInsert(eventContent);
15 editor.actions.replaceContent(markdown);
18 window.$events.listen('editor::append', (eventContent: HtmlOrMarkdown) => {
19 const markdown = getContentToInsert(eventContent);
20 editor.actions.appendContent(markdown);
23 window.$events.listen('editor::prepend', (eventContent: HtmlOrMarkdown) => {
24 const markdown = getContentToInsert(eventContent);
25 editor.actions.prependContent(markdown);
28 window.$events.listen('editor::insert', (eventContent: HtmlOrMarkdown) => {
29 const markdown = getContentToInsert(eventContent);
30 editor.actions.insertContent(markdown);
33 window.$events.listen('editor::focus', () => {
34 editor.actions.focus();