Skip to content

Commit

Permalink
New Filters: syntax_highlighting_code_block_transient_key and syntax_…
Browse files Browse the repository at this point in the history
…highlighting_code_block_injected_markup

New filter: `syntax_highlighting_code_block_transient_key` - This is for filtering the language param that's returned. See: westonruter#191
New filter: `syntax_highlighting_code_block_injected_markup` - This is for being able to modify the output before its returned. This is to help those who want to extend the markup or introduce their own.
  • Loading branch information
ronaldhuereca committed Oct 7, 2023
1 parent 5c1869b commit d1a63ed
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion inc/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,18 @@ function render_block( array $attributes, string $content ): string {

// Use the previously-highlighted content if cached.
$transient_key = ! DEVELOPMENT_MODE ? get_transient_key( $matches['content'], $attributes, is_feed(), $auto_detect_languages ) : null;

/**
* Filters the transient key used to cache the highlighted content.
*
* @param string|null $transient_key Transient key.
* @param array $attributes Block attributes. See constant ATTRIBUTE_SCHEMA.
*
* @since 1.4.1
*/
$transient_key = apply_filters( 'syntax_highlighting_code_block_transient_key', $transient_key, $attributes );


$highlighted = $transient_key ? get_transient( $transient_key ) : null;
if (
is_array( $highlighted )
Expand All @@ -672,7 +684,21 @@ function render_block( array $attributes, string $content ): string {
&&
isset( $highlighted['attributes']['wrapLines'] ) && is_bool( $highlighted['attributes']['wrapLines'] )
) {
return inject_markup( $matches['pre_start_tag'], $matches['code_start_tag'], $highlighted['attributes'], $highlighted['content'] );
// Get injected markup, set up for filter.
$injected_markup = inject_markup( $matches['pre_start_tag'], $matches['code_start_tag'], $highlighted['attributes'], $highlighted['content'] );

/**
* Filter the injected markup before it's returned.
*
* @param string $injected_markup Injected markup.
* @param array $attributes Block attributes. See constant ATTRIBUTE_SCHEMA.
* @param string $content Block's original content.
*
* @since 1.4.1
*/
$injected_markup = apply_filters( 'syntax_highlighting_code_block_injected_markup', $injected_markup, $attributes, $content );

return $injected_markup;
}

try {
Expand Down

0 comments on commit d1a63ed

Please sign in to comment.