link/utils
Constants
LINK_KEYSTROKE : 'Ctrl+K'module:link/utils~LINK_KEYSTROKEA keystroke used by the link UI feature.
Type Definitions
module:link/utils~NormalizedLinkDecoratorAutomaticDefinitionmodule:link/utils~NormalizedLinkDecoratorDefinitionmodule:link/utils~NormalizedLinkDecoratorManualDefinition
Functions
addLinkProtocolIfApplicable( link, [ defaultProtocol ] ) → stringmodule:link/utils~addLinkProtocolIfApplicableAdds the protocol prefix to the specified
linkwhen:- it does not contain it already, and there is a
defaultProtocolconfiguration 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 ) → ViewAttributeElementmodule:link/utils~createLinkElementCreates a link
ViewAttributeElementwith the providedhrefattribute.Parameters
href : string__namedParameters : DowncastConversionApi
Returns
ensureSafeUrl( url, allowedProtocols ) → stringinternalmodule:link/utils~ensureSafeUrlReturns 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 : unknownallowedProtocols : Array<string>Defaults to
DEFAULT_LINK_PROTOCOLS
Returns
string
extractTextFromLinkRange( range ) → undefined | stringmodule:link/utils~extractTextFromLinkRangeReturns 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~getLocalizedDecoratorsReturns the
config.link.decoratorsconfiguration 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.decoratorsconfiguration.Parameters
t : LocaleTranslateShorthand for Locale#t.
decorators : Array<NormalizedLinkDecoratorDefinition>The decorator reference where the label values should be localized.
Returns
isEmail( value ) → booleaninternalmodule:link/utils~isEmailReturns
trueif the specifiedvalueis an email.Parameters
value : string
Returns
boolean
isLinkElement( node ) → booleanmodule:link/utils~isLinkElementReturns
trueif a given view node is the link element.Parameters
node : ViewNode | ViewDocumentFragment
Returns
boolean
isLinkableElement( element, schema ) → element is ModelElementmodule:link/utils~isLinkableElementReturns
trueif the specifiedelementcan be linked (the element allows thelinkHrefattribute).Parameters
element : null | ModelElementschema : ModelSchema
Returns
element is ModelElement
linkHasProtocol( link ) → booleaninternalmodule:link/utils~linkHasProtocolChecks if protocol is already included in the link.
Parameters
link : string
Returns
boolean
normalizeDecorators( [ decorators ] ) → Array<NormalizedLinkDecoratorDefinition>internalmodule:link/utils~normalizeDecoratorsConverts an object with defined decorators to a normalized array of decorators. The
idkey is added for each decorator and is used as the attribute's name in the model.Parameters
[ decorators ] : Record<string, LinkDecoratorDefinition>
Returns
openLink( link ) → voidmodule:link/utils~openLinkOpens the link in a new browser tab.
Parameters
link : string
Returns
void