mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-27 10:02:59 +08:00
feat(slash): markdown import
This commit is contained in:
parent
06ebe0a9b3
commit
32ee75ea43
@ -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 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 INTERNAL_LINK_COMMAND } from './plugins/internallink.js';
|
||||||
import { COMMAND_NAME as INCLUDE_NOTE_COMMAND } from './plugins/includenote.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 { ADMONITION_TYPES, type AdmonitionType } from '@triliumnext/ckeditor5-admonition';
|
||||||
import dateTimeIcon from './icons/date-time.svg?raw';
|
import dateTimeIcon from './icons/date-time.svg?raw';
|
||||||
import internalLinkIcon from './icons/trilium.svg?raw';
|
import internalLinkIcon from './icons/trilium.svg?raw';
|
||||||
import noteIcon from './icons/note.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';
|
import { icons as mathIcons, MathUI } from '@triliumnext/ckeditor5-math';
|
||||||
|
|
||||||
type SlashCommandDefinition = SlashCommandEditorConfig["extraCommands"][number];
|
type SlashCommandDefinition = SlashCommandEditorConfig["extraCommands"][number];
|
||||||
@ -58,6 +60,13 @@ export default function buildExtraCommands(): SlashCommandDefinition[] {
|
|||||||
description: "Insert a page break (for printing)",
|
description: "Insert a page break (for printing)",
|
||||||
icon: IconPageBreak,
|
icon: IconPageBreak,
|
||||||
commandName: "pageBreak"
|
commandName: "pageBreak"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "markdown-import",
|
||||||
|
title: "Markdown import",
|
||||||
|
description: "Import a markdown file into this note",
|
||||||
|
icon: importMarkdownIcon,
|
||||||
|
commandName: MARKDOWN_IMPORT_COMMAND
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,14 @@
|
|||||||
import { ButtonView, Plugin } from 'ckeditor5';
|
import { ButtonView, Command, Plugin } from 'ckeditor5';
|
||||||
import markdownIcon from '../icons/markdown-mark.svg?raw';
|
import markdownIcon from '../icons/markdown-mark.svg?raw';
|
||||||
|
|
||||||
|
export const COMMAND_NAME = 'importMarkdownInline';
|
||||||
|
|
||||||
export default class MarkdownImportPlugin extends Plugin {
|
export default class MarkdownImportPlugin extends Plugin {
|
||||||
init() {
|
init() {
|
||||||
const editor = this.editor;
|
const editor = this.editor;
|
||||||
|
|
||||||
|
editor.commands.add(COMMAND_NAME, new ImportMarkdownInline(editor));
|
||||||
|
|
||||||
editor.ui.componentFactory.add( 'markdownImport', locale => {
|
editor.ui.componentFactory.add( 'markdownImport', locale => {
|
||||||
const view = new ButtonView( locale );
|
const view = new ButtonView( locale );
|
||||||
|
|
||||||
@ -15,11 +19,19 @@ export default class MarkdownImportPlugin extends Plugin {
|
|||||||
} );
|
} );
|
||||||
|
|
||||||
// Callback executed once the image is clicked.
|
// Callback executed once the image is clicked.
|
||||||
view.on( 'execute', () => {
|
const command = editor.commands.get(COMMAND_NAME)!;
|
||||||
glob.importMarkdownInline();
|
view.bind('isEnabled').to(command, 'isEnabled');
|
||||||
} );
|
view.on('execute', () => editor.execute(COMMAND_NAME));
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class ImportMarkdownInline extends Command {
|
||||||
|
|
||||||
|
execute() {
|
||||||
|
glob.importMarkdownInline();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user