API REFERENCE · RICH TEXT PLUGINS
@dojo-ng/rich-text-autolink
Automatic links for <dj-rich-text>: URLs and email addresses become links as you type.
npm install @dojo-ng/rich-text-autolink
Compose the autolink plugin with the default set; typing a URL or email followed by a space (or any boundary) links it. Add the links plugin too for manual link editing.
<dj-rich-text id="editor" label="Article"></dj-rich-text>
<script type="module">
import "@dojo-ng/rich-text";
import { defaultPlugins } from "@dojo-ng/rich-text";
import { autolinkPlugin } from "@dojo-ng/rich-text-autolink";
document.getElementById("editor").plugins = [...defaultPlugins, autolinkPlugin];
</script>
How it works
- A text transform finds URLs and email addresses as you type and wraps them in links.
- Editing the text so it no longer matches removes the link; editing it to a different URL updates the address. Links you made by hand are never changed.
www.addresses gethttps://, and plain email addresses getmailto:.
Setup
- Exports
autolinkPlugin,createAutoLinkPlugin({ matchers? }), anddefaultMatchers. - A matcher is
{ regex, url(matched) }. The regex must not be global, and the earliest match wins. - It also registers the link node, so exported
<a>elements import again throughvalueeven withoutrich-text-links. Loading both is fine. - Pair it with
rich-text-linksfor editing links by hand. - Setting
pluginsreplaces the default set, so spread...defaultPluginsto keep bold, italic, underline, undo, and redo.
Not built
- URLs split across formatting, removing an automatic link from a toolbar, and opening a link by clicking it in the editor.
Need one of these? Make a request on Discord or add an issue (work item) on Heptapod.
Functions
createAutoLinkPlugin
function createAutoLinkPlugin(options?: AutoLinkPluginOptions): RichTextPlugin;
Values
autolinkPlugin
const autolinkPlugin: RichTextPlugin;
defaultMatchers
const defaultMatchers: AutoLinkMatcher[];
Types
AutoLinkMatcher
interface AutoLinkMatcher {
regex: RegExp;
url(matched: string): string;
}
AutoLinkPluginOptions
interface AutoLinkPluginOptions {
matchers?: AutoLinkMatcher[];
}