link/utils
Constants
-
LINK_KEYSTROKE : 'Ctrl+K'
module:link/utils~LINK_KEYSTROKE
A keystroke used by the link UI feature.
Type Definitions
-
module:link/utils~NormalizedLinkDecoratorAutomaticDefinition
-
module:link/utils~NormalizedLinkDecoratorDefinition
-
module:link/utils~NormalizedLinkDecoratorManualDefinition
Functions
-
addLinkProtocolIfApplicable( link, [ defaultProtocol ] ) → string
module:link/utils~addLinkProtocolIfApplicable
Adds the protocol prefix to the specified
link
when:- it does not contain it already, and there is a
defaultProtocol
configuration value provided, - or the link is an email address.
Parameters
link : string
[ defaultProtocol ] : string
Returns
string
- it does not contain it already, and there is a
-
createLinkElement( href, __namedParameters ) → ViewAttributeElement
module:link/utils~createLinkElement
Creates a link
ViewAttributeElement
with the providedhref
attribute.Parameters
href : string
__namedParameters : DowncastConversionApi
Returns
-
ensureSafeUrl( url, allowedProtocols ) → string
internalmodule:link/utils~ensureSafeUrl
Returns a safe URL based on a given value.
A URL is considered safe if it is safe for the user (does not contain any malicious code).
If a URL is considered unsafe, a simple
"#"
is returned.Parameters
url : unknown
allowedProtocols : Array<string>
-
Defaults to
DEFAULT_LINK_PROTOCOLS
Returns
string
-
extractTextFromLinkRange( range ) → undefined | string
module:link/utils~extractTextFromLinkRange
Returns a text of a link range.
If the returned value is
undefined
, the range contains elements other than text nodes.Parameters
range : ModelRange
Returns
undefined | string
-
getLocalizedDecorators( t, decorators ) → Array<NormalizedLinkDecoratorDefinition>
internalmodule:link/utils~getLocalizedDecorators
Returns the
config.link.decorators
configuration processed to respect the locale of the editor, i.e. to display the label in the correct language.Note: Only the few most commonly used labels are translated automatically. Other labels should be manually translated in the
config.link.decorators
configuration.Parameters
t : LocaleTranslate
Shorthand for Locale#t.
decorators : Array<NormalizedLinkDecoratorDefinition>
The decorator reference where the label values should be localized.
Returns
-
isEmail( value ) → boolean
internalmodule:link/utils~isEmail
Returns
true
if the specifiedvalue
is an email.Parameters
value : string
Returns
boolean
-
isLinkElement( node ) → boolean
module:link/utils~isLinkElement
Returns
true
if a given view node is the link element.Parameters
node : ViewNode | ViewDocumentFragment
Returns
boolean
-
isLinkableElement( element, schema ) → element is ModelElement
module:link/utils~isLinkableElement
Returns
true
if the specifiedelement
can be linked (the element allows thelinkHref
attribute).Parameters
element : null | ModelElement
schema : ModelSchema
Returns
element is ModelElement
-
linkHasProtocol( link ) → boolean
internalmodule:link/utils~linkHasProtocol
Checks if protocol is already included in the link.
Parameters
link : string
Returns
boolean
-
normalizeDecorators( [ decorators ] ) → Array<NormalizedLinkDecoratorDefinition>
internalmodule:link/utils~normalizeDecorators
Converts an object with defined decorators to a normalized array of decorators. The
id
key is added for each decorator and is used as the attribute's name in the model.Parameters
[ decorators ] : Record<string, LinkDecoratorDefinition>
Returns
-
openLink( link ) → void
module:link/utils~openLink
Opens the link in a new browser tab.
Parameters
link : string
Returns
void