Ah, missed that you talked about highlighting in documents. My solution won’t help there. It’s not unusual to have problems with the highlighting in documents, it’s a very rough method.
Actually, you don’t need a specific filter hook for modifying highlighted content. The highlighting is added with the_content
on priority 11, so you can add your own function on a later priority that cleans out the unwanted highlights. That’s one solution.
For another solution, I’ll add this filter:
$content = apply_filters( 'relevanssi_clean_excerpt', $content, $start_emp_token, $end_emp_token );
It’ll be added in relevanssi_highlight_terms()
, before these lines:
$content = str_replace( $start_emp_token, $start_emp, $content );
$content = str_replace( $end_emp_token, $end_emp, $content );
$content = str_replace( $end_emp . $start_emp, '', $content );
It’ll allow you to modify the highlight marker tokens before they are converted into whatever tags your chosen highlighting method uses. The tokens look like this: **{}[
and ]}**
, but since they may change at some point, the actual tokens are passed as parameters.
This is probably the cleanest way to remove unwanted highlights. Slightly before those lines in excerpts-highlights.php there’s some code that cleans out highlights from inside tags.
Actually, now that I look at it, the easiest solution is actually even easier. Relevanssi already cleans out highlights from inside script
, style
, object
and embed
tags. I’ll just add pre
and code
to that list. That should solve your problem here as well.
That’s a simple change, you can try it out now. Just replace this:
if ( preg_match_all( '/<(style|script|object|embed)>.*<\/(style|script|object|embed)>/U', $content, $matches ) > 0 ) {
with this:
if ( preg_match_all( '/<(style|script|object|embed|pre|code)>.*<\/(style|script|object|embed|pre|code)>/U', $content, $matches ) > 0 ) {
in excerpts-highlights.php. Does that solve your problem?