← All changes
|
modules/markdown-render/markdown-renderer.php
+36
-14
4.1.0-beta2
→
4.3.0-beta3
View file →
| @@ -10,30 +10,52 @@ | ||
| 10 | 10 | |
| 11 | 11 | class Markdown_Renderer { |
| 12 | 12 | |
| 13 | 13 | public function render( Document $document ): string { |
| 14 | - $frontmatter = $this->build_frontmatter( $document ); | |
| 15 | - $data = $document->get_elements_data(); | |
| 14 | + return Module::execute_while_rendering_markdown( function () use ( $document ) { | |
| 15 | + $frontmatter = $this->build_frontmatter( $document ); | |
| 16 | + $data = $document->get_elements_data(); | |
| 16 | 17 | |
| 17 | - if ( empty( $data ) ) { | |
| 18 | - return $frontmatter; | |
| 19 | - } | |
| 18 | + if ( empty( $data ) ) { | |
| 19 | + return $frontmatter; | |
| 20 | + } | |
| 20 | 21 | |
| 21 | - $sections = []; | |
| 22 | + $sections = []; | |
| 22 | 23 | |
| 23 | - foreach ( $data as $element_data ) { | |
| 24 | - $md = $this->render_element( $element_data ); | |
| 24 | + foreach ( $data as $element_data ) { | |
| 25 | + $md = $this->render_element( $element_data ); | |
| 25 | 26 | |
| 26 | - if ( ! empty( trim( $md ) ) ) { | |
| 27 | - $sections[] = $md; | |
| 27 | + if ( ! empty( trim( $md ) ) ) { | |
| 28 | + $sections[] = $md; | |
| 29 | + } | |
| 28 | 30 | } |
| 29 | - } | |
| 30 | 31 | |
| 31 | - $body = implode( "\n\n---\n\n", $sections ); | |
| 32 | + $body = implode( "\n\n---\n\n", $sections ); | |
| 32 | 33 | |
| 33 | - $output = $frontmatter . "\n\n" . $body; | |
| 34 | + $output = $frontmatter . "\n\n" . $body; | |
| 34 | 35 | |
| 35 | - return apply_filters( 'elementor/markdown/document_output', $output, $document ); | |
| 36 | + return apply_filters( 'elementor/markdown/document_output', $output, $document ); | |
| 37 | + } ); | |
| 38 | + } | |
| 39 | + | |
| 40 | + public function render_elements_data( array $elements_data ): string { | |
| 41 | + return Module::execute_while_rendering_markdown( function () use ( $elements_data ) { | |
| 42 | + if ( empty( $elements_data ) ) { | |
| 43 | + return ''; | |
| 44 | + } | |
| 45 | + | |
| 46 | + $sections = []; | |
| 47 | + | |
| 48 | + foreach ( $elements_data as $element_data ) { | |
| 49 | + $md = $this->render_element( $element_data ); | |
| 50 | + | |
| 51 | + if ( ! empty( trim( $md ) ) ) { | |
| 52 | + $sections[] = $md; | |
| 53 | + } | |
| 54 | + } | |
| 55 | + | |
| 56 | + return implode( "\n\n", $sections ); | |
| 57 | + } ); | |
| 36 | 58 | } |
| 37 | 59 | |
| 38 | 60 | private function build_frontmatter( Document $document ): string { |
| 39 | 61 | $post_id = $document->get_main_id(); |