| 1 |
<?php |
| 2 |
|
| 3 |
namespace Code_Snippets\Utils; |
| 4 |
|
| 5 |
use const Code_Snippets\PLUGIN_FILE; |
| 6 |
use const Code_Snippets\PLUGIN_VERSION; |
| 7 |
|
| 8 |
/** |
| 9 |
* This class handles the integration of the PrismJS syntax highlighter. |
| 10 |
* |
| 11 |
* @package Code_Snippets |
| 12 |
*/ |
| 13 |
class Code_Highlighter { |
| 14 |
|
| 15 |
/** |
| 16 |
* Handle to use for the PrismJS library. |
| 17 |
*/ |
| 18 |
public const PRISM_HANDLE = 'code-snippets-prism'; |
| 19 |
|
| 20 |
/** |
| 21 |
* Enqueue the styles and scripts for the Prism syntax highlighter. |
| 22 |
* |
| 23 |
* @return void |
| 24 |
*/ |
| 25 |
public static function register_prism_assets() { |
| 26 |
wp_register_script( |
| 27 |
self::PRISM_HANDLE, |
| 28 |
plugins_url( 'dist/prism.js', PLUGIN_FILE ), |
| 29 |
[], |
| 30 |
PLUGIN_VERSION, |
| 31 |
[ 'in_footer' => true ] |
| 32 |
); |
| 33 |
|
| 34 |
wp_register_style( |
| 35 |
self::PRISM_HANDLE, |
| 36 |
plugins_url( 'dist/prism.css', PLUGIN_FILE ), |
| 37 |
[], |
| 38 |
PLUGIN_VERSION |
| 39 |
); |
| 40 |
} |
| 41 |
|
| 42 |
|
| 43 |
/** |
| 44 |
* Enqueue all available Prism themes. |
| 45 |
* |
| 46 |
* @return void |
| 47 |
*/ |
| 48 |
public static function enqueue_all_prism_themes() { |
| 49 |
self::register_prism_assets(); |
| 50 |
|
| 51 |
wp_enqueue_style( self::PRISM_HANDLE ); |
| 52 |
wp_enqueue_script( self::PRISM_HANDLE ); |
| 53 |
} |
| 54 |
} |
| 55 |
|