UNPKG

contentful-rich-text-html-parser

Version:
43 lines 1.55 kB
import { BLOCKS, } from "@contentful/rich-text-types"; import { isNodeTypeBlock, isNodeTypeInline, isNodeTypeText, isNodeTypeTopLevelBlock, } from "./utils.js"; export const processConvertedNodesFromTopLevel = (node, options) => { if (isNodeTypeBlock(node)) { if (isNodeTypeTopLevelBlock(node)) { return node; } // Block types that can not be at the top level are: BLOCKS.DOCUMENT | BLOCKS.LIST_ITEM | BLOCKS.TABLE_ROW | BLOCKS.TABLE_CELL | BLOCKS.TABLE_HEADER_CELL if (node.nodeType === BLOCKS.DOCUMENT) { return null; } // TODO: Handle top level list items and table elements return node; } if (isNodeTypeInline(node)) { if (options.postProcessing.handleTopLevelInlines === "remove") { return null; } if (options.postProcessing.handleTopLevelInlines === "wrap-paragraph") { return { nodeType: BLOCKS.PARAGRAPH, data: {}, content: [node], }; } return node; } if (isNodeTypeText(node)) { if (options.postProcessing.handleTopLevelText === "remove") { return null; } if (options.postProcessing.handleTopLevelText === "wrap-paragraph") { return { nodeType: BLOCKS.PARAGRAPH, data: {}, content: [node], }; } return node; } return null; }; //# sourceMappingURL=processConvertedNodesFromTopLevel.js.map