| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928 |
- /**
- * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md.
- */
- /* bender-tags: treeview */
- 'use strict';
- import Writer from '/ckeditor5/engine/treeview/writer.js';
- import Element from '/ckeditor5/engine/treeview/element.js';
- import ContainerElement from '/ckeditor5/engine/treeview/containerelement.js';
- import AttributeElement from '/ckeditor5/engine/treeview/attributeelement.js';
- import Position from '/ckeditor5/engine/treeview/position.js';
- import Range from '/ckeditor5/engine/treeview/range.js';
- import Text from '/ckeditor5/engine/treeview/text.js';
- import utils from '/tests/engine/treeview/writer/_utils/utils.js';
- import CKEditorError from '/ckeditor5/utils/ckeditorerror.js';
- describe( 'Writer', () => {
- const create = utils.create;
- const test = utils.test;
- let writer;
- beforeEach( () => {
- writer = new Writer();
- } );
- describe( 'unwrap', () => {
- it( 'should do nothing on collapsed ranges', () => {
- const description = {
- instanceOf: ContainerElement,
- name: 'p',
- children: [
- { instanceOf: Text, data: 'foo', rangeStart: 1, rangeEnd: 1 }
- ]
- };
- const created = create( writer, description );
- const newRange = writer.unwrap( created.range, new AttributeElement( 'b' ), 1 );
- test( writer, newRange, created.node, description );
- } );
- it( 'should do nothing on single text node', () => {
- // <p>[{foobar}]</p>
- const description = {
- instanceOf: ContainerElement,
- name: 'p',
- rangeStart: 0,
- rangeEnd: 1,
- children: [
- { instanceOf: Text, data: 'foobar' }
- ]
- };
- const created = create( writer, description );
- const b = new AttributeElement( 'b' );
- b.priority = 1;
- const newRange = writer.unwrap( created.range, b );
- test( writer, newRange, created.node, description );
- } );
- it( 'should throw error when element is not instance of AttributeElement', () => {
- const container = new ContainerElement( 'p', null, new AttributeElement( 'b', null, new Text( 'foo' ) ) );
- const range = new Range(
- new Position( container, 0 ),
- new Position( container, 1 )
- );
- const b = new Element( 'b' );
- expect( () => {
- writer.unwrap( range, b );
- } ).to.throw( CKEditorError, 'treeview-writer-unwrap-invalid-attribute' );
- } );
- it( 'should throw error when range placed in two containers', () => {
- const container1 = new ContainerElement( 'p' );
- const container2 = new ContainerElement( 'p' );
- const range = new Range(
- new Position( container1, 0 ),
- new Position( container2, 1 )
- );
- const b = new AttributeElement( 'b' );
- expect( () => {
- writer.unwrap( range, b, 1 );
- } ).to.throw( CKEditorError, 'treeview-writer-invalid-range-container' );
- } );
- it( 'should unwrap single node', () => {
- // <p>[<b>{foobar}</b>]<p> -> <p>[{foobar}]</p>
- const created = create( writer, {
- instanceOf: ContainerElement,
- name: 'p',
- rangeStart: 0,
- rangeEnd: 1,
- children: [
- {
- instanceOf: AttributeElement,
- name: 'b',
- priority: 1,
- children: [
- { instanceOf: Text, data: 'foobar' }
- ]
- }
- ]
- } );
- const b = new AttributeElement( 'b' );
- b.priority = 1;
- const newRange = writer.unwrap( created.range, b );
- test( writer, newRange, created.node, {
- instanceOf: ContainerElement,
- name: 'p',
- rangeStart: 0,
- rangeEnd: 1,
- children: [
- { instanceOf: Text, data: 'foobar' }
- ]
- } );
- } );
- it( 'should not unwrap attributes with different priorities #1', () => {
- // <p>[<b>{foobar}</b>]<p> -> <p>[<b>{foobar}</b>]</p>
- // Unwrapped with <b> but using different priority.
- const description = {
- instanceOf: ContainerElement,
- name: 'p',
- rangeStart: 0,
- rangeEnd: 1,
- children: [
- {
- instanceOf: AttributeElement,
- name: 'b',
- priority: 1,
- children: [
- { instanceOf: Text, data: 'foobar' }
- ]
- }
- ]
- };
- const created = create( writer, description );
- const b = new AttributeElement( 'b' );
- b.priority = 2;
- const newRange = writer.unwrap( created.range, b );
- test( writer, newRange, created.node, description );
- } );
- it( 'should not unwrap attributes with different priorities #2', () => {
- // <p>[<b>{foo}</b><b>{bar}</b><b>{baz}</b>]<p> -> <p>[{foo}<b>bar</b>{baz}]</p>
- // <b> around `bar` has different priority than others.
- const created = create( writer, {
- instanceOf: ContainerElement,
- name: 'p',
- rangeStart: 0,
- rangeEnd: 3,
- children: [
- {
- instanceOf: AttributeElement,
- name: 'b',
- priority: 2,
- children: [
- { instanceOf: Text, data: 'foo' }
- ]
- },
- {
- instanceOf: AttributeElement,
- name: 'b',
- priority: 1,
- children: [
- { instanceOf: Text, data: 'bar' }
- ]
- },
- {
- instanceOf: AttributeElement,
- name: 'b',
- priority: 2,
- children: [
- { instanceOf: Text, data: 'baz' }
- ]
- }
- ]
- } );
- const b = new AttributeElement( 'b' );
- b.priority = 2;
- const newRange = writer.unwrap( created.range, b );
- test( writer, newRange, created.node, {
- instanceOf: ContainerElement,
- name: 'p',
- rangeStart: 0,
- rangeEnd: 3,
- children: [
- { instanceOf: Text, data: 'foo' },
- {
- instanceOf: AttributeElement,
- name: 'b',
- priority: 1,
- children: [
- { instanceOf: Text, data: 'bar' }
- ]
- },
- { instanceOf: Text, data: 'baz' }
- ]
- } );
- } );
- it( 'should unwrap part of the node', () => {
- // <p>[{baz}<b>{foo]bar}</b><p> -> <p>[{bazfoo}]<b>{bar}</b></p>
- const created = create( writer, {
- instanceOf: ContainerElement,
- name: 'p',
- rangeStart: 0,
- children: [
- { instanceOf: Text, data: 'baz' },
- {
- instanceOf: AttributeElement,
- name: 'b',
- priority: 1,
- children: [
- { instanceOf: Text, data: 'foobar', rangeEnd: 3 }
- ]
- }
- ]
- } );
- const b = new AttributeElement( 'b' );
- b.priority = 1;
- const newRange = writer.unwrap( created.range, b );
- test( writer, newRange, created.node, {
- instanceOf: ContainerElement,
- name: 'p',
- rangeStart: 0,
- rangeEnd: 1,
- children: [
- { instanceOf: Text, data: 'bazfoo' },
- {
- instanceOf: AttributeElement,
- name: 'b',
- priority: 1,
- children: [
- { instanceOf: Text, data: 'bar' }
- ]
- }
- ]
- } );
- } );
- it( 'should unwrap nested attributes', () => {
- // <p>[<u><b>{foobar}</b></u>]</p> -> <p>[<u>{foobar}</u>]</p>
- const created = create( writer, {
- instanceOf: ContainerElement,
- name: 'p',
- rangeStart: 0,
- rangeEnd: 1,
- children: [
- {
- instanceOf: AttributeElement,
- name: 'u',
- priority: 1,
- children: [
- {
- instanceOf: AttributeElement,
- name: 'b',
- priority: 1,
- children: [
- { instanceOf: Text, data: 'foobar' }
- ]
- }
- ]
- }
- ]
- } );
- const b = new AttributeElement( 'b' );
- b.priority = 1;
- const newRange = writer.unwrap( created.range, b );
- test( writer, newRange, created.node, {
- instanceOf: ContainerElement,
- name: 'p',
- rangeStart: 0,
- rangeEnd: 1,
- children: [
- {
- instanceOf: AttributeElement,
- name: 'u',
- priority: 1,
- children: [
- { instanceOf: Text, data: 'foobar' }
- ]
- }
- ]
- } );
- } );
- it( 'should merge unwrapped nodes #1', () => {
- // <p>{foo}[<b>{bar}</b>]{bom}</p> -> <p>{foo[bar]bom}</p>
- const created = create( writer, {
- instanceOf: ContainerElement,
- name: 'p',
- rangeStart: 1,
- rangeEnd: 2,
- children: [
- { instanceOf: Text, data: 'foo' },
- {
- instanceOf: AttributeElement,
- name: 'b',
- priority: 1,
- children: [
- { instanceOf: Text, data: 'bar' }
- ]
- },
- { instanceOf: Text, data: 'bom' }
- ]
- } );
- const b = new AttributeElement( 'b' );
- b.priority = 1;
- const newRange = writer.unwrap( created.range, b );
- test( writer, newRange, created.node, {
- instanceOf: ContainerElement,
- name: 'p',
- children: [
- {
- instanceOf: Text,
- data: 'foobarbom',
- rangeStart: 3,
- rangeEnd: 6
- }
- ]
- } );
- } );
- it( 'should merge unwrapped nodes #2', () => {
- // <p>{foo}<u>{bar}</u>[<b><u>{bazqux}</u></b>]</p> -> <p>{foo}<u>{bar[bazqux}</u>]</p>
- const created = create( writer, {
- instanceOf: ContainerElement,
- name: 'p',
- rangeStart: 2,
- rangeEnd: 3,
- children: [
- { instanceOf: Text, data: 'foo' },
- {
- instanceOf: AttributeElement,
- name: 'u',
- priority: 1,
- children: [
- { instanceOf: Text, data: 'bar' }
- ]
- },
- {
- instanceOf: AttributeElement,
- name: 'b',
- priority: 1,
- children: [
- {
- instanceOf: AttributeElement,
- name: 'u',
- priority: 1,
- children: [
- { instanceOf: Text, data: 'bazqux' }
- ]
- }
- ]
- }
- ]
- } );
- const b = new AttributeElement( 'b' );
- b.priority = 1;
- const newRange = writer.unwrap( created.range, b );
- test( writer, newRange, created.node, {
- instanceOf: ContainerElement,
- name: 'p',
- rangeEnd: 2,
- children: [
- {
- instanceOf: Text,
- data: 'foo'
- },
- {
- instanceOf: AttributeElement,
- name: 'u',
- priority: 1,
- children: [
- { instanceOf: Text, data: 'barbazqux', rangeStart: 3 }
- ]
- }
- ]
- } );
- } );
- it( 'should merge unwrapped nodes #3', () => {
- // <p>{foo}<u>{bar}</u>[<b><u>{baz]qux}</u></b></p> -> <p>{foo}<u>{bar[baz}</u>]<b><u>{qux}</u></b></p>
- const created = create( writer, {
- instanceOf: ContainerElement,
- name: 'p',
- rangeStart: 2,
- children: [
- { instanceOf: Text, data: 'foo' },
- {
- instanceOf: AttributeElement,
- name: 'u',
- priority: 1,
- children: [
- { instanceOf: Text, data: 'bar' }
- ]
- },
- {
- instanceOf: AttributeElement,
- name: 'b',
- priority: 1,
- children: [
- {
- instanceOf: AttributeElement,
- name: 'u',
- priority: 1,
- children: [
- { instanceOf: Text, data: 'bazqux', rangeEnd: 3 }
- ]
- }
- ]
- }
- ]
- } );
- const b = new AttributeElement( 'b' );
- b.priority = 1;
- const newRange = writer.unwrap( created.range, b );
- test( writer, newRange, created.node, {
- instanceOf: ContainerElement,
- name: 'p',
- rangeEnd: 2,
- children: [
- {
- instanceOf: Text,
- data: 'foo'
- },
- {
- instanceOf: AttributeElement,
- name: 'u',
- priority: 1,
- children: [
- { instanceOf: Text, data: 'barbaz', rangeStart: 3 }
- ]
- },
- {
- instanceOf: AttributeElement,
- name: 'b',
- priority: 1,
- children: [
- {
- instanceOf: AttributeElement,
- name: 'u',
- priority: 1,
- children: [
- { instanceOf: Text, data: 'qux' }
- ]
- }
- ]
- }
- ]
- } );
- } );
- it( 'should merge unwrapped nodes #4', () => {
- // <p>{foo}<u>{bar}</u>[<b><u>{baz}</u></b>]<u>qux</u></p> -> <p>{foo}<u>{bar[baz]qux}</u></p>
- const created = create( writer, {
- instanceOf: ContainerElement,
- name: 'p',
- rangeStart: 2,
- rangeEnd: 3,
- children: [
- { instanceOf: Text, data: 'foo' },
- {
- instanceOf: AttributeElement,
- name: 'u',
- priority: 1,
- children: [
- { instanceOf: Text, data: 'bar' }
- ]
- },
- {
- instanceOf: AttributeElement,
- name: 'b',
- priority: 1,
- children: [
- {
- instanceOf: AttributeElement,
- name: 'u',
- priority: 1,
- children: [
- { instanceOf: Text, data: 'baz' }
- ]
- }
- ]
- },
- {
- instanceOf: AttributeElement,
- name: 'u',
- priority: 1,
- children: [
- { instanceOf: Text, data: 'qux' }
- ]
- }
- ]
- } );
- const b = new AttributeElement( 'b' );
- b.priority = 1;
- const newRange = writer.unwrap( created.range, b );
- test( writer, newRange, created.node, {
- instanceOf: ContainerElement,
- name: 'p',
- children: [
- {
- instanceOf: Text,
- data: 'foo'
- },
- {
- instanceOf: AttributeElement,
- name: 'u',
- priority: 1,
- children: [
- { instanceOf: Text, data: 'barbazqux', rangeStart: 3, rangeEnd: 6 }
- ]
- }
- ]
- } );
- } );
- it( 'should merge unwrapped nodes #5', () => {
- // <p>[<b><u>{foo}</u></b><b><u>{bar}</u></b><b><u>{baz}</u></b>]</p> -> <p>[<u>{foobarbaz}</u>]</p>
- const created = create( writer, {
- instanceOf: ContainerElement,
- name: 'p',
- rangeStart: 0,
- rangeEnd: 3,
- children: [
- {
- instanceOf: AttributeElement,
- name: 'b',
- priority: 1,
- children: [
- {
- instanceOf: AttributeElement,
- name: 'u',
- priority: 1,
- children: [
- { instanceOf: Text, data: 'foo' }
- ]
- }
- ]
- },
- {
- instanceOf: AttributeElement,
- name: 'b',
- priority: 1,
- children: [
- {
- instanceOf: AttributeElement,
- name: 'u',
- priority: 1,
- children: [
- { instanceOf: Text, data: 'bar' }
- ]
- }
- ]
- },
- {
- instanceOf: AttributeElement,
- name: 'b',
- priority: 1,
- children: [
- {
- instanceOf: AttributeElement,
- name: 'u',
- priority: 1,
- children: [
- { instanceOf: Text, data: 'baz' }
- ]
- }
- ]
- }
- ]
- } );
- const b = new AttributeElement( 'b' );
- b.priority = 1;
- const newRange = writer.unwrap( created.range, b );
- test( writer, newRange, created.node, {
- instanceOf: ContainerElement,
- name: 'p',
- rangeStart: 0,
- rangeEnd: 1,
- children: [
- {
- instanceOf: AttributeElement,
- name: 'u',
- priority: 1,
- children: [
- { instanceOf: Text, data: 'foobarbaz' }
- ]
- }
- ]
- } );
- } );
- it( 'should unwrap mixed ranges #1', () => {
- // <p>[<u><b>{foo}]</b></u></p> -> <p>[<u>{foo}</u>]</p
- const created = create( writer, {
- instanceOf: ContainerElement,
- name: 'p',
- rangeStart: 0,
- children: [
- {
- instanceOf: AttributeElement,
- name: 'u',
- priority: 1,
- children: [
- {
- instanceOf: AttributeElement,
- name: 'b',
- priority: 1,
- rangeEnd: 1,
- children: [
- { instanceOf: Text, data: 'foo' }
- ]
- }
- ]
- }
- ]
- } );
- const b = new AttributeElement( 'b' );
- b.priority = 1;
- const newRange = writer.unwrap( created.range, b );
- test( writer, newRange, created.node, {
- instanceOf: ContainerElement,
- name: 'p',
- rangeStart: 0,
- rangeEnd: 1,
- children: [
- {
- instanceOf: AttributeElement,
- name: 'u',
- priority: 1,
- children: [
- { instanceOf: Text, data: 'foo' }
- ]
- }
- ]
- } );
- } );
- it( 'should unwrap mixed ranges #2', () => {
- // <p>[<u><b>{foo]}</b></u></p> -> <p>[<u>{foo}</u>]</p
- const created = create( writer, {
- instanceOf: ContainerElement,
- name: 'p',
- rangeStart: 0,
- children: [
- {
- instanceOf: AttributeElement,
- name: 'u',
- priority: 1,
- children: [
- {
- instanceOf: AttributeElement,
- name: 'b',
- priority: 1,
- children: [
- { instanceOf: Text, data: 'foo', rangeEnd: 3 }
- ]
- }
- ]
- }
- ]
- } );
- const b = new AttributeElement( 'b' );
- b.priority = 1;
- const newRange = writer.unwrap( created.range, b );
- test( writer, newRange, created.node, {
- instanceOf: ContainerElement,
- name: 'p',
- rangeStart: 0,
- rangeEnd: 1,
- children: [
- {
- instanceOf: AttributeElement,
- name: 'u',
- priority: 1,
- children: [
- { instanceOf: Text, data: 'foo' }
- ]
- }
- ]
- } );
- } );
- it( 'should unwrap single element by removing matching attributes', () => {
- // <p>[<b foo="bar" baz="qux" >test</b>]</p>
- // unwrap using <b baz="qux"></b>
- // <p>[<b foo="bar">test</b>]</p>
- const text = new Text( 'test' );
- const b = new AttributeElement( 'b', {
- foo: 'bar',
- baz: 'qux'
- }, text );
- const p = new ContainerElement( 'p', null, b );
- const wrapper = new AttributeElement( 'b', {
- baz: 'qux'
- } );
- const range = Range.createFromParentsAndOffsets( p, 0, p, 1 );
- const newRange = writer.unwrap( range, wrapper );
- expect( b.getAttribute( 'foo' ) ).to.equal( 'bar' );
- expect( b.hasAttribute( 'baz' ) ).to.be.false;
- expect( b.parent ).to.equal( p );
- test( writer, newRange, p, {
- instanceof: ContainerElement,
- name: 'p',
- rangeStart: 0,
- rangeEnd: 1,
- children: [
- {
- instanceof: AttributeElement,
- name: 'b',
- children: [
- { instanceof: Text, data: 'test' }
- ]
- }
- ]
- } );
- } );
- it( 'should not unwrap single element when attributes are different', () => {
- // <p>[<b foo="bar" baz="qux">test</b>]</p>
- // unwrap using <b baz="qux" test="true"></b>
- // <p>[<b foo="bar" baz="qux">test</b>]</p>
- const text = new Text( 'test' );
- const b = new AttributeElement( 'b', {
- foo: 'bar',
- baz: 'qux'
- }, text );
- const p = new ContainerElement( 'p', null, b );
- const wrapper = new AttributeElement( 'b', {
- baz: 'qux',
- test: 'true'
- } );
- const range = Range.createFromParentsAndOffsets( p, 0, p, 1 );
- const newRange = writer.unwrap( range, wrapper );
- expect( b.getAttribute( 'foo' ) ).to.equal( 'bar' );
- expect( b.getAttribute( 'baz' ) ).to.equal( 'qux' );
- expect( b.parent ).to.equal( p );
- test( writer, newRange, p, {
- instanceof: ContainerElement,
- name: 'p',
- rangeStart: 0,
- rangeEnd: 1,
- children: [
- {
- instanceof: AttributeElement,
- name: 'b',
- children: [
- { instanceof: Text, data: 'test' }
- ]
- }
- ]
- } );
- } );
- it( 'should unwrap single element by removing matching classes', () => {
- // <p>[<b class="foo bar baz">test</b>]</p>
- // unwrap using <b class="baz foo"></b>
- // <p>[<b class="bar">test</b>]</p>
- const text = new Text( 'test' );
- const b = new AttributeElement( 'b', {
- class: 'foo bar baz'
- }, text );
- const p = new ContainerElement( 'p', null, b );
- const wrapper = new AttributeElement( 'b', {
- class: 'baz foo'
- } );
- const range = Range.createFromParentsAndOffsets( p, 0, p, 1 );
- const newRange = writer.unwrap( range, wrapper );
- expect( b.hasClass( 'bar' ) ).to.be.true;
- expect( b.hasClass( 'foo' ) ).to.be.false;
- expect( b.hasClass( 'baz' ) ).to.be.false;
- expect( b.parent ).to.equal( p );
- test( writer, newRange, p, {
- instanceof: ContainerElement,
- name: 'p',
- rangeStart: 0,
- rangeEnd: 1,
- children: [
- {
- instanceof: AttributeElement,
- name: 'b',
- children: [
- { instanceof: Text, data: 'test' }
- ]
- }
- ]
- } );
- } );
- it( 'should not unwrap single element when classes are different', () => {
- // <p>[<b class="foo bar baz">test</b>]</p>
- // unwrap using <b class="baz foo qux"></b>
- // <p>[<b class="foo bar baz">test</b>]</p>
- const text = new Text( 'test' );
- const b = new AttributeElement( 'b', {
- class: 'foo bar baz'
- }, text );
- const p = new ContainerElement( 'p', null, b );
- const wrapper = new AttributeElement( 'b', {
- class: 'baz foo qux'
- } );
- const range = Range.createFromParentsAndOffsets( p, 0, p, 1 );
- const newRange = writer.unwrap( range, wrapper );
- expect( b.hasClass( 'bar' ) ).to.be.true;
- expect( b.hasClass( 'foo' ) ).to.be.true;
- expect( b.hasClass( 'baz' ) ).to.be.true;
- expect( b.parent ).to.equal( p );
- test( writer, newRange, p, {
- instanceof: ContainerElement,
- name: 'p',
- rangeStart: 0,
- rangeEnd: 1,
- children: [
- {
- instanceof: AttributeElement,
- name: 'b',
- children: [
- { instanceof: Text, data: 'test' }
- ]
- }
- ]
- } );
- } );
- it( 'should unwrap single element by removing matching styles', () => {
- // <p>[<b style="color:red; position:absolute; top:10px;">test</b>]</p>
- // unwrap using <b style="position: absolute;"></b>
- // <p>[<b style="color:red; top:10px;">test</b>]</p>
- const text = new Text( 'test' );
- const b = new AttributeElement( 'b', {
- style: 'color:red; position:absolute; top:10px;'
- }, text );
- const p = new ContainerElement( 'p', null, b );
- const wrapper = new AttributeElement( 'b', {
- style: 'position: absolute;'
- } );
- const range = Range.createFromParentsAndOffsets( p, 0, p, 1 );
- const newRange = writer.unwrap( range, wrapper );
- expect( b.getStyle( 'color' ) ).to.equal( 'red' );
- expect( b.getStyle( 'top' ) ).to.equal( '10px' );
- expect( b.hasStyle( 'position' ) ).to.be.false;
- expect( b.parent ).to.equal( p );
- test( writer, newRange, p, {
- instanceof: ContainerElement,
- name: 'p',
- rangeStart: 0,
- rangeEnd: 1,
- children: [
- {
- instanceof: AttributeElement,
- name: 'b',
- children: [
- { instanceof: Text, data: 'test' }
- ]
- }
- ]
- } );
- } );
- it( 'should not unwrap single element when styles are different', () => {
- // <p>[<b style="color:red; position:absolute; top:10px;">test</b>]</p>
- // unwrap using <b style="position: relative;"></b>
- // <p>[<b style="color:red; position:absolute; top:10px;">test</b>]</p>
- const text = new Text( 'test' );
- const b = new AttributeElement( 'b', {
- style: 'color:red; position:absolute; top:10px;'
- }, text );
- const p = new ContainerElement( 'p', null, b );
- const wrapper = new AttributeElement( 'b', {
- style: 'position: relative;'
- } );
- const range = Range.createFromParentsAndOffsets( p, 0, p, 1 );
- const newRange = writer.unwrap( range, wrapper );
- expect( b.getStyle( 'color' ) ).to.equal( 'red' );
- expect( b.getStyle( 'top' ) ).to.equal( '10px' );
- expect( b.getStyle( 'position' ) ).to.equal( 'absolute' );
- expect( b.parent ).to.equal( p );
- test( writer, newRange, p, {
- instanceof: ContainerElement,
- name: 'p',
- rangeStart: 0,
- rangeEnd: 1,
- children: [
- {
- instanceof: AttributeElement,
- name: 'b',
- children: [
- { instanceof: Text, data: 'test' }
- ]
- }
- ]
- } );
- } );
- } );
- } );
|