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

57 lines 2.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 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 }),
19 })}
20 data-code-block-pro-font-family={attributes.fontFamily}
21 style={
22 {
23 fontSize: maybeClamp(
24 attributes.fontSize,
25 attributes.clampFonts,
26 ),
27 // Tiny check to avoid block invalidation error
28 fontFamily: fontFamilyLong(attributes.fontFamily),
29 '--cbp-line-number-color': attributes?.lineNumbers
30 ? attributes.textColor
31 : undefined,
32 '--cbp-line-number-start':
33 Number(attributes?.startingLineNumber) > 1
34 ? attributes.startingLineNumber
35 : undefined,
36 '--cbp-line-number-width': attributes.lineNumbersWidth
37 ? `${attributes.lineNumbersWidth}px`
38 : undefined,
39 lineHeight: maybeClamp(
40 attributes.lineHeight,
41 attributes.clampFonts,
42 ),
43 } as React.CSSProperties
44 }>
45 {attributes.code?.length > 0 ? (
46 <>
47 <HeaderType {...attributes} />
48 {attributes.copyButton && (
49 <CopyButton attributes={attributes} />
50 )}
51 <RichText.Content value={attributes.codeHTML} />
52 <FooterType {...attributes} />
53 </>
54 ) : null}
55 </div>
56 );
57