| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831 |
- /**
- * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
- */
- import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor';
- import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
- import LinkImageEditing from '../src/linkimageediting';
- import { getData as getModelData, setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
- import normalizeHtml from '@ckeditor/ckeditor5-utils/tests/_utils/normalizehtml';
- import { getData as getViewData } from '@ckeditor/ckeditor5-engine/src/dev-utils/view';
- import ImageCaptionEditing from '@ckeditor/ckeditor5-image/src/imagecaption/imagecaptionediting';
- describe( 'LinkImageEditing', () => {
- let editor, model, view;
- beforeEach( () => {
- return VirtualTestEditor
- .create( {
- plugins: [ Paragraph, LinkImageEditing ]
- } )
- .then( newEditor => {
- editor = newEditor;
- model = editor.model;
- view = editor.editing.view;
- } );
- } );
- afterEach( () => {
- return editor.destroy();
- } );
- it( 'should have pluginName', () => {
- expect( LinkImageEditing.pluginName ).to.equal( 'LinkImageEditing' );
- } );
- it( 'should be loaded', () => {
- expect( editor.plugins.get( LinkImageEditing ) ).to.be.instanceOf( LinkImageEditing );
- } );
- it( 'should set proper schema rules', () => {
- expect( model.schema.checkAttribute( [ '$root', 'image' ], 'linkHref' ) ).to.be.true;
- } );
- describe( 'conversion in data pipeline', () => {
- describe( 'model to view', () => {
- it( 'should attach a link indicator to the image element', () => {
- setModelData( model, '<image src="/assets/sample.png" alt="alt text" linkHref="foo"></image>' );
- expect( getViewData( view, { withoutSelection: true, renderUIElements: true } ) ).to.match( new RegExp(
- '<figure class="ck-widget image" contenteditable="false">' +
- '<a href="foo">' +
- '<img alt="alt text" src="/assets/sample.png"></img>' +
- '<span class="ck ck-link-image_icon">' +
- '<svg[^>]+>.*<\\/svg>' +
- '</span>' +
- '</a>' +
- '</figure>'
- ) );
- } );
- } );
- describe( 'model to data', () => {
- it( 'should convert an image with a link', () => {
- setModelData( model, '<image src="/assets/sample.png" alt="alt text" linkHref="http://ckeditor.com"></image>' );
- expect( editor.getData() ).to.equal(
- '<figure class="image"><a href="http://ckeditor.com"><img alt="alt text" src="/assets/sample.png"></a></figure>'
- );
- } );
- it( 'should convert an image with a link and without alt attribute', () => {
- setModelData( model, '<image src="/assets/sample.png" linkHref="http://ckeditor.com"></image>' );
- expect( editor.getData() ).to.equal(
- '<figure class="image"><a href="http://ckeditor.com"><img src="/assets/sample.png"></a></figure>'
- );
- } );
- it( 'should convert srcset attribute to srcset and sizes attribute wrapped into a link', () => {
- setModelData( model,
- '<image src="/assets/sample.png" ' +
- 'linkHref="http://ckeditor.com" ' +
- 'srcset=\'{ "data": "small.png 148w, big.png 1024w" }\'>' +
- '</image>'
- );
- expect( normalizeHtml( editor.getData() ) ).to.equal(
- '<figure class="image">' +
- '<a href="http://ckeditor.com">' +
- '<img sizes="100vw" src="/assets/sample.png" srcset="small.png 148w, big.png 1024w"></img>' +
- '</a>' +
- '</figure>'
- );
- } );
- } );
- describe( 'view to model', () => {
- describe( 'figure > a > img', () => {
- it( 'should convert a link in an image figure', () => {
- editor.setData(
- '<figure class="image"><a href="http://ckeditor.com"><img src="/assets/sample.png" alt="alt text" /></a></figure>'
- );
- expect( getModelData( model, { withoutSelection: true } ) )
- .to.equal( '<image alt="alt text" linkHref="http://ckeditor.com" src="/assets/sample.png"></image>' );
- } );
- it( 'should convert an image with a link and without alt attribute', () => {
- editor.setData( '<figure class="image"><a href="http://ckeditor.com"><img src="/assets/sample.png" /></a></figure>' );
- expect( getModelData( model, { withoutSelection: true } ) )
- .to.equal( '<image linkHref="http://ckeditor.com" src="/assets/sample.png"></image>' );
- } );
- it( 'should not convert without src attribute', () => {
- editor.setData( '<figure class="image"><a href="http://ckeditor.com"><img alt="alt text" /></a></figure>' );
- expect( getModelData( model, { withoutSelection: true } ) )
- .to.equal( '<paragraph></paragraph>' );
- } );
- it( 'should not convert in wrong context', () => {
- model.schema.register( 'div', { inheritAllFrom: '$block' } );
- model.schema.addChildCheck( ( ctx, childDef ) => {
- if ( ctx.endsWith( '$root' ) && childDef.name == 'image' ) {
- return false;
- }
- } );
- editor.conversion.elementToElement( { model: 'div', view: 'div' } );
- editor.setData(
- '<div>' +
- '<figure class="image">' +
- '<a href="http://ckeditor.com">' +
- '<img src="/assets/sample.png" alt="alt text" />' +
- '</a>' +
- '</figure>' +
- '</div>' );
- expect( getModelData( model, { withoutSelection: true } ) )
- .to.equal( '<div></div>' );
- } );
- it( 'should not convert "a" element if is already consumed', () => {
- editor.data.upcastDispatcher.on( 'element:a', ( evt, data, conversionApi ) => {
- conversionApi.consumable.consume( data.viewItem, { attributes: [ 'href' ] } );
- }, { priority: 'highest' } );
- editor.setData(
- '<figure class="image"><a href="http://ckeditor.com"><img src="/assets/sample.png" alt="alt text" /></a></figure>'
- );
- expect( editor.getData() ).to.equal( '<figure class="image"><img src="/assets/sample.png" alt="alt text"></figure>' );
- } );
- it( 'should not convert if a link misses "href" attribute', () => {
- editor.setData(
- '<figure class="image"><a href=""><img src="/assets/sample.png" alt="alt text" /></a></figure>'
- );
- expect( getModelData( model, { withoutSelection: true } ) )
- .to.equal( '<image alt="alt text" src="/assets/sample.png"></image>' );
- } );
- it( 'should convert a link without an image to a paragraph with the link', () => {
- editor.setData(
- '<figure class="image"><a href="http://ckeditor.com">Foo</a></figure>'
- );
- expect( getModelData( model, { withoutSelection: true } ) )
- .to.equal( '<paragraph><$text linkHref="http://ckeditor.com">Foo</$text></paragraph>' );
- } );
- } );
- describe( 'a > img', () => {
- it( 'should convert a link in an image figure', () => {
- editor.setData(
- '<a href="http://ckeditor.com"><img src="/assets/sample.png" alt="alt text" /></a>'
- );
- expect( getModelData( model, { withoutSelection: true } ) )
- .to.equal( '<image alt="alt text" linkHref="http://ckeditor.com" src="/assets/sample.png"></image>' );
- } );
- it( 'should convert an image with a link and without alt attribute', () => {
- editor.setData( '<a href="http://ckeditor.com"><img src="/assets/sample.png" /></a>' );
- expect( getModelData( model, { withoutSelection: true } ) )
- .to.equal( '<image linkHref="http://ckeditor.com" src="/assets/sample.png"></image>' );
- } );
- it( 'should not convert without src attribute', () => {
- editor.setData( '<a href="http://ckeditor.com"><img alt="alt text" /></a>' );
- expect( getModelData( model, { withoutSelection: true } ) )
- .to.equal( '<paragraph></paragraph>' );
- } );
- it( 'should not convert in wrong context', () => {
- model.schema.register( 'div', { inheritAllFrom: '$block' } );
- model.schema.addChildCheck( ( ctx, childDef ) => {
- if ( ctx.endsWith( '$root' ) && childDef.name == 'image' ) {
- return false;
- }
- } );
- editor.conversion.elementToElement( { model: 'div', view: 'div' } );
- editor.setData(
- '<div>' +
- '<a href="http://ckeditor.com">' +
- '<img src="/assets/sample.png" alt="alt text" />' +
- '</a>' +
- '</div>' );
- expect( getModelData( model, { withoutSelection: true } ) )
- .to.equal( '<div></div>' );
- } );
- it( 'should not convert "a" element if is already consumed', () => {
- editor.data.upcastDispatcher.on( 'element:a', ( evt, data, conversionApi ) => {
- conversionApi.consumable.consume( data.viewItem, { attributes: [ 'href' ] } );
- }, { priority: 'highest' } );
- editor.setData(
- '<a href="http://ckeditor.com"><img src="/assets/sample.png" alt="alt text" /></a>'
- );
- expect( editor.getData() ).to.equal( '<figure class="image"><img src="/assets/sample.png" alt="alt text"></figure>' );
- } );
- it( 'should not convert if a link misses "href" attribute', () => {
- editor.setData(
- '<a href=""><img src="/assets/sample.png" alt="alt text" /></a>'
- );
- expect( getModelData( model, { withoutSelection: true } ) )
- .to.equal( '<image alt="alt text" src="/assets/sample.png"></image>' );
- } );
- } );
- describe( 'figure > a > img + figcaption', () => {
- it( 'should convert a link and the caption element', () => {
- return VirtualTestEditor
- .create( {
- plugins: [ Paragraph, LinkImageEditing, ImageCaptionEditing ]
- } )
- .then( editor => {
- editor.setData(
- '<figure class="image">' +
- '<a href="http://ckeditor.com">' +
- '<img src="/assets/sample.png" alt="alt text" />' +
- '</a>' +
- '<figcaption>' +
- 'Foo Bar.' +
- '</figcaption>' +
- '</figure>'
- );
- expect( getModelData( editor.model, { withoutSelection: true } ) ).to.equal(
- '<image alt="alt text" linkHref="http://ckeditor.com" src="/assets/sample.png">' +
- '<caption>Foo Bar.</caption>' +
- '</image>'
- );
- return editor.destroy();
- } );
- } );
- } );
- } );
- } );
- describe( 'conversion in editing pipeline', () => {
- describe( 'model to view', () => {
- it( 'should convert the image element', () => {
- setModelData( model, '<image linkHref="http://ckeditor.com" src="/assets/sample.png" alt="alt text"></image>' );
- expect( getViewData( view, { withoutSelection: true } ) ).to.equal(
- '<figure class="ck-widget image" contenteditable="false">' +
- '<a href="http://ckeditor.com">' +
- '<img alt="alt text" src="/assets/sample.png"></img>' +
- // Content of the UIElement is skipped here.
- '<span class="ck ck-link-image_icon"></span>' +
- '</a>' +
- '</figure>'
- );
- } );
- it( 'should convert attribute change', () => {
- setModelData( model, '<image linkHref="http://ckeditor.com" src="/assets/sample.png" alt="alt text"></image>' );
- const image = model.document.getRoot().getChild( 0 );
- model.change( writer => {
- writer.setAttribute( 'linkHref', 'https://ckeditor.com/why-ckeditor/', image );
- } );
- expect( getViewData( view, { withoutSelection: true } ) ).to.equal(
- '<figure class="ck-widget image" contenteditable="false">' +
- '<a href="https://ckeditor.com/why-ckeditor/">' +
- '<img alt="alt text" src="/assets/sample.png"></img>' +
- // Content of the UIElement is skipped here.
- '<span class="ck ck-link-image_icon"></span>' +
- '</a>' +
- '</figure>'
- );
- } );
- it( 'should convert attribute removal', () => {
- setModelData( model, '<image linkHref="http://ckeditor.com" src="/assets/sample.png" alt="alt text"></image>' );
- const image = model.document.getRoot().getChild( 0 );
- model.change( writer => {
- writer.removeAttribute( 'linkHref', image );
- } );
- expect( getViewData( view, { withoutSelection: true } ) ).to.equal(
- '<figure class="ck-widget image" contenteditable="false">' +
- '<img alt="alt text" src="/assets/sample.png"></img>' +
- '</figure>'
- );
- } );
- } );
- describe( 'figure > a > img + span + figcaption', () => {
- it( 'should convert a link and the caption element', () => {
- return VirtualTestEditor
- .create( {
- plugins: [ Paragraph, LinkImageEditing, ImageCaptionEditing ]
- } )
- .then( editor => {
- setModelData( editor.model,
- '<image linkHref="http://ckeditor.com" src="/assets/sample.png" alt="alt text">' +
- '<caption>Foo Bar.</caption>' +
- '</image>'
- );
- expect( getViewData( editor.editing.view, { withoutSelection: true } ) ).to.equal(
- '<figure class="ck-widget image" contenteditable="false">' +
- '<a href="http://ckeditor.com">' +
- '<img alt="alt text" src="/assets/sample.png"></img>' +
- // Content of the UIElement is skipped here.
- '<span class="ck ck-link-image_icon"></span>' +
- '</a>' +
- '<figcaption class="ck-editor__editable ck-editor__nested-editable" ' +
- 'contenteditable="true" data-placeholder="Enter image caption">' +
- 'Foo Bar.' +
- '</figcaption>' +
- '</figure>'
- );
- return editor.destroy();
- } );
- } );
- } );
- } );
- describe( 'link attributes decorator', () => {
- describe( 'default behavior', () => {
- const testLinks = [
- {
- external: true,
- url: 'http://example.com'
- }, {
- external: true,
- url: 'https://cksource.com'
- }, {
- external: false,
- url: 'ftp://server.io'
- }, {
- external: true,
- url: '//schemaless.org'
- }, {
- external: false,
- url: 'www.ckeditor.com'
- }, {
- external: false,
- url: '/relative/url.html'
- }, {
- external: false,
- url: 'another/relative/url.html'
- }, {
- external: false,
- url: '#anchor'
- }, {
- external: false,
- url: 'mailto:some@user.org'
- }, {
- external: false,
- url: 'tel:123456789'
- }
- ];
- describe( 'for link.addTargetToExternalLinks=false', () => {
- let editor, model;
- beforeEach( async () => {
- editor = await VirtualTestEditor.create( {
- plugins: [ Paragraph, LinkImageEditing ],
- link: {
- addTargetToExternalLinks: false
- }
- } );
- model = editor.model;
- view = editor.editing.view;
- } );
- afterEach( async () => {
- await editor.destroy();
- } );
- testLinks.forEach( link => {
- it( `link: ${ link.url } should not get 'target' and 'rel' attributes`, () => {
- // Upcast check.
- editor.setData(
- '<figure class="image">' +
- `<a href="${ link.url }" target="_blank" rel="noopener noreferrer">` +
- '<img src="/assets/sample.png">' +
- '</a>' +
- '</figure>'
- );
- expect( getModelData( model, { withoutSelection: true } ) )
- .to.equal( `<image linkHref="${ link.url }" src="/assets/sample.png"></image>` );
- // Downcast check.
- expect( editor.getData() ).to.equal(
- '<figure class="image">' +
- `<a href="${ link.url }">` +
- '<img src="/assets/sample.png">' +
- '</a>' +
- '</figure>'
- );
- } );
- } );
- } );
- describe( 'for link.addTargetToExternalLinks=true', () => {
- let editor, model;
- beforeEach( async () => {
- editor = await VirtualTestEditor.create( {
- plugins: [ Paragraph, LinkImageEditing ],
- link: {
- addTargetToExternalLinks: true
- }
- } );
- model = editor.model;
- view = editor.editing.view;
- } );
- afterEach( async () => {
- await editor.destroy();
- } );
- testLinks.forEach( link => {
- it( `link: ${ link.url } should be treat as ${ link.external ? 'external' : 'non-external' } link`, () => {
- // Upcast check.
- editor.setData(
- `<a href="${ link.url }" target="_blank" rel="noopener noreferrer"><img src="/assets/sample.png"></a>`
- );
- expect( getModelData( model, { withoutSelection: true } ) )
- .to.equal( `<image linkHref="${ link.url }" src="/assets/sample.png"></image>` );
- // Downcast check.
- if ( link.external ) {
- expect( editor.getData() ).to.equal(
- '<figure class="image">' +
- `<a href="${ link.url }" target="_blank" rel="noopener noreferrer">` +
- '<img src="/assets/sample.png">' +
- '</a>' +
- '</figure>'
- );
- } else {
- expect( editor.getData() ).to.equal(
- '<figure class="image">' +
- `<a href="${ link.url }">` +
- '<img src="/assets/sample.png">' +
- '</a>' +
- '</figure>'
- );
- }
- } );
- } );
- } );
- } );
- describe( 'custom config', () => {
- describe( 'mode: automatic', () => {
- let editor;
- const testLinks = [
- {
- url: 'relative/url.html',
- attributes: {}
- }, {
- url: 'http://exmaple.com',
- attributes: {
- target: '_blank'
- }
- }, {
- url: 'https://example.com/download/link.pdf',
- attributes: {
- target: '_blank',
- download: 'download'
- }
- }, {
- url: 'mailto:some@person.io',
- attributes: {
- class: 'mail-url'
- }
- }
- ];
- beforeEach( async () => {
- editor = await VirtualTestEditor.create( {
- plugins: [ Paragraph, LinkImageEditing ],
- link: {
- addTargetToExternalLinks: false,
- decorators: {
- isExternal: {
- mode: 'automatic',
- callback: url => url.startsWith( 'http' ),
- attributes: {
- target: '_blank'
- }
- },
- isDownloadable: {
- mode: 'automatic',
- callback: url => url.includes( 'download' ),
- attributes: {
- download: 'download'
- }
- },
- isMail: {
- mode: 'automatic',
- callback: url => url.startsWith( 'mailto:' ),
- attributes: {
- class: 'mail-url'
- }
- }
- }
- }
- } );
- model = editor.model;
- } );
- afterEach( () => {
- return editor.destroy();
- } );
- testLinks.forEach( link => {
- it( `Link: ${ link.url } should get attributes: ${ JSON.stringify( link.attributes ) }`, () => {
- const ORDER = [ 'class', 'href', 'target', 'download' ];
- const attributes = Object.assign( {}, link.attributes, {
- href: link.url
- } );
- const attr = Object.entries( attributes ).sort( ( a, b ) => {
- const aIndex = ORDER.indexOf( a[ 0 ] );
- const bIndex = ORDER.indexOf( b[ 0 ] );
- return aIndex - bIndex;
- } );
- const reducedAttr = attr.reduce( ( acc, cur ) => {
- return acc + `${ cur[ 0 ] }="${ cur[ 1 ] }" `;
- }, '' ).trim();
- editor.setData( `<a href="${ link.url }"><img src="/assets/sample.png"></a>` );
- expect( getModelData( model, { withoutSelection: true } ) )
- .to.equal( `<image linkHref="${ link.url }" src="/assets/sample.png"></image>` );
- // Order of attributes is important, that's why this is assert is construct in such way.
- expect( editor.getData() ).to.equal(
- '<figure class="image">' +
- `<a ${ reducedAttr }>` +
- '<img src="/assets/sample.png">' +
- '</a>' +
- '</figure>'
- );
- } );
- } );
- } );
- } );
- describe( 'upcast converter', () => {
- let editor, model;
- beforeEach( () => {
- return VirtualTestEditor
- .create( {
- plugins: [ Paragraph, LinkImageEditing ],
- link: {
- decorators: {
- isExternal: {
- mode: 'manual',
- label: 'Open in a new tab',
- attributes: {
- target: '_blank',
- rel: 'noopener noreferrer'
- }
- },
- isDownloadable: {
- mode: 'manual',
- label: 'Downloadable',
- attributes: {
- download: 'download'
- }
- },
- isGallery: {
- mode: 'manual',
- label: 'Gallery link',
- attributes: {
- class: 'gallery'
- }
- }
- }
- }
- } )
- .then( newEditor => {
- editor = newEditor;
- model = editor.model;
- } );
- } );
- afterEach( () => {
- return editor.destroy();
- } );
- it( 'should upcast attributes', async () => {
- editor.setData(
- '<figure class="image">' +
- '<a href="url" target="_blank" rel="noopener noreferrer" download="download">' +
- '<img src="/assets/sample.png">' +
- '</a>' +
- '</figure>'
- );
- expect( getModelData( model, { withoutSelection: true } ) ).to.equal(
- '<image linkHref="url" linkIsDownloadable="true" linkIsExternal="true" src="/assets/sample.png"></image>'
- );
- await editor.destroy();
- } );
- it( 'should not upcast partial and incorrect attributes', async () => {
- editor.setData(
- '<figure class="image">' +
- '<a href="url" target="_blank" rel="noopener noreferrer" download="something">' +
- '<img src="/assets/sample.png">' +
- '</a>' +
- '</figure>'
- );
- expect( getModelData( model, { withoutSelection: true } ) ).to.equal(
- '<image linkHref="url" linkIsExternal="true" src="/assets/sample.png"></image>'
- );
- } );
- it( 'allows overwriting conversion process using highest priority', () => {
- // Block manual decorator converter. Consume all attributes and do nothing with them.
- editor.conversion.for( 'upcast' ).add( dispatcher => {
- dispatcher.on( 'element:a', ( evt, data, conversionApi ) => {
- const consumableAttributes = {
- attributes: [ 'target', 'rel', 'download' ]
- };
- conversionApi.consumable.consume( data.viewItem, consumableAttributes );
- }, { priority: 'highest' } );
- } );
- editor.setData(
- '<figure class="image">' +
- '<a href="url" target="_blank" rel="noopener noreferrer" download="something">' +
- '<img src="/assets/sample.png">' +
- '</a>' +
- '</figure>'
- );
- expect( editor.getData() ).to.equal( '<figure class="image"><a href="url"><img src="/assets/sample.png"></a></figure>' );
- } );
- it( 'should upcast the decorators when linked image (figure > a > img)', () => {
- // (#7975)
- editor.setData(
- '<figure class="image">' +
- '<a class="gallery" href="https://cksource.com" target="_blank" rel="noopener noreferrer" download="download">' +
- '<img src="sample.jpg" alt="bar">' +
- '</a>' +
- '<figcaption>Caption</figcaption>' +
- '</figure>' +
- '<p>' +
- '<a href="https://cksource.com" target="_blank" rel="noopener noreferrer" download="download">' +
- 'https://cksource.com' +
- '</a>' +
- '</p>'
- );
- expect( getModelData( model, { withoutSelection: true } ) ).to.equal(
- '<image alt="bar" ' +
- 'linkHref="https://cksource.com" ' +
- 'linkIsDownloadable="true" ' +
- 'linkIsExternal="true" ' +
- 'linkIsGallery="true" ' +
- 'src="sample.jpg">' +
- '</image>' +
- '<paragraph>' +
- '<$text linkHref="https://cksource.com" linkIsDownloadable="true" linkIsExternal="true">' +
- 'https://cksource.com' +
- '</$text>' +
- '</paragraph>'
- );
- } );
- it( 'should upcast the decorators when linked image (a > img)', () => {
- // (#7975)
- editor.setData(
- '<a class="gallery" href="https://cksource.com" target="_blank" rel="noopener noreferrer" download="download">' +
- '<img src="sample.jpg" alt="bar">' +
- '</a>' +
- '<p>' +
- '<a href="https://cksource.com" target="_blank" rel="noopener noreferrer" download="download">' +
- 'https://cksource.com' +
- '</a>' +
- '</p>'
- );
- expect( getModelData( model, { withoutSelection: true } ) ).to.equal(
- '<image alt="bar" ' +
- 'linkHref="https://cksource.com" ' +
- 'linkIsDownloadable="true" ' +
- 'linkIsExternal="true" ' +
- 'linkIsGallery="true" ' +
- 'src="sample.jpg">' +
- '</image>' +
- '<paragraph>' +
- '<$text linkHref="https://cksource.com" linkIsDownloadable="true" linkIsExternal="true">' +
- 'https://cksource.com' +
- '</$text>' +
- '</paragraph>'
- );
- } );
- } );
- describe( 'downcast converter', () => {
- let editor, model;
- beforeEach( () => {
- return VirtualTestEditor
- .create( {
- plugins: [ Paragraph, LinkImageEditing ],
- link: {
- decorators: {
- isExternal: {
- mode: 'manual',
- label: 'Open in a new tab',
- attributes: {
- target: '_blank',
- rel: 'noopener noreferrer'
- }
- },
- isDownloadable: {
- mode: 'manual',
- label: 'Downloadable',
- attributes: {
- download: 'download'
- }
- },
- isGallery: {
- mode: 'manual',
- label: 'Gallery link',
- attributes: {
- class: 'gallery'
- }
- }
- }
- }
- } )
- .then( newEditor => {
- editor = newEditor;
- model = editor.model;
- } );
- } );
- afterEach( () => {
- return editor.destroy();
- } );
- it( 'should downcast the decorators after applying a change', () => {
- setModelData( model,
- '[<image alt="bar" src="sample.jpg"></image>]' +
- '<paragraph>' +
- '<$text>https://cksource.com</$text>' +
- '</paragraph>'
- );
- editor.execute( 'link', 'https://cksource.com', {
- linkIsDownloadable: true,
- linkIsExternal: true,
- linkIsGallery: true
- } );
- model.change( writer => {
- writer.setSelection( model.document.getRoot().getChild( 1 ).getChild( 0 ), 'on' );
- } );
- editor.execute( 'link', 'https://cksource.com', {
- linkIsDownloadable: true,
- linkIsExternal: true,
- linkIsGallery: true
- } );
- expect( editor.getData() ).to.equal(
- '<figure class="image">' +
- '<a class="gallery" href="https://cksource.com" download="download" target="_blank" rel="noopener noreferrer">' +
- '<img src="sample.jpg" alt="bar">' +
- '</a>' +
- '</figure>' +
- '<p>' +
- '<a class="gallery" href="https://cksource.com" download="download" target="_blank" rel="noopener noreferrer">' +
- 'https://cksource.com' +
- '</a>' +
- '</p>'
- );
- } );
- } );
- } );
- } );
|