PluginProbe
Code Block Pro – Beautiful Syntax Highlighting / 1.27.5
Code Block Pro – Beautiful Syntax Highlighting v1.27.5
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 / editor / transforms.ts

transforms.ts in Code Block Pro – Beautiful Syntax Highlighting 1.27.5, at src/editor/transforms.ts

25 lines 868 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { createBlock } from '@wordpress/blocks';
2 import { escapeHTML } from '@wordpress/escape-html';
3 import blockConfig from '../block.json';
4 import { Attributes, Lang } from '../types';
5 import { getMainAlias } from '../util/languages';
6
7 // eslint-disable-next-line @typescript-eslint/no-explicit-any
8 export const transformToCBP = (attrs: any) => {
9 const { content, language } = attrs;
10 const decode = (value: string) => {
11 const txt = document.createElement('textarea');
12 txt.innerHTML = value;
13 return txt.value;
14 };
15 return createBlock(blockConfig.name, {
16 code: content ? escapeHTML(decode(content)) : undefined,
17 language: getMainAlias(language) as Lang,
18 });
19 };
20
21 export const transformFromCBP = (attrs: Attributes) => {
22 const { code: content } = attrs;
23 return createBlock('core/code', { content });
24 };
25