feat(admonitions): use aside instead of blockquote

This commit is contained in:
Elian Doran 2025-03-13 19:28:57 +02:00
parent d11254e044
commit c49b30cf53
3 changed files with 15 additions and 15 deletions

View File

@ -15,7 +15,7 @@
], ],
"htmlOutput": [ "htmlOutput": [
{ {
"elements": "blockquote" "elements": "aside"
} }
] ]
} }

View File

@ -151,7 +151,7 @@ export default class AdmonitionCommand extends Command {
let quote = findQuote( groupRange.start ); let quote = findQuote( groupRange.start );
if ( !quote ) { if ( !quote ) {
quote = writer.createElement( 'blockQuote' ); quote = writer.createElement( 'aside' );
writer.wrap( groupRange, quote ); writer.wrap( groupRange, quote );
} }
@ -176,7 +176,7 @@ export default class AdmonitionCommand extends Command {
} }
function findQuote( elementOrPosition: Element | Position ): Element | DocumentFragment | null { function findQuote( elementOrPosition: Element | Position ): Element | DocumentFragment | null {
return elementOrPosition.parent!.name == 'blockQuote' ? elementOrPosition.parent : null; return elementOrPosition.parent!.name == 'aside' ? elementOrPosition.parent : null;
} }
/** /**
@ -215,8 +215,8 @@ function getRangesOfBlockGroups( writer: Writer, blocks: Array<Element> ): Array
*/ */
function checkCanBeQuoted( schema: Schema, block: Element ): boolean { function checkCanBeQuoted( schema: Schema, block: Element ): boolean {
// TMP will be replaced with schema.checkWrap(). // TMP will be replaced with schema.checkWrap().
const isBQAllowed = schema.checkChild( block.parent as Element, 'blockQuote' ); const isBQAllowed = schema.checkChild( block.parent as Element, 'aside' );
const isBlockAllowedInBQ = schema.checkChild( [ '$root', 'blockQuote' ], block ); const isBlockAllowedInBQ = schema.checkChild( [ '$root', 'aside' ], block );
return isBQAllowed && isBlockAllowedInBQ; return isBQAllowed && isBlockAllowedInBQ;
} }

View File

@ -16,7 +16,7 @@ import AdmonitionCommand from './admonitioncommand.js';
/** /**
* The block quote editing. * The block quote editing.
* *
* Introduces the `'blockQuote'` command and the `'blockQuote'` model element. * Introduces the `'admonition'` command and the `'aside'` model element.
* *
* @extends module:core/plugin~Plugin * @extends module:core/plugin~Plugin
*/ */
@ -44,11 +44,11 @@ export default class AdmonitionEditing extends Plugin {
editor.commands.add( 'admonition', new AdmonitionCommand( editor ) ); editor.commands.add( 'admonition', new AdmonitionCommand( editor ) );
schema.register( 'admonition', { schema.register( 'aside', {
inheritAllFrom: '$container' inheritAllFrom: '$container'
} ); } );
editor.conversion.elementToElement( { model: 'blockQuote', view: 'admonition' } ); editor.conversion.elementToElement( { model: 'aside', view: 'aside' } );
// Postfixer which cleans incorrect model states connected with block quotes. // Postfixer which cleans incorrect model states connected with block quotes.
editor.model.document.registerPostFixer( writer => { editor.model.document.registerPostFixer( writer => {
@ -63,13 +63,13 @@ export default class AdmonitionEditing extends Plugin {
continue; continue;
} }
if ( element.is( 'element', 'blockQuote' ) && element.isEmpty ) { if ( element.is( 'element', 'aside' ) && element.isEmpty ) {
// Added an empty blockQuote - remove it. // Added an empty aside - remove it.
writer.remove( element ); writer.remove( element );
return true; return true;
} else if ( element.is( 'element', 'blockQuote' ) && !schema.checkChild( entry.position, element ) ) { } else if ( element.is( 'element', 'aside' ) && !schema.checkChild( entry.position, element ) ) {
// Added a blockQuote in incorrect place. Unwrap it so the content inside is not lost. // Added a aside in incorrect place. Unwrap it so the content inside is not lost.
writer.unwrap( element ); writer.unwrap( element );
return true; return true;
@ -79,7 +79,7 @@ export default class AdmonitionEditing extends Plugin {
for ( const child of range.getItems() ) { for ( const child of range.getItems() ) {
if ( if (
child.is( 'element', 'blockQuote' ) && child.is( 'element', 'aside' ) &&
!schema.checkChild( writer.createPositionBefore( child ), child ) !schema.checkChild( writer.createPositionBefore( child ), child )
) { ) {
writer.unwrap( child ); writer.unwrap( child );
@ -91,8 +91,8 @@ export default class AdmonitionEditing extends Plugin {
} else if ( entry.type == 'remove' ) { } else if ( entry.type == 'remove' ) {
const parent = entry.position.parent; const parent = entry.position.parent;
if ( parent.is( 'element', 'blockQuote' ) && parent.isEmpty ) { if ( parent.is( 'element', 'aside' ) && parent.isEmpty ) {
// Something got removed and now blockQuote is empty. Remove the blockQuote as well. // Something got removed and now aside is empty. Remove the aside as well.
writer.remove( parent ); writer.remove( parent );
return true; return true;