From a86b59e908a7cd771c9d616a25b3c99d73f7c10c Mon Sep 17 00:00:00 2001 From: Jon Spriggs Date: Tue, 30 Jun 2020 10:20:00 +0100 Subject: [PATCH] Improvements to allow Markdown based slides * Remove "wp_texturize" by default * Add a new markdown field per-slide, separate from the data attribute field * Markdown should be edited in a textarea, not a wp_editor --- presenter.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/presenter.php b/presenter.php index e9fccfd..b166c91 100644 --- a/presenter.php +++ b/presenter.php @@ -56,6 +56,7 @@ protected function _init() { /** * Add filters and actions */ + add_filter( 'run_wptexturize', '__return_false' ); add_action( 'plugins_loaded', array( $this, 'upgrade_check' ) ); add_action( 'after_setup_theme', array( $this, 'after_setup_theme' ) ); add_filter( 'single_template', array( $this, 'single_template' ) ); @@ -292,6 +293,9 @@ private function _get_html_from_slides( $slides ) { } $data_attributes = ''; + if ( $slide->markdown ) { + $data_attributes .= ' data-markdown'; + } if ( ! empty( $slide->data ) ) { foreach ( $slide->data as $data ) { $data_attributes .= sprintf( ' data-%1$s="%2$s"', esc_attr( $data->name ), esc_attr( $data->value ) ); @@ -333,6 +337,11 @@ private function _get_slides_from_post_data() { } } $slide->title = $slide_title; + if ( array_key_exists( 'slide-markdown', $_POST ) && array_key_exists( $num, $_POST['slide-markdown'] ) ) { + $slide->markdown = isset( $_POST['slide-markdown'][$num] )? (bool) $_POST['slide-notes'][$num] : false; + } else { + $slide->markdown = false; + } $slides[] = $slide; } @@ -470,6 +479,7 @@ public function slides_meta_box( $post ) { 'markdown' => false ); $slide->title = 'New Slide'; + $slide->markdown = false; array_unshift( $slides, $slide ); foreach ( $slides as $slide ) { @@ -487,6 +497,9 @@ public function slides_meta_box( $post ) { ); } ?> + if ( ! isset( $slide->markdown ) ) { + $slide->markdown = false; + }
number}"?>">

title ) ?> @@ -509,8 +522,8 @@ public function slides_meta_box( $post ) {

number ) { - printf( '', $slide->number, esc_attr( $slide->index_name ) ); + if ( '__i__' == $slide->number || $slide->markdown ) { + printf( '', $slide->number, esc_attr( $slide->index_name ), "100%", $slide->content ); } else { wp_editor( $slide->content, "slide-content-{$slide->number}", array( 'textarea_name' => 'slide-content[' . esc_attr( $slide->index_name ) . ']', @@ -525,6 +538,7 @@ public function slides_meta_box( $post ) { } ?>
+ markdown, true, true ) ?> />