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

This commit is contained in:
Garrett Mills 2021-02-02 09:11:59 -06:00
parent a338347486
commit c300b7cfea
Signed by: garrettmills
GPG Key ID: D2BF5FBA8298F246

View File

@ -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(