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

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