WYSYWIG - only replace links with <a> if they are NOT already in a tag
continuous-integration/drone/push Build is passing Details

master
Garrett Mills 3 years ago
parent a338347486
commit c300b7cfea
Signed by: garrettmills
GPG Key ID: D2BF5FBA8298F246

@ -84,8 +84,16 @@ export class WysiwygComponent implements OnInit {
}
public get displayContents() {
return (this.contents || 'Double-click to edit...').replace(/</g, '\n<')
.replace(/(https?:\/\/[^\s]+)/g, (val) => `<a href="${val}" target="_blank">${val}</a>`);
return this.replaceLinks((this.contents || 'Double-click to edit...').replace(/</g, '\n<'));
}
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(

Loading…
Cancel
Save