From 32ee75ea43bf24e1e51089db7d0721cd73f373ec Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Mon, 16 Jun 2025 21:14:46 +0300 Subject: [PATCH] feat(slash): markdown import --- .../ckeditor5/src/extra_slash_commands.ts | 9 +++++++++ .../ckeditor5/src/plugins/markdownimport.ts | 20 +++++++++++++++---- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/packages/ckeditor5/src/extra_slash_commands.ts b/packages/ckeditor5/src/extra_slash_commands.ts index 0592f17e1..0ead233aa 100644 --- a/packages/ckeditor5/src/extra_slash_commands.ts +++ b/packages/ckeditor5/src/extra_slash_commands.ts @@ -6,10 +6,12 @@ import IconPageBreak from "@ckeditor/ckeditor5-icons/theme/icons/page-break.svg? import { COMMAND_NAME as INSERT_DATE_TIME_COMMAND } from './plugins/insert_date_time.js'; import { COMMAND_NAME as INTERNAL_LINK_COMMAND } from './plugins/internallink.js'; import { COMMAND_NAME as INCLUDE_NOTE_COMMAND } from './plugins/includenote.js'; +import { COMMAND_NAME as MARKDOWN_IMPORT_COMMAND } from './plugins/markdownimport.js'; import { ADMONITION_TYPES, type AdmonitionType } from '@triliumnext/ckeditor5-admonition'; import dateTimeIcon from './icons/date-time.svg?raw'; import internalLinkIcon from './icons/trilium.svg?raw'; import noteIcon from './icons/note.svg?raw'; +import importMarkdownIcon from './icons/markdown-mark.svg?raw'; import { icons as mathIcons, MathUI } from '@triliumnext/ckeditor5-math'; type SlashCommandDefinition = SlashCommandEditorConfig["extraCommands"][number]; @@ -58,6 +60,13 @@ export default function buildExtraCommands(): SlashCommandDefinition[] { description: "Insert a page break (for printing)", icon: IconPageBreak, commandName: "pageBreak" + }, + { + id: "markdown-import", + title: "Markdown import", + description: "Import a markdown file into this note", + icon: importMarkdownIcon, + commandName: MARKDOWN_IMPORT_COMMAND } ]; } diff --git a/packages/ckeditor5/src/plugins/markdownimport.ts b/packages/ckeditor5/src/plugins/markdownimport.ts index 2da1c7e4e..a8af674a2 100644 --- a/packages/ckeditor5/src/plugins/markdownimport.ts +++ b/packages/ckeditor5/src/plugins/markdownimport.ts @@ -1,10 +1,14 @@ -import { ButtonView, Plugin } from 'ckeditor5'; +import { ButtonView, Command, Plugin } from 'ckeditor5'; import markdownIcon from '../icons/markdown-mark.svg?raw'; +export const COMMAND_NAME = 'importMarkdownInline'; + export default class MarkdownImportPlugin extends Plugin { init() { const editor = this.editor; + editor.commands.add(COMMAND_NAME, new ImportMarkdownInline(editor)); + editor.ui.componentFactory.add( 'markdownImport', locale => { const view = new ButtonView( locale ); @@ -15,11 +19,19 @@ export default class MarkdownImportPlugin extends Plugin { } ); // Callback executed once the image is clicked. - view.on( 'execute', () => { - glob.importMarkdownInline(); - } ); + const command = editor.commands.get(COMMAND_NAME)!; + view.bind('isEnabled').to(command, 'isEnabled'); + view.on('execute', () => editor.execute(COMMAND_NAME)); return view; } ); } } + +class ImportMarkdownInline extends Command { + + execute() { + glob.importMarkdownInline(); + } + +}