@contentstack/utils
Advanced tools
Comparing version 1.3.16 to 1.3.17
@@ -159,2 +159,4 @@ 'use strict'; | ||
if (allowedAttributes === void 0) { allowedAttributes = ['href', 'title', 'target', 'alt', 'src', 'class', 'id', 'style', 'colspan', 'rowspan', 'content-type-uid', 'data-sys-asset-uid', 'sys-style-type', 'data-type', 'data-width', 'data-rows', 'data-cols']; } | ||
// Replace newline characters with <br /> before processing the HTML tags | ||
input = input.replace(/\n/g, '<br />'); | ||
// Regular expression to find and remove all HTML tags except the allowed ones | ||
@@ -928,26 +930,14 @@ var sanitized = input.replace(/<\/?([a-z][a-z0-9]*)\b[^<>]*>/gi, function (match, tag) { | ||
function updateAssetURLForGQL(gqlResponse) { | ||
var _a; | ||
try { | ||
var response = gqlResponse === null || gqlResponse === void 0 ? void 0 : gqlResponse.data; | ||
for (var contentType in response) { | ||
var entry = response[contentType]; // page_json_rte | ||
var _loop_1 = function (field) { | ||
var fieldData = entry[field]; | ||
if (fieldData && fieldData.embedded_itemsConnection) { // rte field with embedded items e.g rte_2 | ||
var edges = (_a = fieldData === null || fieldData === void 0 ? void 0 : fieldData.embedded_itemsConnection) === null || _a === void 0 ? void 0 : _a.edges; | ||
edges.forEach(function (edge) { | ||
var _a, _b, _c; | ||
var node = edge.node; | ||
if ((node === null || node === void 0 ? void 0 : node.url) && (node === null || node === void 0 ? void 0 : node.filename)) { | ||
if (!((_a = node === null || node === void 0 ? void 0 : node.system) === null || _a === void 0 ? void 0 : _a.uid)) | ||
throw new Error('Asset UID not found in the response'); | ||
var correspondingAsset = (_c = (_b = fieldData === null || fieldData === void 0 ? void 0 : fieldData.json) === null || _b === void 0 ? void 0 : _b.children) === null || _c === void 0 ? void 0 : _c.find(function (child) { return child.attrs['asset-uid'] === node.system.uid; }); | ||
correspondingAsset.attrs['asset-link'] = node.url; | ||
} | ||
}); | ||
} | ||
}; | ||
for (var field in entry) { | ||
_loop_1(field); | ||
if ("items" in response[contentType]) { | ||
var entries = response[contentType].items; | ||
entries.forEach(function (entry) { | ||
processEntry(entry); | ||
}); | ||
} | ||
else { | ||
processEntry(response[contentType]); | ||
} | ||
} | ||
@@ -959,2 +949,36 @@ } | ||
} | ||
function processEntry(entry) { | ||
var _a; | ||
var _loop_1 = function (field) { | ||
var fieldData = entry[field]; | ||
var rteField = findRTEField(fieldData); | ||
var edges = (_a = rteField === null || rteField === void 0 ? void 0 : rteField.embedded_itemsConnection) === null || _a === void 0 ? void 0 : _a.edges; | ||
edges.forEach(function (edge) { | ||
var _a, _b, _c; | ||
var node = edge.node; | ||
if ((node === null || node === void 0 ? void 0 : node.url) && (node === null || node === void 0 ? void 0 : node.filename)) { | ||
if (!((_a = node === null || node === void 0 ? void 0 : node.system) === null || _a === void 0 ? void 0 : _a.uid)) | ||
throw new Error('Asset UID not found in the response'); | ||
var correspondingAsset = (_c = (_b = rteField === null || rteField === void 0 ? void 0 : rteField.json) === null || _b === void 0 ? void 0 : _b.children) === null || _c === void 0 ? void 0 : _c.find(function (child) { return child.attrs['asset-uid'] === node.system.uid; }); | ||
correspondingAsset.attrs['asset-link'] = node.url; | ||
} | ||
}); | ||
}; | ||
for (var field in entry) { | ||
_loop_1(field); | ||
} | ||
} | ||
function findRTEField(fieldData) { | ||
if (fieldData && fieldData.embedded_itemsConnection) { | ||
return fieldData; | ||
} | ||
for (var key in fieldData) { | ||
if (fieldData[key] && typeof fieldData[key] === 'object') { | ||
var found = findRTEField(fieldData[key]); | ||
if (found) { | ||
return found; | ||
} | ||
} | ||
} | ||
} | ||
@@ -961,0 +985,0 @@ exports.Document = Document; |
export function sanitizeHTML(input, allowedTags, allowedAttributes) { | ||
if (allowedTags === void 0) { allowedTags = ['p', 'a', 'strong', 'em', 'ul', 'ol', 'li', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'sub', 'u', 'table', 'thead', 'tbody', 'tr', 'th', 'td', 'span', 'fragment', 'sup', 'strike', 'br', 'img', 'colgroup', 'col', 'div']; } | ||
if (allowedAttributes === void 0) { allowedAttributes = ['href', 'title', 'target', 'alt', 'src', 'class', 'id', 'style', 'colspan', 'rowspan', 'content-type-uid', 'data-sys-asset-uid', 'sys-style-type', 'data-type', 'data-width', 'data-rows', 'data-cols']; } | ||
// Replace newline characters with <br /> before processing the HTML tags | ||
input = input.replace(/\n/g, '<br />'); | ||
// Regular expression to find and remove all HTML tags except the allowed ones | ||
@@ -5,0 +7,0 @@ var sanitized = input.replace(/<\/?([a-z][a-z0-9]*)\b[^<>]*>/gi, function (match, tag) { |
export function updateAssetURLForGQL(gqlResponse) { | ||
var _a; | ||
try { | ||
var response = gqlResponse === null || gqlResponse === void 0 ? void 0 : gqlResponse.data; | ||
for (var contentType in response) { | ||
var entry = response[contentType]; // page_json_rte | ||
var _loop_1 = function (field) { | ||
var fieldData = entry[field]; | ||
if (fieldData && fieldData.embedded_itemsConnection) { // rte field with embedded items e.g rte_2 | ||
var edges = (_a = fieldData === null || fieldData === void 0 ? void 0 : fieldData.embedded_itemsConnection) === null || _a === void 0 ? void 0 : _a.edges; | ||
edges.forEach(function (edge) { | ||
var _a, _b, _c; | ||
var node = edge.node; | ||
if ((node === null || node === void 0 ? void 0 : node.url) && (node === null || node === void 0 ? void 0 : node.filename)) { | ||
if (!((_a = node === null || node === void 0 ? void 0 : node.system) === null || _a === void 0 ? void 0 : _a.uid)) | ||
throw new Error('Asset UID not found in the response'); | ||
var correspondingAsset = (_c = (_b = fieldData === null || fieldData === void 0 ? void 0 : fieldData.json) === null || _b === void 0 ? void 0 : _b.children) === null || _c === void 0 ? void 0 : _c.find(function (child) { return child.attrs['asset-uid'] === node.system.uid; }); | ||
correspondingAsset.attrs['asset-link'] = node.url; | ||
} | ||
}); | ||
} | ||
}; | ||
for (var field in entry) { | ||
_loop_1(field); | ||
if ("items" in response[contentType]) { | ||
var entries = response[contentType].items; | ||
entries.forEach(function (entry) { | ||
processEntry(entry); | ||
}); | ||
} | ||
else { | ||
processEntry(response[contentType]); | ||
} | ||
} | ||
@@ -32,2 +20,36 @@ } | ||
} | ||
function processEntry(entry) { | ||
var _a; | ||
var _loop_1 = function (field) { | ||
var fieldData = entry[field]; | ||
var rteField = findRTEField(fieldData); | ||
var edges = (_a = rteField === null || rteField === void 0 ? void 0 : rteField.embedded_itemsConnection) === null || _a === void 0 ? void 0 : _a.edges; | ||
edges.forEach(function (edge) { | ||
var _a, _b, _c; | ||
var node = edge.node; | ||
if ((node === null || node === void 0 ? void 0 : node.url) && (node === null || node === void 0 ? void 0 : node.filename)) { | ||
if (!((_a = node === null || node === void 0 ? void 0 : node.system) === null || _a === void 0 ? void 0 : _a.uid)) | ||
throw new Error('Asset UID not found in the response'); | ||
var correspondingAsset = (_c = (_b = rteField === null || rteField === void 0 ? void 0 : rteField.json) === null || _b === void 0 ? void 0 : _b.children) === null || _c === void 0 ? void 0 : _c.find(function (child) { return child.attrs['asset-uid'] === node.system.uid; }); | ||
correspondingAsset.attrs['asset-link'] = node.url; | ||
} | ||
}); | ||
}; | ||
for (var field in entry) { | ||
_loop_1(field); | ||
} | ||
} | ||
function findRTEField(fieldData) { | ||
if (fieldData && fieldData.embedded_itemsConnection) { | ||
return fieldData; | ||
} | ||
for (var key in fieldData) { | ||
if (fieldData[key] && typeof fieldData[key] === 'object') { | ||
var found = findRTEField(fieldData[key]); | ||
if (found) { | ||
return found; | ||
} | ||
} | ||
} | ||
} | ||
//# sourceMappingURL=updateAssetURLForGQL.js.map |
{ | ||
"name": "@contentstack/utils", | ||
"version": "1.3.16", | ||
"version": "1.3.17", | ||
"description": "Contentstack utilities for Javascript", | ||
@@ -41,3 +41,3 @@ "main": "dist/index.es.js", | ||
"@types/jest": "^26.0.24", | ||
"babel-core": "^4.7.16", | ||
"babel-core": "^6.26.3", | ||
"babel-jest": "^29.7.0", | ||
@@ -44,0 +44,0 @@ "babel-loader": "8.4.1", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
267424
2302