WYSYWIG - only replace links with <a> if they are NOT already in a tag
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
a338347486
commit
c300b7cfea
@ -84,8 +84,16 @@ export class WysiwygComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public get displayContents() {
|
public get displayContents() {
|
||||||
return (this.contents || 'Double-click to edit...').replace(/</g, '\n<')
|
return this.replaceLinks((this.contents || 'Double-click to edit...').replace(/</g, '\n<'));
|
||||||
.replace(/(https?:\/\/[^\s]+)/g, (val) => `<a href="${val}" target="_blank">${val}</a>`);
|
}
|
||||||
|
|
||||||
|
private replaceLinks(text) {
|
||||||
|
const exp = /((href|src)=["']|)(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
|
||||||
|
return text.replace(exp, (...args) => {
|
||||||
|
return args[2] ?
|
||||||
|
args[0] :
|
||||||
|
'<a href="' + args[3] + '" target="_blank">' + args[3] + '</a>';
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
|
Loading…
Reference in New Issue
Block a user