PluginProbe
Highlighting Code Block / 1.2.4
Highlighting Code Block v1.2.4
2.2.1 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.4.0 All 41 releases
highlighting-code-block / src / js / _nouse.js

_nouse.js in Highlighting Code Block 1.2.4, at src/js/_nouse.js

51 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * Valid Blocks - 高度な設定を追加するブロックを指定
3 */
4 function isValidBlockType(blockName) {
5 const validBlocks = ['loos-hcb/code-block'];
6 return -1 !== validBlocks.indexOf(blockName);
7 }
8
9 /**
10 * Override props assigned to save component to inject our custom data.
11 * This is only done if the component is a valid block type.
12 *
13 * @param {Object} extraProps Additional props applied to save element.
14 * @param {Object} blockType Block type.
15 * @param {Object} attributes Current block attributes.
16 *
17 * @return {Object} Filtered props applied to save element.
18 */
19 function addSaveProps(extraProps, blockType, attributes) {
20 if (isValidBlockType(blockType.name)) {
21 // 「wp-block-loos-hcb-code-block」をつけない
22 extraProps.className = attributes.className;
23 }
24 return extraProps;
25 }
26 // addFilter("blocks.getSaveContent.extraProps", "loos-hcb/add-props", addSaveProps);
27
28 /**
29 * ベータ版での設定値によるバリデーション回避
30 *
31 * @param {Object} attributes Current block attributes.
32 * @param {Object} settings Current block settings.
33 * @param {Object} content Current block content.
34 */
35 function beforeValidation(attributes, settings, content) {
36 //console.log(settings.name);
37 if ('loos-hcb/code-block' === settings.name) {
38 if ('undefined' === typeof attributes.preClass) {
39 let isLineShow = attributes.isLineShow;
40 if ('undefined' === typeof isLineShow) {
41 isLineShow = 'line'; // "on" or "off"
42 }
43 const preClass =
44 'prism ' + isLineShow + '-numbers lang-' + attributes.langType;
45 attributes.preClass = preClass;
46 }
47 }
48 return attributes;
49 }
50 // addFilter("blocks.getBlockAttributes", "loos-hcb/before-validation", beforeValidation);
51