forked from xwp/code-syntax-block
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
111 lines (99 loc) · 3.03 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
/**
* Plugin Name: Code Syntax Block
* Plugin URI: https://github.com/mkaz/code-syntax-block
* Description: A plugin to extend Gutenberg code block with syntax highlighting
* Version: 0.8.1
* Author: Marcus Kazmierczak
* Author URI: https://mkaz.blog/
* License: GPL2
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: code-syntax-block
*
* @package Code_Syntax_Block
*/
/**
* Load text domain.
*/
function mkaz_load_plugin_textdomain() {
load_plugin_textdomain( 'code-syntax-block', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
}
add_action( 'plugins_loaded', 'mkaz_load_plugin_textdomain' );
/**
* Enqueue assets for editor portion of Gutenberg
*/
function mkaz_code_syntax_editor_assets() {
// Files.
$block_path = 'code-syntax.js';
$editor_style_path = 'assets/blocks.editor.css';
// Prism Languages
wp_enqueue_script(
'mkaz-code-syntax-langs',
plugins_url( 'assets/prism-languages.js', __FILE__ ),
array(),
filemtime( plugin_dir_path( __FILE__ ) . 'assets/prism-languages.js' )
);
// Block.
wp_enqueue_script(
'mkaz-code-syntax',
plugins_url( $block_path, __FILE__ ),
array( 'wp-blocks', 'wp-editor', 'wp-element' ),
filemtime( plugin_dir_path( __FILE__ ) . $block_path )
);
}
add_action( 'enqueue_block_editor_assets', 'mkaz_code_syntax_editor_assets' );
/**
* Enqueue assets for viewing posts
*/
function mkaz_code_syntax_view_assets() {
// Files.
$view_style_path = 'assets/blocks.style.css';
$prism_js_path = 'assets/prism.js';
$prism_settings_path = 'assets/prism-settings.js';
// Syntax Highlighting colors
$prism_css_path = 'assets/prism.css';
/**
* Filter the URL of the Syntax Highlighting colors.
* Use this filter to define your own color set.
*
* @since 0.8.1
*
* @param string $prism_css_url Absolute URL of the CSS file you want to enqueue.
*/
$prism_css_url = apply_filters( 'mkaz_prism_css_url', plugins_url( $prism_css_path, __FILE__ ) );
// Enqueue view style.
wp_enqueue_style(
'mkaz-code-syntax-css',
plugins_url( $view_style_path, __FILE__ ),
array(),
filemtime( plugin_dir_path( __FILE__ ) . $view_style_path )
);
// Enqueue prism style.
wp_enqueue_style(
'mkaz-code-syntax-prism-css',
esc_url( $prism_css_url ),
array(),
filemtime( plugin_dir_path( __FILE__ ) . $prism_css_path )
);
// Enqueue prism script.
wp_enqueue_script(
'mkaz-code-syntax-prism-css',
plugins_url( $prism_js_path, __FILE__ ),
array(), // No dependencies.
filemtime( plugin_dir_path( __FILE__ ) . $prism_js_path ),
true // In footer.
);
// enqueue prism settings script
wp_enqueue_script(
'mkaz-code-syntax-prism-settings',
plugins_url( $prism_settings_path, __FILE__ ),
[], // no dependencies
filemtime( plugin_dir_path(__FILE__) . $prism_settings_path ),
true // in footer
);
// save the plugin path
wp_localize_script('mkaz-code-syntax-prism-settings', 'settings', array(
'pluginUrl' => plugin_dir_url(__FILE__),
));
}
add_action( 'wp_enqueue_scripts', 'mkaz_code_syntax_view_assets' );