@wordpress/block-library
Version:
Block library for the WordPress editor.
48 lines (47 loc) • 1.52 kB
JavaScript
import { createBlock } from "@wordpress/blocks";
import { create, join, toHTMLString } from "@wordpress/rich-text";
// packages/block-library/src/pullquote/transforms.js
const transforms = {
from: [{
type: "block",
isMultiBlock: true,
blocks: ["core/paragraph"],
transform: (attributes) => {
return createBlock("core/pullquote", {
value: toHTMLString({ value: join(attributes.map(({ content }) => create({ html: content })), "\n") }),
anchor: attributes.anchor
});
}
}, {
type: "block",
blocks: ["core/heading"],
transform: ({ content, anchor }) => {
return createBlock("core/pullquote", {
value: content,
anchor
});
}
}],
to: [{
type: "block",
blocks: ["core/paragraph"],
transform: ({ value, citation }) => {
const paragraphs = [];
if (value) paragraphs.push(createBlock("core/paragraph", { content: value }));
if (citation) paragraphs.push(createBlock("core/paragraph", { content: citation }));
if (paragraphs.length === 0) return createBlock("core/paragraph", { content: "" });
return paragraphs;
}
}, {
type: "block",
blocks: ["core/heading"],
transform: ({ value, citation }) => {
if (!value) return createBlock("core/heading", { content: citation });
const headingBlock = createBlock("core/heading", { content: value });
if (!citation) return headingBlock;
return [headingBlock, createBlock("core/heading", { content: citation })];
}
}]
};
export { transforms as default };
//# sourceMappingURL=transforms.mjs.map