Skip to content

Build your personal knowledge base with Trilium Notes

feat(slash): admonition types

Elian Doran3a0b61680049
diff --git a/apps/client/src/widgets/type_widgets/ckeditor/config.ts b/apps/client/src/widgets/type_widgets/ckeditor/config.ts
index a1fa4c3827..39b3261b35 100644
--- a/apps/client/src/widgets/type_widgets/ckeditor/config.ts
+++ b/apps/client/src/widgets/type_widgets/ckeditor/config.ts
@@ -1,6 +1,6 @@
import { ALLOWED_PROTOCOLS } from "../../../services/link.js";
import { MIME_TYPE_AUTO } from "@triliumnext/commons";
-import type { EditorConfig } from "@triliumnext/ckeditor5";
+import { buildExtraCommands, type EditorConfig } from "@triliumnext/ckeditor5";
import { getHighlightJsNameForMime } from "../../../services/mime_types.js";
import options from "../../../services/options.js";
import { ensureMimeTypesForHighlighting, isSyntaxHighlightEnabled } from "../../../services/syntax_highlight.js";
@@ -121,6 +121,11 @@ export function buildConfig(): EditorConfig {
clipboard: {
copy: copyTextWithToast
},
+ slashCommand: {
+ removeCommands: [],
+ dropdownLimit: Number.MAX_SAFE_INTEGER,
+ extraCommands: buildExtraCommands()
+ },
// This value must be kept in sync with the language defined in webpack.config.js.
language: "en"
};
diff --git a/packages/ckeditor5-admonition/src/index.ts b/packages/ckeditor5-admonition/src/index.ts
index c6db132c29..99edeece88 100644
--- a/packages/ckeditor5-admonition/src/index.ts
+++ b/packages/ckeditor5-admonition/src/index.ts
@@ -4,9 +4,9 @@ import "../theme/blockquote.css";
export { default as Admonition } from './admonition.js';
export { default as AdmonitionEditing } from './admonitionediting.js';
-export { default as AdmonitionUI } from './admonitionui.js';
+export { default as AdmonitionUI, ADMONITION_TYPES } from './admonitionui.js';
export { default as AdmonitionAutoformat } from './admonitionautoformat.js';
-export type { default as AdmonitionCommand } from './admonitioncommand.js';
+export type { default as AdmonitionCommand, AdmonitionType } from './admonitioncommand.js';
export const icons = {
admonitionIcon
diff --git a/packages/ckeditor5/src/extra_slash_commands.ts b/packages/ckeditor5/src/extra_slash_commands.ts
new file mode 100644
index 0000000000..96d5e81719
--- /dev/null
+++ b/packages/ckeditor5/src/extra_slash_commands.ts
@@ -0,0 +1,25 @@
+import type { Editor } from 'ckeditor5';
+import type { SlashCommandEditorConfig } from 'ckeditor5-premium-features';
+import { icons as admonitionIcons } from '@triliumnext/ckeditor5-admonition';
+import { ADMONITION_TYPES, type AdmonitionType } from '@triliumnext/ckeditor5-admonition';
+
+type SlashCommandDefinition = SlashCommandEditorConfig["extraCommands"][number];
+
+export default function buildExtraCommands(): SlashCommandDefinition[] {
+ return [
+ ...buildAdmonitionExtraCommands()
+ ];
+}
+
+function buildAdmonitionExtraCommands(): SlashCommandDefinition[] {
+ const commands: SlashCommandDefinition[] = [];
+ for (const [ keyword, definition ] of Object.entries(ADMONITION_TYPES)) {
+ commands.push({
+ id: keyword,
+ title: `Admonition: ${definition.title}`,
+ icon: admonitionIcons.admonitionIcon,
+ execute: (editor: Editor) => editor.execute("admonition", { forceValue: keyword as AdmonitionType })
+ });
+ }
+ return commands;
+}
diff --git a/packages/ckeditor5/src/index.ts b/packages/ckeditor5/src/index.ts
index 117d14574e..0ddd55d60e 100644
--- a/packages/ckeditor5/src/index.ts
+++ b/packages/ckeditor5/src/index.ts
@@ -4,6 +4,7 @@ import { COMMON_PLUGINS, CORE_PLUGINS, POPUP_EDITOR_PLUGINS } from "./plugins";
import { BalloonEditor, DecoupledEditor, FindAndReplaceEditing, FindCommand } from "ckeditor5";
export { EditorWatchdog } from "ckeditor5";
export type { EditorConfig, MentionFeed, MentionFeedObjectItem, Node, Position, Element, WatchdogConfig } from "ckeditor5";
+export { default as buildExtraCommands } from "./extra_slash_commands.js";
// Import with sideffects to ensure that type augmentations are present.
import "@triliumnext/ckeditor5-math";
@@ -25,6 +26,7 @@ export type FindCommandResult = ReturnType<FindCommand["execute"]>;
* The text editor that can be used for editing attributes and relations.
*/
export class AttributeEditor extends BalloonEditor {
+
static override get builtinPlugins() {
return CORE_PLUGINS;
}