@wordpress/block-library
Version:
Block library for the WordPress editor.
103 lines (95 loc) • 2.22 kB
JavaScript
/**
* WordPress dependencies
*/
import { createBlock } from '@wordpress/blocks';
import { create, join, toHTMLString } from '@wordpress/rich-text';
const transforms = {
from: [{
type: 'block',
isMultiBlock: true,
blocks: ['core/paragraph'],
transform: attributes => {
return createBlock('core/pullquote', {
value: toHTMLString({
value: join(attributes.map(_ref => {
let {
content
} = _ref;
return create({
html: content
});
}), '\n')
}),
anchor: attributes.anchor
});
}
}, {
type: 'block',
blocks: ['core/heading'],
transform: _ref2 => {
let {
content,
anchor
} = _ref2;
return createBlock('core/pullquote', {
value: content,
anchor
});
}
}],
to: [{
type: 'block',
blocks: ['core/paragraph'],
transform: _ref3 => {
let {
value,
citation
} = _ref3;
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: _ref4 => {
let {
value,
citation
} = _ref4;
// If there is no pullquote content, use the citation as the
// content of the resulting heading. A nonexistent citation
// will result in an empty heading.
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 default transforms;
//# sourceMappingURL=transforms.js.map