I am using a Wordpress plugin that puts the code tag around text that is in backticks for highlighting purposes on my blog. Now the original function is this:
function mdc_the_content( $content ) {
$content = preg_replace( '/`(.*?)`/', '<code>$1</code>', $content );
return $content;
} // mdc_the_content
add_filter( 'the_content', 'mdc_the_content' );
When I am using js highlighter plugin (code highlighter) then it places the code tag around the code that is in backticks. I want to avoid that. Would the function below work? Only put the code tag around tags when the backticks are not wrapped in <pre class="EnlighterJSRAW" data-enlighter-language="r">$1</pre>
. Would the if statement below work? Sometimes there might be multiple objects wrapped around backticks within the highlighter. Thank you.
function mdc_the_content( $content ) {
if(!preg_match('/`(.*?)`/', '<pre class="EnlighterJSRAW" data-enlighter-language="r">$1</pre>', $content)) {
$content = preg_replace( '/`(.*?)`/', '<code>$1</code>', $content );
}
return $content;
} // mdc_the_content
add_filter( 'the_content', 'mdc_the_content' );
question from:
https://stackoverflow.com/questions/65857323/avoiding-getting-text-wrapped-around-the-code-tag-when-text-is-with-certain-tag 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…