mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-09-19 02:10:04 +08:00
fix(admonitions): breaking math plugin
This commit is contained in:
parent
2c6df42d51
commit
80de28c617
@ -18,6 +18,7 @@ import type { DocumentFragment, Element, Position, Range, Schema, Writer } from
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
export const ADMONITION_TYPES = [ "note", "tip", "important", "caution", "warning" ] as const;
|
export const ADMONITION_TYPES = [ "note", "tip", "important", "caution", "warning" ] as const;
|
||||||
|
export const ADMONITION_TYPE_ATTRIBUTE = "admonitionType";
|
||||||
export const DEFAULT_ADMONITION_TYPE = ADMONITION_TYPES[0];
|
export const DEFAULT_ADMONITION_TYPE = ADMONITION_TYPES[0];
|
||||||
export type AdmonitionType = typeof ADMONITION_TYPES[number];
|
export type AdmonitionType = typeof ADMONITION_TYPES[number];
|
||||||
|
|
||||||
@ -119,7 +120,7 @@ export default class AdmonitionCommand extends Command {
|
|||||||
// In the current implementation, the admonition must be an immediate parent of a block element.
|
// In the current implementation, the admonition must be an immediate parent of a block element.
|
||||||
const firstQuote = findQuote( firstBlock );
|
const firstQuote = findQuote( firstBlock );
|
||||||
if (firstQuote?.is("element")) {
|
if (firstQuote?.is("element")) {
|
||||||
return firstQuote.getAttribute("type") as AdmonitionType;
|
return firstQuote.getAttribute(ADMONITION_TYPE_ATTRIBUTE) as AdmonitionType;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@ -203,7 +204,7 @@ export default class AdmonitionCommand extends Command {
|
|||||||
writer.wrap( groupRange, quote );
|
writer.wrap( groupRange, quote );
|
||||||
} else if (quote.is("element")) {
|
} else if (quote.is("element")) {
|
||||||
this.editor.model.change((writer) => {
|
this.editor.model.change((writer) => {
|
||||||
writer.setAttribute("type", type, quote as Element);
|
writer.setAttribute(ADMONITION_TYPE_ATTRIBUTE, type, quote as Element);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ import { Plugin } from 'ckeditor5/src/core.js';
|
|||||||
import { Enter, type ViewDocumentEnterEvent } from 'ckeditor5/src/enter.js';
|
import { Enter, type ViewDocumentEnterEvent } from 'ckeditor5/src/enter.js';
|
||||||
import { Delete, type ViewDocumentDeleteEvent } from 'ckeditor5/src/typing.js';
|
import { Delete, type ViewDocumentDeleteEvent } from 'ckeditor5/src/typing.js';
|
||||||
|
|
||||||
import AdmonitionCommand, { AdmonitionType, ADMONITION_TYPES, DEFAULT_ADMONITION_TYPE } from './admonitioncommand.js';
|
import AdmonitionCommand, { AdmonitionType, ADMONITION_TYPES, DEFAULT_ADMONITION_TYPE, ADMONITION_TYPE_ATTRIBUTE } from './admonitioncommand.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The block quote editing.
|
* The block quote editing.
|
||||||
@ -46,7 +46,7 @@ export default class AdmonitionEditing extends Plugin {
|
|||||||
|
|
||||||
schema.register( 'aside', {
|
schema.register( 'aside', {
|
||||||
inheritAllFrom: '$container',
|
inheritAllFrom: '$container',
|
||||||
allowAttributes: "type"
|
allowAttributes: ADMONITION_TYPE_ATTRIBUTE
|
||||||
} );
|
} );
|
||||||
|
|
||||||
editor.conversion.for("upcast").elementToElement({
|
editor.conversion.for("upcast").elementToElement({
|
||||||
@ -62,9 +62,9 @@ export default class AdmonitionEditing extends Plugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return writer.createElement("aside", {
|
const attributes: Record<string, unknown> = {};
|
||||||
type
|
attributes[ADMONITION_TYPE_ATTRIBUTE] = type;
|
||||||
});
|
return writer.createElement("aside", attributes);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -74,7 +74,7 @@ export default class AdmonitionEditing extends Plugin {
|
|||||||
view: "aside"
|
view: "aside"
|
||||||
})
|
})
|
||||||
.attributeToAttribute({
|
.attributeToAttribute({
|
||||||
model: "type",
|
model: ADMONITION_TYPE_ATTRIBUTE,
|
||||||
view: (value) => ({
|
view: (value) => ({
|
||||||
key: "class",
|
key: "class",
|
||||||
value: [ "admonition", value as string ]
|
value: [ "admonition", value as string ]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user