mirror of
https://github.com/zadam/trilium.git
synced 2025-11-07 05:46:10 +01:00
40 lines
929 B
TypeScript
40 lines
929 B
TypeScript
|
|
import { Plugin, ButtonView } from 'ckeditor5';
|
||
|
|
|
||
|
|
import ckeditor5Icon from '../theme/icons/ckeditor.svg';
|
||
|
|
|
||
|
|
export default class Admonition extends Plugin {
|
||
|
|
public static get pluginName() {
|
||
|
|
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: ckeditor5Icon,
|
||
|
|
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;
|
||
|
|
} );
|
||
|
|
}
|
||
|
|
}
|