feat(slash): markdown import

This commit is contained in:
Elian Doran 2025-06-16 21:14:46 +03:00
parent 06ebe0a9b3
commit 32ee75ea43
No known key found for this signature in database
2 changed files with 25 additions and 4 deletions

View File

@ -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
}
];
}

View File

@ -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();
}
}