diff --git a/src/model/model.js b/src/model/model.js index 5655415b4..86cfb6175 100644 --- a/src/model/model.js +++ b/src/model/model.js @@ -105,6 +105,14 @@ export default class Model { isLimit: true } ); this.schema.extend( '$text', { allowIn: '$clipboardHolder' } ); + + // Element needed by `upcastElementToMarker` converter. + // This element temporarily represents marker bound during conversion process and is removed + // at the end of conversion. `UpcastDispatcher` or at least `Conversion` class looks like a better for this + // registration but both know nothing about Schema. + this.schema.register( '$marker', { + allowIn: [ '$root', '$block' ] + } ); } /** diff --git a/tests/conversion/upcast-converters.js b/tests/conversion/upcast-converters.js index a6f1379de..391d9c83d 100644 --- a/tests/conversion/upcast-converters.js +++ b/tests/conversion/upcast-converters.js @@ -35,21 +35,14 @@ describe( 'upcast-helpers', () => { schema = model.schema; schema.extend( '$text', { - allowIn: '$root' - } ); - - schema.register( '$marker', { - inheritAllFrom: '$block' + allowIn: '$root', + allowAttributes: [ 'bold' ] } ); schema.register( 'paragraph', { inheritAllFrom: '$block' } ); - schema.extend( '$text', { - allowAttributes: [ 'bold' ] - } ); - upcastDispatcher = new UpcastDispatcher( { schema } ); upcastDispatcher.on( 'text', convertText() ); upcastDispatcher.on( 'element', convertToModelFragment(), { priority: 'lowest' } ); @@ -580,6 +573,26 @@ describe( 'upcast-helpers', () => { expectResult( frag, 'foobar', marker ); } ); + + it( 'marker is in a block element', () => { + conversion.for( 'upcast' ).add( upcastElementToElement( { model: 'paragraph', view: 'p' } ) ); + + const helper = upcastElementToMarker( { view: 'marker-search', model: 'search' } ); + + conversion.for( 'upcast' ).add( helper ); + + const element = new ViewContainerElement( 'p', null, [ + new ViewText( 'fo' ), + new ViewUIElement( 'marker-search' ), + new ViewText( 'oba' ), + new ViewUIElement( 'marker-search' ), + new ViewText( 'r' ) + ] ); + + const marker = { name: 'search', start: [ 0, 2 ], end: [ 0, 5 ] }; + + expectResult( element, 'foobar', marker ); + } ); } ); function expectResult( viewToConvert, modelString, marker ) { diff --git a/tests/manual/highlight.js b/tests/manual/highlight.js index 5718633b9..9a09cd3a3 100644 --- a/tests/manual/highlight.js +++ b/tests/manual/highlight.js @@ -49,8 +49,7 @@ class FancyWidget extends Plugin { conversion.for( 'editingDowncast' ).add( downcastElementToElement( { model: 'fancywidget', - view: ( modelItem, conversionApi ) => { - const viewWriter = conversionApi.writer; + view: ( modelItem, viewWriter ) => { const widgetElement = viewWriter.createContainerElement( 'figure', { class: 'fancy-widget' } ); viewWriter.insert( ViewPosition.createAt( widgetElement ), viewWriter.createText( 'widget' ) ); diff --git a/tests/model/model.js b/tests/model/model.js index 9c7d77dca..03359a31c 100644 --- a/tests/model/model.js +++ b/tests/model/model.js @@ -50,6 +50,12 @@ describe( 'Model', () => { expect( schema.checkChild( [ '$clipboardHolder' ], '$text' ) ).to.be.true; expect( schema.checkChild( [ '$clipboardHolder' ], '$block' ) ).to.be.true; } ); + + it( 'registers $marker to the schema', () => { + expect( schema.isRegistered( '$marker' ) ).to.be.true; + expect( schema.checkChild( [ '$root' ], '$marker' ), 1 ).to.be.true; + expect( schema.checkChild( [ '$block' ], '$marker' ), 1 ).to.be.true; + } ); } ); describe( 'change() & enqueueChange()', () => {