1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-07-28 17:02:04 +03:00

Refactored markdown editor logic

Split out the markdown editor logic into seperate components to provide
a more orgranised heirachy with feature-specific files.
This commit is contained in:
Dan Brown
2022-11-26 16:43:28 +00:00
parent 40a1377c0b
commit 63d6272282
9 changed files with 790 additions and 574 deletions

View File

@ -0,0 +1,33 @@
function getContentToInsert({html, markdown}) {
return markdown || html;
}
/**
* @param {MarkdownEditor} editor
*/
export function listen(editor) {
window.$events.listen('editor::replace', (eventContent) => {
const markdown = getContentToInsert(eventContent);
editor.actions.replaceContent(markdown);
});
window.$events.listen('editor::append', (eventContent) => {
const markdown = getContentToInsert(eventContent);
editor.actions.appendContent(markdown);
});
window.$events.listen('editor::prepend', (eventContent) => {
const markdown = getContentToInsert(eventContent);
editor.actions.prependContent(markdown);
});
window.$events.listen('editor::insert', (eventContent) => {
const markdown = getContentToInsert(eventContent);
editor.actions.insertContent(markdown);
});
window.$events.listen('editor::focus', () => {
editor.actions.focus();
});
}