@wordpress/blocks
Version:
Block API for WordPress.
24 lines (23 loc) • 781 B
JavaScript
// packages/blocks/src/api/parser/serialize-raw-block.js
import { getCommentDelimitedContent } from "../serializer";
function serializeRawBlock(rawBlock, options = {}) {
const { isCommentDelimited = true } = options;
const {
blockName,
attrs = {},
innerBlocks = [],
innerContent = []
} = rawBlock;
let childIndex = 0;
const content = innerContent.map(
(item) => (
// `null` denotes a nested block, otherwise we have an HTML fragment.
item !== null ? item : serializeRawBlock(innerBlocks[childIndex++], options)
)
).join("\n").replace(/\n+/g, "\n").trim();
return isCommentDelimited ? getCommentDelimitedContent(blockName, attrs, content) : content;
}
export {
serializeRawBlock
};
//# sourceMappingURL=serialize-raw-block.js.map