Skip to content

Build your personal knowledge base with Trilium Notes

feat(slash): markdown import

Elian Doran32ee75ea43bf
diff --git a/packages/ckeditor5/src/extra_slash_commands.ts b/packages/ckeditor5/src/extra_slash_commands.ts
index 0592f17e1b..0ead233aaf 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 2da1c7e4ee..a8af674a24 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();
+ }
+
+}