Ckeditor5: How to put linkHref into create('link')

Created on 11 Sep 2019  路  4Comments  路  Source: ckeditor/ckeditor5

Hello I cannot reach to add an href different than the value.

this.editor.execute( 'link', 'link name', { linkHref: 'http://google.com' } );

true is all the time set.
Can you help ?
thanks

link question

Most helpful comment

For this case, it'd be better to use a writer:

const linkText = 'text';
const linkUrl = 'https://google.com';

editor.model.change( writer => {
    const insertPosition = editor.model.document.selection.getFirstPosition();
    writer.insertText( linkText, { linkHref: linkUrl }, insertPosition );
} );

All 4 comments

Hi, if you'd like to create a link, use the following syntax:

const linkCommand = editor.commands.get( 'link' );

linkCommand.execute( 'http://google.com', {
    linkIsExternal: true
} );

You'll find more information here.

Thank's for the answer, what i don't get it's how to have a text different than the href

exemple get <a href="http://google.com">google</a>

For this case, it'd be better to use a writer:

const linkText = 'text';
const linkUrl = 'https://google.com';

editor.model.change( writer => {
    const insertPosition = editor.model.document.selection.getFirstPosition();
    writer.insertText( linkText, { linkHref: linkUrl }, insertPosition );
} );

Perfect thank's alot

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jodator picture jodator  路  3Comments

pomek picture pomek  路  3Comments

Reinmar picture Reinmar  路  3Comments

MCMicS picture MCMicS  路  3Comments

pjasiun picture pjasiun  路  3Comments