feat(admonitions): allow changing admonition type

This commit is contained in:
Elian Doran 2025-03-13 22:20:12 +02:00
parent fb7e310224
commit 504879b11c
2 changed files with 22 additions and 10 deletions

View File

@ -162,6 +162,10 @@ export default class AdmonitionCommand extends Command {
quote = writer.createElement( 'aside', { type });
writer.wrap( groupRange, quote );
} else if (quote.is("element")) {
this.editor.model.change((writer) => {
writer.setAttribute("type", type, quote as Element);
});
}
quotesToMerge.push( quote );

View File

@ -70,16 +70,24 @@ export default class AdmonitionEditing extends Plugin {
}
});
editor.conversion.for("downcast").elementToElement( {
model: 'aside',
view: (modelElement, { writer }) => {
return writer.createContainerElement(
"aside", {
class: [ "admonition", modelElement.getAttribute("type") ].join(" ")
}
)
}
});
editor.conversion.for("downcast")
.elementToElement( {
model: 'aside',
view: (modelElement, { writer }) => {
return writer.createContainerElement(
"aside", {
class: [ "admonition", modelElement.getAttribute("type") ].join(" ")
}
)
}
})
.attributeToAttribute({
model: "type",
view: (value) => ({
key: "class",
value: [ "admonition", value as string ]
})
});
// Postfixer which cleans incorrect model states connected with block quotes.
editor.model.document.registerPostFixer( writer => {