1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2026-01-03 23:42:28 +03:00

MD Editor: Starting conversion to typescript

This commit is contained in:
Dan Brown
2025-07-20 12:33:22 +01:00
parent 61f8d18af5
commit 7bbf591a7f
13 changed files with 237 additions and 229 deletions

View File

@@ -0,0 +1,36 @@
import {MarkdownEditor} from "./index.mjs";
export interface HtmlOrMarkdown {
html: string;
markdown: string;
}
function getContentToInsert({html, markdown}: {html: string, markdown: string}): string {
return markdown || html;
}
export function listenToCommonEvents(editor: MarkdownEditor): void {
window.$events.listen('editor::replace', (eventContent: HtmlOrMarkdown) => {
const markdown = getContentToInsert(eventContent);
editor.actions.replaceContent(markdown);
});
window.$events.listen('editor::append', (eventContent: HtmlOrMarkdown) => {
const markdown = getContentToInsert(eventContent);
editor.actions.appendContent(markdown);
});
window.$events.listen('editor::prepend', (eventContent: HtmlOrMarkdown) => {
const markdown = getContentToInsert(eventContent);
editor.actions.prependContent(markdown);
});
window.$events.listen('editor::insert', (eventContent: HtmlOrMarkdown) => {
const markdown = getContentToInsert(eventContent);
editor.actions.insertContent(markdown);
});
window.$events.listen('editor::focus', () => {
editor.actions.focus();
});
}