Skip to content

Build your personal knowledge base with Trilium Notes

chore(ckeditor5): integrate ckeditor5-admonition

Elian Dorana494ff1169d1
diff --git a/packages/ckeditor5-admonition/src/admonition.ts b/packages/ckeditor5-admonition/src/admonition.ts
index edc31357d6..33cbf25286 100644
--- a/packages/ckeditor5-admonition/src/admonition.ts
+++ b/packages/ckeditor5-admonition/src/admonition.ts
@@ -1,6 +1,5 @@
-import { Plugin, ButtonView } from 'ckeditor5';
+import { Plugin } from 'ckeditor5';
-import admonitionIcon from '../theme/icons/admonition.svg';
import AdmonitionEditing from './admonitionediting.js';
import AdmonitionUI from './admonitionui.js';
import AdmonitionAutoformat from './admonitionautoformat.js';
@@ -15,33 +14,4 @@ export default class Admonition extends Plugin {
return 'Admonition' as const;
}
- public init(): void {
- const editor = this.editor;
- const t = editor.t;
- const model = editor.model;
-
- // Register the "admonition" button, so it can be displayed in the toolbar.
- editor.ui.componentFactory.add( 'admonition', locale => {
- const view = new ButtonView( locale );
-
- view.set( {
- label: t( 'Admonition' ),
- icon: admonitionIcon,
- tooltip: true
- } );
-
- // Insert a text into the editor after clicking the button.
- this.listenTo( view, 'execute', () => {
- model.change( writer => {
- const textNode = writer.createText( 'Hello CKEditor 5!' );
-
- model.insertContent( textNode );
- } );
-
- editor.editing.view.focus();
- } );
-
- return view;
- } );
- }
}
diff --git a/packages/ckeditor5-admonition/src/index.ts b/packages/ckeditor5-admonition/src/index.ts
index 0242a34fa4..c6db132c29 100644
--- a/packages/ckeditor5-admonition/src/index.ts
+++ b/packages/ckeditor5-admonition/src/index.ts
@@ -1,4 +1,4 @@
-import ckeditor from './../theme/icons/ckeditor.svg';
+import admonitionIcon from '../theme/icons/admonition.svg';
import './augmentation.js';
import "../theme/blockquote.css";
@@ -9,5 +9,5 @@ export { default as AdmonitionAutoformat } from './admonitionautoformat.js';
export type { default as AdmonitionCommand } from './admonitioncommand.js';
export const icons = {
- ckeditor
+ admonitionIcon
};
diff --git a/packages/ckeditor5-admonition/tests/admonition.ts b/packages/ckeditor5-admonition/tests/admonition.ts
deleted file mode 100644
index a7357ed12e..0000000000
--- a/packages/ckeditor5-admonition/tests/admonition.ts
+++ /dev/null
@@ -1,56 +0,0 @@
-import { describe, expect, it, beforeEach, afterEach } from 'vitest';
-import { ClassicEditor, Essentials, Paragraph, Heading } from 'ckeditor5';
-import Admonition from '../src/admonition.js';
-
-describe( 'Admonition', () => {
- it( 'should be named', () => {
- expect( Admonition.pluginName ).to.equal( 'Admonition' );
- } );
-
- describe( 'init()', () => {
- let domElement: HTMLElement, editor: ClassicEditor;
-
- beforeEach( async () => {
- domElement = document.createElement( 'div' );
- document.body.appendChild( domElement );
-
- editor = await ClassicEditor.create( domElement, {
- licenseKey: 'GPL',
- plugins: [
- Paragraph,
- Heading,
- Essentials,
- Admonition
- ],
- toolbar: [
- 'admonition'
- ]
- } );
- } );
-
- afterEach( () => {
- domElement.remove();
- return editor.destroy();
- } );
-
- it( 'should load Admonition', () => {
- const myPlugin = editor.plugins.get( 'Admonition' );
-
- expect( myPlugin ).to.be.an.instanceof( Admonition );
- } );
-
- it( 'should add an icon to the toolbar', () => {
- expect( editor.ui.componentFactory.has( 'admonition' ) ).to.equal( true );
- } );
-
- it( 'should add a text into the editor after clicking the icon', () => {
- const icon = editor.ui.componentFactory.create( 'admonition' );
-
- expect( editor.getData() ).to.equal( '' );
-
- icon.fire( 'execute' );
-
- expect( editor.getData() ).to.equal( '<p>Hello CKEditor 5!</p>' );
- } );
- } );
-} );
diff --git a/packages/ckeditor5-admonition/tests/index.ts b/packages/ckeditor5-admonition/tests/index.ts
deleted file mode 100644
index 1c3ad627ec..0000000000
--- a/packages/ckeditor5-admonition/tests/index.ts
+++ /dev/null
@@ -1,17 +0,0 @@
-import { describe, expect, it } from 'vitest';
-import { Admonition as AdmonitionDll, icons } from '../src/index.js';
-import Admonition from '../src/admonition.js';
-
-import ckeditor from './../theme/icons/ckeditor.svg';
-
-describe( 'CKEditor5 Admonition DLL', () => {
- it( 'exports Admonition', () => {
- expect( AdmonitionDll ).to.equal( Admonition );
- } );
-
- describe( 'icons', () => {
- it( 'exports the "ckeditor" icon', () => {
- expect( icons.ckeditor ).to.equal( ckeditor );
- } );
- } );
-} );
diff --git a/packages/ckeditor5-admonition/tsconfig.json b/packages/ckeditor5-admonition/tsconfig.json
index 069e3cb16b..f53643f74d 100644
--- a/packages/ckeditor5-admonition/tsconfig.json
+++ b/packages/ckeditor5-admonition/tsconfig.json
@@ -17,6 +17,7 @@
],
"noImplicitAny": true,
"noImplicitOverride": true,
+ "composite": true,
"strict": true,
"target": "es2019",
"sourceMap": true,
diff --git a/packages/ckeditor5/package.json b/packages/ckeditor5/package.json
index 4e69049ee2..949bfe5d02 100644
--- a/packages/ckeditor5/package.json
+++ b/packages/ckeditor5/package.json
@@ -21,7 +21,8 @@
"dependencies": {
"ckeditor5": "43.2.0",
"@triliumnext/ckeditor5-keyboard-marker": "workspace:*",
- "@triliumnext/ckeditor5-mermaid": "workspace:*"
+ "@triliumnext/ckeditor5-mermaid": "workspace:*",
+ "@triliumnext/ckeditor5-admonition": "workspace:*"
},
"devDependencies": {
"@types/jquery": "3.5.32"
diff --git a/packages/ckeditor5/src/plugins.ts b/packages/ckeditor5/src/plugins.ts
index aef2909f49..bfb33841f0 100644
--- a/packages/ckeditor5/src/plugins.ts
+++ b/packages/ckeditor5/src/plugins.ts
@@ -15,8 +15,10 @@ import IncludeNote from "./plugins/includenote.js";
import Uploadfileplugin from "./plugins/file_upload/uploadfileplugin.js";
import { Kbd } from "@triliumnext/ckeditor5-keyboard-marker";
import { Mermaid } from "@triliumnext/ckeditor5-mermaid";
+import { Admonition } from "@triliumnext/ckeditor5-admonition";
import "@triliumnext/ckeditor5-mermaid/index.css";
+import "@triliumnext/ckeditor5-admonition/index.css";
const TRILIUM_PLUGINS: typeof Plugin[] = [
CutToNotePlugin,
@@ -36,7 +38,8 @@ const TRILIUM_PLUGINS: typeof Plugin[] = [
const EXTERNAL_PLUGINS: typeof Plugin[] = [
Kbd,
- Mermaid
+ Mermaid,
+ Admonition
];
export const COMMON_PLUGINS: typeof Plugin[] = [
@@ -102,8 +105,7 @@ export const COMMON_PLUGINS: typeof Plugin[] = [
// External plugins
// Math,
// AutoformatMath,
- // Footnotes,
- // Admonition
+ // Footnotes
];
export const COMMON_SETTINGS = { };
diff --git a/packages/ckeditor5/tsconfig.json b/packages/ckeditor5/tsconfig.json
index 33dc5beb1a..7bc3add808 100644
--- a/packages/ckeditor5/tsconfig.json
+++ b/packages/ckeditor5/tsconfig.json
@@ -3,6 +3,9 @@
"files": [],
"include": [],
"references": [
+ {
+ "path": "../ckeditor5-admonition"
+ },
{
"path": "../ckeditor5-mermaid"
},
diff --git a/packages/ckeditor5/tsconfig.lib.json b/packages/ckeditor5/tsconfig.lib.json
index d4ba9f0aa8..d5f64c53e8 100644
--- a/packages/ckeditor5/tsconfig.lib.json
+++ b/packages/ckeditor5/tsconfig.lib.json
@@ -19,6 +19,9 @@
"src/**/*.ts"
],
"references": [
+ {
+ "path": "../ckeditor5-admonition"
+ },
{
"path": "../ckeditor5-mermaid"
},
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 3928dd3ca3..413367aea4 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -801,6 +801,9 @@ importers:
packages/ckeditor5:
dependencies:
+ '@triliumnext/ckeditor5-admonition':
+ specifier: workspace:*
+ version: link:../ckeditor5-admonition
'@triliumnext/ckeditor5-keyboard-marker':
specifier: workspace:*
version: link:../ckeditor5-keyboard-marker
@@ -948,7 +951,7 @@ importers:
vitest:
specifier: ^2.0.5
webdriverio:
specifier: ^9.0.7
@@ -1024,7 +1027,7 @@ importers:
vitest:
specifier: ^2.0.5
webdriverio:
specifier: ^9.0.7
@@ -18815,7 +18818,7 @@ snapshots:
sirv: 3.0.1
tinyrainbow: 1.2.0
optionalDependencies:
playwright: 1.52.0
@@ -28808,10 +28811,10 @@ snapshots:
tsx: 4.19.4
yaml: 2.7.1
dependencies:
'@vitest/expect': 2.1.9
'@vitest/pretty-format': 2.1.9
'@vitest/runner': 2.1.9
'@vitest/snapshot': 2.1.9
@@ -28827,12 +28830,12 @@ snapshots:
tinyexec: 0.3.2
tinypool: 1.0.2
tinyrainbow: 1.2.0
why-is-node-running: 2.3.0
optionalDependencies:
'@types/node': 22.15.3
'@vitest/ui': 3.1.2([email protected])
happy-dom: 17.4.6
@@ -28847,10 +28850,10 @@ snapshots:
- supports-color
- terser
dependencies:
'@vitest/expect': 2.1.9
'@vitest/pretty-format': 2.1.9
'@vitest/runner': 2.1.9
'@vitest/snapshot': 2.1.9
@@ -28866,12 +28869,12 @@ snapshots:
tinyexec: 0.3.2
tinypool: 1.0.2
tinyrainbow: 1.2.0
why-is-node-running: 2.3.0
optionalDependencies:
'@types/node': 22.15.3
'@vitest/ui': 3.1.2([email protected])
happy-dom: 17.4.6
diff --git a/tsconfig.json b/tsconfig.json
index fa6c30ae74..f470c36ff5 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -41,6 +41,9 @@
},
{
"path": "./packages/ckeditor5-mermaid"
+ },
+ {
+ "path": "./packages/ckeditor5-admonition"
}
]
}