2020-06-02 17:29:02 +00:00
|
|
|
export const escapeHtml = (unsafe = '') => {
|
|
|
|
return unsafe
|
|
|
|
.replace(/&/g, '&')
|
|
|
|
.replace(/</g, '<')
|
|
|
|
.replace(/>/g, '>')
|
|
|
|
.replace(/"/g, '"')
|
|
|
|
.replace(/'/g, ''');
|
|
|
|
};
|
2022-05-16 05:59:05 +00:00
|
|
|
|
|
|
|
export const afterSanitizeAttributes = currentNode => {
|
|
|
|
if ('target' in currentNode) {
|
|
|
|
currentNode.setAttribute('target', '_blank');
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
export const domPurifyConfig = {
|
|
|
|
hooks: {
|
|
|
|
afterSanitizeAttributes,
|
|
|
|
},
|
|
|
|
};
|