/
githubmirror
/
gutenberg
Обзор
Документация
Войти
/
githubmirror
/
gutenberg
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
trunk
packages/block-library/src/code/transforms.js
74 строки
2 KB
Marco Ciampini
ESLint: Replace strict config with bulk suppressions (#81248)
07 авг 2026, 14:34
Не верифицирован
07 авг 2026, 14:34
7f43eaf
Код
Авторство
О чём код?
import { createBlock, getBlockContent } from '@wordpress/blocks'; import { create, toHTMLString } from '@wordpress/rich-text'; import { getTransformedAttributes } from '../utils/get-transformed-attributes'; 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' ), // The HTML is plain text (with plain line breaks), so // convert it to rich text. 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 default transforms;