datocms-html-to-structured-text
Version:
Convert HTML (or a `hast` syntax tree) to a valid DatoCMS Structured Text `dast` document
20 lines • 698 B
JavaScript
import { visit, SKIP } from 'unist-util-visit';
export default function preprocessGoogleDocs(tree) {
visit(tree, 'element', (node, index, parent) => {
if (!isGoogleDocsWrapper(node) ||
!parent ||
index === undefined ||
!('children' in parent)) {
return;
}
parent.children.splice(index, 1, ...node.children);
return [SKIP, index];
});
}
function isGoogleDocsWrapper(node) {
return (node.tagName === 'b' &&
typeof node.properties === 'object' &&
typeof node.properties.id === 'string' &&
node.properties.id.startsWith('docs-internal-guid-'));
}
//# sourceMappingURL=google-docs.js.map