2022-11-27 00:43:28 +08:00
|
|
|
function getContentToInsert({html, markdown}) {
|
|
|
|
return markdown || html;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {MarkdownEditor} editor
|
|
|
|
*/
|
|
|
|
export function listen(editor) {
|
2023-04-19 05:20:02 +08:00
|
|
|
window.$events.listen('editor::replace', eventContent => {
|
2022-11-27 00:43:28 +08:00
|
|
|
const markdown = getContentToInsert(eventContent);
|
|
|
|
editor.actions.replaceContent(markdown);
|
|
|
|
});
|
|
|
|
|
2023-04-19 05:20:02 +08:00
|
|
|
window.$events.listen('editor::append', eventContent => {
|
2022-11-27 00:43:28 +08:00
|
|
|
const markdown = getContentToInsert(eventContent);
|
|
|
|
editor.actions.appendContent(markdown);
|
|
|
|
});
|
|
|
|
|
2023-04-19 05:20:02 +08:00
|
|
|
window.$events.listen('editor::prepend', eventContent => {
|
2022-11-27 00:43:28 +08:00
|
|
|
const markdown = getContentToInsert(eventContent);
|
|
|
|
editor.actions.prependContent(markdown);
|
|
|
|
});
|
|
|
|
|
2023-04-19 05:20:02 +08:00
|
|
|
window.$events.listen('editor::insert', eventContent => {
|
2022-11-27 00:43:28 +08:00
|
|
|
const markdown = getContentToInsert(eventContent);
|
|
|
|
editor.actions.insertContent(markdown);
|
|
|
|
});
|
|
|
|
|
|
|
|
window.$events.listen('editor::focus', () => {
|
|
|
|
editor.actions.focus();
|
|
|
|
});
|
2023-04-19 05:20:02 +08:00
|
|
|
}
|