PluginProbe
Code Block Pro – Beautiful Syntax Highlighting / 1.22.0
Code Block Pro – Beautiful Syntax Highlighting v1.22.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 / front / BlockOutput.tsx

BlockOutput.tsx in Code Block Pro – Beautiful Syntax Highlighting 1.22.0, at src/front/BlockOutput.tsx

97 lines 4.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { RichText, useBlockProps as blockProps } from '@wordpress/block-editor';
2 import { applyFilters } from '@wordpress/hooks';
3 import classNames from 'classnames';
4 import defaultThemes from '../defaultThemes.json';
5 import { FooterType } from '../editor/components/FooterSelect';
6 import { HeaderType } from '../editor/components/HeaderSelect';
7 import { SeeMoreType } from '../editor/components/SeeMoreSelect';
8 import { ButtonList } from '../editor/components/buttons/ButtonList';
9 import { Attributes, ThemeOption } from '../types';
10 import { findLineNumberColor } from '../util/colors';
11 import { fontFamilyLong, maybeClamp } from '../util/fonts';
12 import './style.css';
13
14 export const BlockOutput = ({ attributes }: { attributes: Attributes }) => {
15 // To add custom styles
16 const themes = applyFilters(
17 'blocks.codeBlockPro.themes',
18 defaultThemes,
19 ) as ThemeOption;
20 const styles = themes[attributes.theme]?.styles;
21 return (
22 <div
23 {...blockProps.save({
24 className: classNames({
25 'padding-disabled': attributes.disablePadding,
26 'padding-bottom-disabled':
27 attributes?.footerType &&
28 attributes?.footerType !== 'none',
29 'cbp-has-line-numbers': attributes.lineNumbers,
30 'cbp-blur-enabled': attributes.enableBlurring,
31 'cbp-unblur-on-hover': attributes.removeBlurOnHover,
32 'cbp-highlight-hover': attributes.highlightingHover,
33 }),
34 })}
35 data-code-block-pro-font-family={attributes.fontFamily}
36 style={
37 {
38 fontSize: maybeClamp(
39 attributes.fontSize,
40 attributes.clampFonts,
41 ),
42 // Tiny check to avoid block invalidation error
43 fontFamily: fontFamilyLong(attributes.fontFamily),
44 '--cbp-line-number-color': attributes?.lineNumbers
45 ? findLineNumberColor(attributes)
46 : undefined,
47 '--cbp-line-number-start':
48 Number(attributes?.startingLineNumber) > 1
49 ? attributes.startingLineNumber
50 : undefined,
51 '--cbp-line-number-width': attributes.lineNumbersWidth
52 ? `${attributes.lineNumbersWidth}px`
53 : undefined,
54 '--cbp-line-highlight-color':
55 attributes?.enableHighlighting ||
56 attributes?.highlightingHover
57 ? attributes.lineHighlightColor
58 : undefined,
59 lineHeight: maybeClamp(
60 attributes.lineHeight,
61 attributes.clampFonts,
62 ),
63 '--cbp-tab-width':
64 attributes.useTabs === undefined
65 ? undefined // bw compatibility
66 : String(attributes.tabSize),
67 tabSize:
68 attributes.useTabs === undefined
69 ? undefined // bw compatibility
70 : 'var(--cbp-tab-width, 2)',
71 ...Object.entries(styles ?? {}).reduce(
72 (acc, [key, value]) => ({
73 ...acc,
74 [`--shiki-${key}`]: value,
75 }),
76 {},
77 ),
78 ...(applyFilters(
79 'blocks.codeBlockPro.additionalOutputAttributes',
80 {},
81 attributes,
82 ) as object),
83 } as React.CSSProperties
84 }>
85 {attributes.code?.length > 0 ? (
86 <>
87 <HeaderType {...attributes} />
88 <ButtonList {...attributes} />
89 <RichText.Content value={attributes.codeHTML} />
90 <FooterType {...attributes} />
91 <SeeMoreType {...attributes} />
92 </>
93 ) : null}
94 </div>
95 );
96 };
97