diff --git a/src/Support/Highlighter.php b/src/Support/Highlighter.php index da6afe7..7dcef3f 100644 --- a/src/Support/Highlighter.php +++ b/src/Support/Highlighter.php @@ -28,14 +28,15 @@ public function highlight($text, $needle, $tag = 'em', $options = []) { $this->options = array_merge($this->options, $options); - $tagAttributes = ' '; + $tagAttributes = ''; if (count($this->options['tagOptions'])) { foreach ($this->options['tagOptions'] as $attr => $value) { $tagAttributes .= $attr . '="' . $value . '" '; } + $tagAttributes = ' ' . trim($tagAttributes); } - $highlight = '<' . $tag . trim($tagAttributes) .'>\1'; + $highlight = '<' . $tag . $tagAttributes .'>\1'; $needle = preg_split('/\PL+/u', $needle, -1, PREG_SPLIT_NO_EMPTY); // Select pattern to use