automator_markdown_parser_html
Filter the final markdown HTML output. Allows final modifications to the processed HTML content. Filters the final markdown HTML output after processing, allowing modifications to the generated content.
add_filter( 'automator_markdown_parser_html', $callback, 10, 3 );
Description
This filter hook, `automator_markdown_parser_html`, allows developers to modify the final HTML output after markdown content has been processed. It's ideal for making last-minute adjustments, adding custom elements, or transforming the generated HTML before it's displayed. The hook passes the processed HTML, original markdown, and formatting options, providing full control over the output.
Usage
add_filter( 'automator_markdown_parser_html', 'your_function_name', 10, 3 );
Parameters
-
$formatted_content(string) - The processed HTML content
-
$content(string) - The original markdown content
-
$options(array) - The formatting options used
Return Value
string Modified HTML content
Examples
/**
* Example of using the 'automator_markdown_parser_html' filter hook.
*
* This function demonstrates how to modify the HTML output generated from markdown.
* In this specific example, we'll add a CSS class to all paragraphs for styling.
*/
add_filter( 'automator_markdown_parser_html', function( $formatted_content, $content, $options ) {
// Check if the formatted content is not empty and is a string.
if ( ! empty( $formatted_content ) && is_string( $formatted_content ) ) {
// Replace all instances of <p> with <p class="automator-markdown-paragraph">.
// This is a basic example; more complex DOM manipulation might be needed for
// advanced scenarios.
$formatted_content = str_replace( '<p>', '<p class="automator-markdown-paragraph">', $formatted_content );
}
// Always return the modified content.
return $formatted_content;
}, 10, 3 ); // Priority 10, accepts 3 arguments
Placement
This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.
Source Code
src/core/services/markdown/class-markdown-parser.php:55
public function parse( $content, $options = array() ) {
if ( empty( $content ) || ! is_string( $content ) ) {
return '';
}
$options = $this->get_default_options( $options );
/**
* Filter markdown parsing options.
*
* Allows modification of how markdown content is processed and converted to HTML.
*
* @param array $options Formatting options array
* @param string $content The original markdown content
*
* @return array Modified formatting options
*/
$options = apply_filters( 'automator_markdown_parser_options', $options, $content );
$formatted_content = $this->process_content( $content, $options );
/**
* Filter the final markdown HTML output.
*
* Allows final modifications to the processed HTML content.
*
* @param string $formatted_content The processed HTML content
* @param string $content The original markdown content
* @param array $options The formatting options used
*
* @return string Modified HTML content
*/
$formatted_content = apply_filters( 'automator_markdown_parser_html', $formatted_content, $content, $options );
return $formatted_content;
}