This repository was archived by the owner on Feb 25, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclass-markdown-block.php
More file actions
70 lines (64 loc) · 1.77 KB
/
class-markdown-block.php
File metadata and controls
70 lines (64 loc) · 1.77 KB
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
<?php
/**
* Name: Markdown Block
* Plugin URI: https://github.com/emrikol/Markdown-Block
* Description: A markdown block for the Gutenberg editor. Requires Jetpack and the Jetpack Markdown module enabled.
* Version: 1.1
* Author: Derrick Tennant
* Author URI: https://github.com/emrikol/Markdown-Block
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
* GitHub Plugin URI: https://github.com/emrikol/markdown-block/
* Text Domain: markdown-block
*
* @package WordPress
*/
/**
* Main Class for the Markdown Block
*/
class Markdown_Block {
/**
* Registers the markdown-block Block Type.
*
* @access public
* @return void
*/
public static function register_block_types() {
register_block_type(
'mdblock/markdown-block', array(
'render_callback' => array( 'Markdown_Block', 'render_markdown' ),
'attributes' => array( 'content' => array( 'type' => 'string' ) ),
)
);
}
/**
* Enqueues Block JS and CSS assets.
*
* @access public
* @return void
*/
public static function enqueue_block_editor_assets() {
wp_enqueue_script(
'markdown-block',
plugins_url( 'assets/js/markdown-block.js', __FILE__ ),
array( 'wp-blocks', 'wp-element' )
);
wp_enqueue_style(
'markdown-block',
plugins_url( 'assets/css/markdown-block.css', __FILE__ ),
array()
);
}
/**
* Filters the post content to Markdown-ify the block contents.
*
* @param string $content The post content.
* @access public
* @return string
*/
public static function render_markdown( $attributes ) {
$wpcom_markdown = WPCom_Markdown::get_instance();
$mdown = $wpcom_markdown->transform( $attributes['content'], array( 'unslash' => false ) );
return '<div class="wp-block-mdblock-markdown-block">' . wpautop( $mdown ) . '</div>';
}
}