This method creates a link in the selected text or if the cursor is collapsed. You can use properties such as:
const $link = app.link.create( url: 'https://example.com' );
This method updates the properties of the links selected in the text.
app.link.update( url: 'https://example.com' );
app.link.update( target: '_blank' );
app.link.update( target: null );
const $links = app.link.get();
$links.each($link => {
$link.text('New text');
});
const $link = app.link.update({ text: '' });
const caret = app.create('caret');
caret.set($link, 'start');
This method returns an array with the Dom elements of all links in the selected text.
const $links = app.link.get();
const $link = app.link.get().first();
$link.addClass('link-classname');
const $links = app.link.get();
if ($links.length) {
// some action
}
const $link = app.link.get().first();
const selection = app.create('selection');
selection.select($link);
const $links = app.link.get();
$links.addClass('link-classname');
const $links = app.link.get();
const urls = $links.map($link => $link.attr('href'));
const $links = app.link.get();
const hasDataAttr = $links.some(link => link.attr('data-id'));
if (hasDataAttr) {
console.log('Has links with data-id');
}
This method removes links in the selected content, keeping only the link text.
this.app.link.unlink();
const $links = app.link.get();
$links.filter('.link-classname').each(link => {
app.link.unlink(link);
});