datocms-html-to-structured-text
Version:
Convert HTML (or a `hast` syntax tree) to a valid DatoCMS Structured Text `dast` document
36 lines • 1.35 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;
};
/* eslint-disable @typescript-eslint/no-explicit-any */
import { findAll } from 'unist-utils-core';
export default function preprocessGoogleDocs(tree) {
// Remove Google docs <b> tags.
// Inline styles are already handled by the extractInlineStyles handler in handlers.ts
findAll(tree, isGoogleDocsNode);
}
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