Skip to content

Commit 934ef86

Browse files
authored
Merge pull request #261 from pfefferle/hashtags-protect-tags
2 parents dbaddd9 + 32f5bec commit 934ef86

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

includes/class-hashtag.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,22 @@ public static function insert_post( $id, $data ) {
4343
* @return string the filtered post-content
4444
*/
4545
public static function the_content( $the_content ) {
46+
$protected_tags = array();
47+
$the_content = preg_replace_callback(
48+
'#<[^>]+>#i',
49+
function( $m ) use ( &$protected_tags ) {
50+
$c = count( $protected_tags );
51+
$protect = '!#!#PROTECT' . $c . '#!#!';
52+
$protected_tags[ $protect ] = $m[0];
53+
return $protect;
54+
},
55+
$the_content
56+
);
57+
4658
$the_content = \preg_replace_callback( '/' . ACTIVITYPUB_HASHTAGS_REGEXP . '/i', array( '\Activitypub\Hashtag', 'replace_with_links' ), $the_content );
4759

60+
$the_content = str_replace( array_keys( $protected_tags ), array_values( $protected_tags ), $the_content );
61+
4862
return $the_content;
4963
}
5064

0 commit comments

Comments
 (0)