]*>.*?\1\s*>#is', '', $text );
$text = self::replace( '##s', '', $text );
// Links: keep the URL when it differs from the link text.
$linked = preg_replace_callback(
'#]*?href\s*=\s*(["\'])(.*?)\1[^>]*>(.*?)#is',
static function ( $m ) {
$href = html_entity_decode( trim( $m[2] ), ENT_QUOTES | ENT_HTML5, 'UTF-8' );
$label = trim( wp_strip_all_tags( $m[3] ) );
$label = html_entity_decode( $label, ENT_QUOTES | ENT_HTML5, 'UTF-8' );
if ( '' === $href || 0 === stripos( $href, 'javascript:' ) || 0 === strpos( $href, '#' ) ) {
return $label;
}
if ( 0 === stripos( $href, 'mailto:' ) ) {
$address = substr( $href, 7 );
return ( '' === $label || $label === $address ) ? $address : $label . ' (' . $address . ')';
}
if ( '' === $label || rtrim( $label, '/' ) === rtrim( $href, '/' ) ) {
return $href;
}
return $label . ' (' . $href . ')';
},
$text
);
$text = null === $linked ? $text : $linked;
// Images: keep meaningful alt text.
$text = self::replace( '#]*?alt\s*=\s*(["\'])(.+?)\1[^>]*>#is', '[$2]', $text );
// Block structure to line breaks.
$text = self::replace( '#
#i', "\n", $text );
$text = self::replace( '#