From 32f5bec23ae7a4289568c5df0c8be8084d252db7 Mon Sep 17 00:00:00 2001 From: Alex Kirk Date: Fri, 27 Jan 2023 12:13:41 +0100 Subject: [PATCH] Protect tags from being broken --- includes/class-hashtag.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/includes/class-hashtag.php b/includes/class-hashtag.php index 356cdb9..2b7fa54 100644 --- a/includes/class-hashtag.php +++ b/includes/class-hashtag.php @@ -43,8 +43,22 @@ class Hashtag { * @return string the filtered post-content */ public static function the_content( $the_content ) { + $protected_tags = array(); + $the_content = preg_replace_callback( + '#<[^>]+>#i', + function( $m ) use ( &$protected_tags ) { + $c = count( $protected_tags ); + $protect = '!#!#PROTECT' . $c . '#!#!'; + $protected_tags[ $protect ] = $m[0]; + return $protect; + }, + $the_content + ); + $the_content = \preg_replace_callback( '/' . ACTIVITYPUB_HASHTAGS_REGEXP . '/i', array( '\Activitypub\Hashtag', 'replace_with_links' ), $the_content ); + $the_content = str_replace( array_keys( $protected_tags ), array_values( $protected_tags ), $the_content ); + return $the_content; }