PluginProbe
Code Block Pro – Beautiful Syntax Highlighting / 1.11.0
Code Block Pro – Beautiful Syntax Highlighting v1.11.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.11.0, at src/front/BlockOutput.tsx

62 lines 2.5 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 classNames from 'classnames';
3 import { FooterType } from '../editor/components/FooterSelect';
4 import { HeaderType } from '../editor/components/HeaderSelect';
5 import { Attributes } from '../types';
6 import { fontFamilyLong, maybeClamp } from '../util/fonts';
7 import { CopyButton } from './CopyButton';
8 import './style.css';
9
10 export const BlockOutput = ({ attributes }: { attributes: Attributes }) => (
11 <div
12 {...blockProps.save({
13 className: classNames({
14 'padding-disabled': attributes.disablePadding,
15 'padding-bottom-disabled':
16 attributes?.footerType && attributes?.footerType !== 'none',
17 'cbp-has-line-numbers': attributes.lineNumbers,
18 'cbp-blur-enabled': attributes.enableBlurring,
19 'cbp-unblur-on-hover': attributes.removeBlurOnHover,
20 }),
21 })}
22 data-code-block-pro-font-family={attributes.fontFamily}
23 style={
24 {
25 fontSize: maybeClamp(
26 attributes.fontSize,
27 attributes.clampFonts,
28 ),
29 // Tiny check to avoid block invalidation error
30 fontFamily: fontFamilyLong(attributes.fontFamily),
31 '--cbp-line-number-color': attributes?.lineNumbers
32 ? attributes.textColor
33 : undefined,
34 '--cbp-line-number-start':
35 Number(attributes?.startingLineNumber) > 1
36 ? attributes.startingLineNumber
37 : undefined,
38 '--cbp-line-number-width': attributes.lineNumbersWidth
39 ? `${attributes.lineNumbersWidth}px`
40 : undefined,
41 '--cbp-line-highlight-color': attributes?.enableHighlighting
42 ? attributes.lineHighlightColor
43 : undefined,
44 lineHeight: maybeClamp(
45 attributes.lineHeight,
46 attributes.clampFonts,
47 ),
48 } as React.CSSProperties
49 }>
50 {attributes.code?.length > 0 ? (
51 <>
52 <HeaderType {...attributes} />
53 {attributes.copyButton && (
54 <CopyButton attributes={attributes} />
55 )}
56 <RichText.Content value={attributes.codeHTML} />
57 <FooterType {...attributes} />
58 </>
59 ) : null}
60 </div>
61 );
62