1 | import { createElement } from "@wordpress/element";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | import { __ } from '@wordpress/i18n';
|
7 | import { createBlock } from '@wordpress/blocks';
|
8 | import { Path, SVG } from '@wordpress/components';
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | import edit from './edit';
|
14 | export var name = 'core/code';
|
15 | export var settings = {
|
16 | title: __('Code'),
|
17 | description: __('Display code snippets that respect your spacing and tabs.'),
|
18 | icon: createElement(SVG, {
|
19 | viewBox: "0 0 24 24",
|
20 | xmlns: "http://www.w3.org/2000/svg"
|
21 | }, createElement(Path, {
|
22 | d: "M0,0h24v24H0V0z",
|
23 | fill: "none"
|
24 | }), createElement(Path, {
|
25 | d: "M9.4,16.6L4.8,12l4.6-4.6L8,6l-6,6l6,6L9.4,16.6z M14.6,16.6l4.6-4.6l-4.6-4.6L16,6l6,6l-6,6L14.6,16.6z"
|
26 | })),
|
27 | category: 'formatting',
|
28 | attributes: {
|
29 | content: {
|
30 | type: 'string',
|
31 | source: 'text',
|
32 | selector: 'code'
|
33 | }
|
34 | },
|
35 | supports: {
|
36 | html: false
|
37 | },
|
38 | transforms: {
|
39 | from: [{
|
40 | type: 'enter',
|
41 | regExp: /^```$/,
|
42 | transform: function transform() {
|
43 | return createBlock('core/code');
|
44 | }
|
45 | }, {
|
46 | type: 'raw',
|
47 | isMatch: function isMatch(node) {
|
48 | return node.nodeName === 'PRE' && node.children.length === 1 && node.firstChild.nodeName === 'CODE';
|
49 | },
|
50 | schema: {
|
51 | pre: {
|
52 | children: {
|
53 | code: {
|
54 | children: {
|
55 | '#text': {}
|
56 | }
|
57 | }
|
58 | }
|
59 | }
|
60 | }
|
61 | }]
|
62 | },
|
63 | edit: edit,
|
64 | save: function save(_ref) {
|
65 | var attributes = _ref.attributes;
|
66 | return createElement("pre", null, createElement("code", null, attributes.content));
|
67 | }
|
68 | };
|
69 |
|
\ | No newline at end of file |