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

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