UNPKG

@wordpress/block-library

Version:
56 lines (55 loc) • 1.53 kB
import { createBlock, getBlockContent } from "@wordpress/blocks"; import { create, toHTMLString } from "@wordpress/rich-text"; import { getTransformedAttributes } from "../utils/get-transformed-attributes.mjs"; // packages/block-library/src/code/transforms.js const transforms = { from: [ { type: "input", regExp: /^```$/, transform: () => createBlock("core/code") }, { type: "block", blocks: ["core/paragraph"], transform: (attributes) => { const { content } = attributes; return createBlock("core/code", { ...attributes, ...getTransformedAttributes(attributes, "core/code"), content }); } }, { type: "block", blocks: ["core/html"], __experimentalConvert(block) { const { attributes } = block; return createBlock("core/code", { ...attributes, ...getTransformedAttributes(attributes, "core/code"), content: toHTMLString({ value: create({ text: getBlockContent(block) }) }) }); } }, { type: "raw", isMatch: (node) => node.nodeName === "PRE" && node.children.length === 1 && node.firstChild.nodeName === "CODE", schema: { pre: { children: { code: { children: { "#text": {} } } } } } } ], to: [{ type: "block", blocks: ["core/paragraph"], transform: (attributes) => { const { content } = attributes; return createBlock("core/paragraph", { ...getTransformedAttributes(attributes, "core/paragraph"), content }); } }] }; export { transforms as default }; //# sourceMappingURL=transforms.mjs.map