mirror of
https://github.com/BookStackApp/BookStack.git
synced 2026-07-24 21:33:26 +03:00
- Removed unused import - Added some trailing newlines to code files - Prevented <hr>s confusing logic in MD editor - Aligned logic to select end of header across editors
41 lines
1.3 KiB
TypeScript
41 lines
1.3 KiB
TypeScript
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();
|
|
});
|
|
|
|
window.$events.listen<{id: string, index: number}>('editor::focus-heading', ({index}) => {
|
|
editor.actions.focusOnHeader(index);
|
|
});
|
|
}
|