This repository has been archived by the owner on Jun 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
Merged
Removed LinkElement #163
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/** | ||
* @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved. | ||
* For licensing, see LICENSE.md. | ||
*/ | ||
|
||
/** | ||
* @module link/utils | ||
*/ | ||
|
||
import AttributeElement from '@ckeditor/ckeditor5-engine/src/view/attributeelement'; | ||
|
||
const linkElementSymbol = Symbol( 'linkElement' ); | ||
|
||
/** | ||
* Returns `true` if a given view node is the link element. | ||
* | ||
* @param {module:engine/view/node~Node} node | ||
* @return {Boolean} | ||
*/ | ||
export function isLinkElement( node ) { | ||
return node.is( 'attributeElement' ) && !!node.getCustomProperty( linkElementSymbol ); | ||
} | ||
|
||
/** | ||
* Creates link {@link module:engine/view/attributeelement~AttributeElement} with provided `href` attribute. | ||
* | ||
* @param {String} href | ||
* @return {module:engine/view/attributeelement~AttributeElement} | ||
*/ | ||
export function createLinkElement( href ) { | ||
const linkElement = new AttributeElement( 'a', { href } ); | ||
linkElement.setCustomProperty( linkElementSymbol, true ); | ||
|
||
// https://github.com/ckeditor/ckeditor5-link/issues/121 | ||
linkElement.priority = 5; | ||
|
||
return linkElement; | ||
} | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/** | ||
* @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved. | ||
* For licensing, see LICENSE.md. | ||
*/ | ||
|
||
import AttributeElement from '@ckeditor/ckeditor5-engine/src/view/attributeelement'; | ||
import ContainerElement from '@ckeditor/ckeditor5-engine/src/view/containerelement'; | ||
import Text from '@ckeditor/ckeditor5-engine/src/view/text'; | ||
|
||
import { createLinkElement, isLinkElement } from '../src/utils'; | ||
|
||
describe( 'utils', () => { | ||
describe( 'isLinkElement', () => { | ||
it( 'should return true for elements created by createLinkElement', () => { | ||
const element = createLinkElement( 'http://ckeditor.com' ); | ||
|
||
expect( isLinkElement( element ) ).to.be.true; | ||
} ); | ||
|
||
it( 'should return false for other AttributeElements', () => { | ||
expect( isLinkElement( new AttributeElement( 'a' ) ) ).to.be.false; | ||
} ); | ||
|
||
it( 'should return false for ContainerElements', () => { | ||
expect( isLinkElement( new ContainerElement( 'p' ) ) ).to.be.false; | ||
} ); | ||
|
||
it( 'should return false for text nodes', () => { | ||
expect( isLinkElement( new Text( 'foo' ) ) ).to.be.false; | ||
} ); | ||
} ); | ||
|
||
describe( 'createLinkElement', () => { | ||
it( 'should create link AttributeElement', () => { | ||
const element = createLinkElement( 'http://cksource.com' ); | ||
|
||
expect( isLinkElement( element ) ).to.be.true; | ||
expect( element.priority ).to.equal( 5 ); | ||
expect( element.getAttribute( 'href' ) ).to.equal( 'http://cksource.com' ); | ||
expect( element.name ).to.equal( 'a' ); | ||
} ); | ||
} ); | ||
} ); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need a separate file for these methods? I mean they are used only once and I don't think this code will be used again. I think we could just keep it in-place.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you think that link will never be created by any other feature? I actually think that the chance is very high for this (by 3rd party code).