datocms-html-to-structured-text
Version:
Convert HTML (or a `hast` syntax tree) to a valid DatoCMS Structured Text `dast` document
39 lines • 1.48 kB
JavaScript
;
var __spreadArrays = (this && this.__spreadArrays) || function () {
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
for (var r = Array(s), k = 0, i = 0; i < il; i++)
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
r[k] = a[j];
return r;
};
Object.defineProperty(exports, "__esModule", { value: true });
/* eslint-disable @typescript-eslint/no-explicit-any */
var unist_utils_core_1 = require("unist-utils-core");
function preprocessGoogleDocs(tree) {
// Remove Google docs <b> tags.
// Inline styles are already handled by the extractInlineStyles handler in handlers.ts
unist_utils_core_1.findAll(tree, isGoogleDocsNode);
}
exports.default = preprocessGoogleDocs;
function isGoogleDocsNode(node, index, parent) {
var _a;
var isGDocsNode = node.type === 'element' &&
node.tagName === 'b' &&
typeof node.properties === 'object' &&
typeof node.properties.id === 'string' &&
node.properties.id.startsWith('docs-internal-guid-');
if (isGDocsNode) {
if ('children' in parent &&
'children' in node &&
parent.children &&
node.children) {
// Remove google docs tag.
(_a = parent.children).splice.apply(_a, __spreadArrays([index, 1], node.children));
}
return true;
}
else {
return false;
}
}
//# sourceMappingURL=google-docs.js.map