automator_markdown_parser_options
Filter markdown parsing options. Allows modification of how markdown content is processed and converted to HTML. Filters markdown parsing options to customize how markdown content is processed and converted to HTML.
add_filter( 'automator_markdown_parser_options', $callback, 10, 2 );
Description
This filter hook, automator_markdown_parser_options, fires within the Markdown parsing process. Developers can modify the $options array to customize how markdown content is converted to HTML. This provides granular control over formatting rules and processing behaviors, allowing for tailored markdown rendering within the WordPress environment.
Usage
add_filter( 'automator_markdown_parser_options', 'your_function_name', 10, 2 );
Parameters
-
$options(array) - Formatting options array
-
$content(string) - The original markdown content
Return Value
array Modified formatting options
Examples
<?php
/**
* Example: Modify markdown parsing options to disable a specific feature.
*
* This function hooks into the 'automator_markdown_parser_options' filter
* to demonstrate how to modify the parsing options passed to the markdown parser.
* In this example, we'll disable the parsing of inline HTML.
*
* @param array $options The original formatting options array.
* @param string $content The original markdown content.
* @return array Modified formatting options.
*/
function my_automator_disable_inline_html_in_markdown( $options, $content ) {
// Check if the 'html_input' option exists and is enabled, then disable it.
// The specific key ('html_input') might vary depending on the markdown parser
// implementation used by AutomatorWP, so adjust if necessary.
if ( isset( $options['html_input'] ) && $options['html_input'] === true ) {
$options['html_input'] = false;
}
// You could also add new options or modify existing ones based on $content.
// For example, if the content contains a specific tag, you might alter options.
if ( strpos( $content, '[special_shortcode]' ) !== false ) {
// Let's say we want to enable GitHub-flavored markdown for this specific content.
$options['flavor'] = 'gfm';
}
return $options;
}
// Add the filter to WordPress.
// The third parameter '2' indicates that our callback function accepts two arguments:
// $options and $content.
add_filter( 'automator_markdown_parser_options', 'my_automator_disable_inline_html_in_markdown', 10, 2 );
?>
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:40
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;
}