diff --git a/Sources/Autolinker.php b/Sources/Autolinker.php index 66b9becdcb..ae34c80a21 100644 --- a/Sources/Autolinker.php +++ b/Sources/Autolinker.php @@ -384,7 +384,11 @@ public function detectUrls(string $string, bool $plaintext_only = false): array // An entity right after the URL can break the autolinker. $this->setEntitiesRegex(); - $string = preg_replace('~(' . $this->entities_regex . ')*(?=\s|$)~u', ' ', $string); + $string = preg_replace_callback( + '~(' . $this->entities_regex . ')*(?=\s|$)~u', + fn ($matches) => str_repeat(' ', strlen($matches[0])), + $string, + ); $this->setUrlRegex(); @@ -412,7 +416,7 @@ public function detectUrls(string $string, bool $plaintext_only = false): array // Overwrite all BBC markup elements. $string = preg_replace_callback( - '/\[[^\]]*\]/i' . ($this->encoding === 'UTF-8' ? 'u' : ''), + '~\[/?' . Parser::getBBCodeTagsRegex() . '[^\]]*\]~i' . ($this->encoding === 'UTF-8' ? 'u' : ''), fn ($matches) => str_repeat(' ', strlen($matches[0])), $string, ); @@ -786,7 +790,7 @@ public static function createJavaScriptFile(bool $force = false): void $regexes['email'] = self::load()->getJavaScriptEmailRegex(); // Don't autolink if the URL is inside a Markdown link construct. - $md_lookbehind = !empty(Config::$modSettings['enableMarkdown']) ? '(? $value) { $js[] = 'autolinker_regexes.set(' . Utils::escapeJavaScript($key) . ', new RegExp(' . Utils::escapeJavaScript($md_lookbehind . $value) . ', "giu"));'; diff --git a/Sources/Parser.php b/Sources/Parser.php index 097312d2f4..030e48bd70 100644 --- a/Sources/Parser.php +++ b/Sources/Parser.php @@ -354,6 +354,16 @@ public static function getSigTags(): array return BBcodeParser::getSigTags(); } + /** + * Gets a regular expression to match all known BBC tags. + * + * @return string Regular expression to match all BBCode tags. + */ + public static function getBBCodeTagsRegex(): string + { + return BBcodeParser::load()->getAllTagsRegex(); + } + /** * Highlight any code. * diff --git a/Themes/default/scripts/jquery.sceditor.smf.js b/Themes/default/scripts/jquery.sceditor.smf.js index befa682a1b..31d756c8e7 100644 --- a/Themes/default/scripts/jquery.sceditor.smf.js +++ b/Themes/default/scripts/jquery.sceditor.smf.js @@ -544,8 +544,8 @@ url[0] = '//' + url[0]; } - // Wrap the URL in BBC tags. - editor.insert('[' + bbc_tag + '="' + url[0] + '"]', '[/' + bbc_tag + ']'); + // Insert the URL. + editor.wysiwygEditorInsertHtml('' + url[0] + ''); } // Helper for this.signalKeydownEvent.