PluginProbe
Code Block Pro – Beautiful Syntax Highlighting / 1.25.0
Code Block Pro – Beautiful Syntax Highlighting v1.25.0
1.27.1 1.27.2 1.27.3 1.27.4 1.27.5 1.27.6 1.27.7 1.28.0 1.3.0 1.4.0 1.5.0 1.5.1 1.5.2 1.6.0 1.7.0 1.8.0 1.9.0 1.9.1 1.9.2 1.9.3 trunk 1.1.0 1.10.0 1.11.0 1.11.1 All 63 releases
code-block-pro / src / index.tsx

index.tsx in Code Block Pro – Beautiful Syntax Highlighting 1.25.0, at src/index.tsx

99 lines 3.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { registerBlockType } from '@wordpress/blocks';
2 import { addFilter } from '@wordpress/hooks';
3 import { __ } from '@wordpress/i18n';
4 import { Editor } from './Editor';
5 import blockConfig from './block.json';
6 import { BlockFilter } from './editor/components/BlockFilter';
7 import './editor/editor.css';
8 import { transformToCBP, transformFromCBP } from './editor/transforms';
9 import { BlockOutput } from './front/BlockOutput';
10 import { blockIcon } from './icons';
11 import { Attributes } from './types';
12
13 registerBlockType<Attributes>(blockConfig.name, {
14 ...blockConfig,
15 icon: blockIcon,
16 // Types seem to be mismatched if importing these from block.json
17 attributes: {
18 code: { type: 'string' },
19 codeHTML: { type: 'string' },
20 language: { type: 'string' },
21 theme: { type: 'string' },
22 align: { type: 'string' },
23 bgColor: { type: 'string', default: '#282a37' },
24 textColor: { type: 'string', default: '#f8f8f2' },
25 fontSize: { type: 'string' },
26 fontFamily: { type: 'string' },
27 lineHeight: { type: 'string' },
28 clampFonts: { type: 'boolean' },
29 editorHeight: { type: 'string' },
30 lineNumbers: { type: 'boolean' },
31 headerType: { type: 'string' },
32 headerString: { type: 'string' },
33 disablePadding: { type: 'boolean' },
34 footerType: { type: 'string' },
35 footerString: { type: 'string' },
36 footerLink: { type: 'string' },
37 footerLinkTarget: { type: 'boolean' },
38 enableMaxHeight: { type: 'boolean' },
39 seeMoreType: { type: 'string' },
40 seeMoreString: { type: 'string' },
41 seeMoreAfterLine: { type: 'string' },
42 seeMoreTransition: { type: 'boolean' },
43 startingLineNumber: { type: 'string' },
44 lineNumbersWidth: { type: 'number' },
45 highestLineNumber: { type: 'number' },
46 enableHighlighting: { type: 'boolean' },
47 highlightingHover: { type: 'boolean' },
48 lineHighlights: { type: 'string' },
49 lineHighlightColor: { type: 'string' },
50 enableBlurring: { type: 'boolean' },
51 lineBlurs: { type: 'string' },
52 removeBlurOnHover: { type: 'boolean' },
53 frame: { type: 'boolean' },
54 renderType: { type: 'string', default: 'code' },
55 label: { type: 'string', default: '' },
56 copyButton: { type: 'boolean' },
57 copyButtonType: { type: 'string' },
58 useDecodeURI: { type: 'boolean', default: false },
59 tabSize: { type: 'number', default: 2 },
60 useTabs: { type: 'boolean' },
61 },
62 // Need to add these here to avoid TS type errors
63 supports: {
64 html: false,
65 align: ['wide', 'full'],
66 },
67 title: __('Code Pro', 'code-block-pro'),
68 edit: ({ attributes, setAttributes }) => (
69 <Editor attributes={attributes} setAttributes={setAttributes} />
70 ),
71 save: ({ attributes }) => <BlockOutput attributes={attributes} />,
72 transforms: {
73 from: [
74 {
75 type: 'block',
76 blocks: ['core/code', 'syntaxhighlighter/code'],
77 transform: transformToCBP,
78 },
79 ],
80 to: [
81 {
82 type: 'block',
83 blocks: ['core/code'],
84 transform: transformFromCBP,
85 },
86 ],
87 },
88 });
89
90 addFilter(
91 'editor.BlockEdit',
92 blockConfig.name,
93 (CurrentMenuItems) =>
94 // Not sure how to type these incoming props
95 // eslint-disable-next-line
96 (props: any) =>
97 BlockFilter(CurrentMenuItems, props),
98 );
99