mirror of
https://github.com/zadam/trilium.git
synced 2025-11-12 08:15:52 +01:00
feat(editor): functional autoformat when type is specified
This commit is contained in:
@@ -1,6 +1,17 @@
|
||||
import Plugin from "@ckeditor/ckeditor5-core/src/plugin";
|
||||
import Autoformat from "@ckeditor/ckeditor5-autoformat/src/autoformat";
|
||||
import blockAutoformatEditing from "@ckeditor/ckeditor5-autoformat/src/blockautoformatediting";
|
||||
import { AdmonitionType, admonitionTypes } from "./admonitioncommand";
|
||||
|
||||
function tryParseAdmonitionType(match: RegExpMatchArray) {
|
||||
if (match.length !== 2) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ((admonitionTypes as readonly string[]).includes(match[1])) {
|
||||
return match[1] as AdmonitionType;
|
||||
}
|
||||
}
|
||||
|
||||
export default class AdmonitionAutoformat extends Plugin {
|
||||
static get requires() {
|
||||
@@ -13,8 +24,13 @@ export default class AdmonitionAutoformat extends Plugin {
|
||||
}
|
||||
|
||||
const instance = (this as any);
|
||||
blockAutoformatEditing(this.editor, instance, /^\!\!\[*\! (.+) $/, (match) => {
|
||||
console.log("Got match ", match);
|
||||
blockAutoformatEditing(this.editor, instance, /^\!\!\[*\! (.+) $/, ({ match }) => {
|
||||
const type = tryParseAdmonitionType(match);
|
||||
if (!type) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.editor.execute("admonition", { forceValue: type });
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user