diff --git a/app/Entities/Tools/SearchResultsFormatter.php b/app/Entities/Tools/SearchResultsFormatter.php index 24dc820a4..1ddee5830 100644 --- a/app/Entities/Tools/SearchResultsFormatter.php +++ b/app/Entities/Tools/SearchResultsFormatter.php @@ -2,6 +2,7 @@ namespace BookStack\Entities\Tools; +use BookStack\Actions\Tag; use BookStack\Entities\Models\Entity; use Illuminate\Support\HtmlString; @@ -41,6 +42,34 @@ class SearchResultsFormatter $formatted = $this->formatTextUsingMatchPositions($mergedRefs, $content); $entity->setAttribute($attributeName, new HtmlString($formatted)); } + + $tags = $entity->relationLoaded('tags') ? $entity->tags->all() : []; + $this->highlightTagsContainingTerms($tags, $terms); + } + + /** + * Highlight tags which match the given terms. + * @param Tag[] $tags + * @param string[] $terms + */ + protected function highlightTagsContainingTerms(array $tags, array $terms): void + { + foreach ($tags as $tag) { + $tagName = strtolower($tag->name); + $tagValue = strtolower($tag->value); + + foreach ($terms as $term) { + $termLower = strtolower($term); + + if (strpos($tagName, $termLower) !== false) { + $tag->setAttribute('highlight_name', true); + } + + if (strpos($tagValue, $termLower) !== false) { + $tag->setAttribute('highlight_value', true); + } + } + } } /** diff --git a/resources/sass/_blocks.scss b/resources/sass/_blocks.scss index ef03699f1..ae3e7a441 100644 --- a/resources/sass/_blocks.scss +++ b/resources/sass/_blocks.scss @@ -262,6 +262,10 @@ } } +.tag-name.highlight, .tag-value.highlight { + font-weight: bold; +} + .tag-list div:last-child .tag-item { margin-bottom: 0; } diff --git a/resources/views/entities/tag.blade.php b/resources/views/entities/tag.blade.php index 057c70921..de4750c13 100644 --- a/resources/views/entities/tag.blade.php +++ b/resources/views/entities/tag.blade.php @@ -1,9 +1,9 @@
@if($linked ?? true) -
@icon('tag'){{ $tag->name }}
- @if($tag->value)
{{$tag->value}}
@endif +
@icon('tag'){{ $tag->name }}
+ @if($tag->value)
{{$tag->value}}
@endif @else -
@icon('tag'){{ $tag->name }}
- @if($tag->value)
{{$tag->value}}
@endif +
@icon('tag'){{ $tag->name }}
+ @if($tag->value)
{{$tag->value}}
@endif @endif
\ No newline at end of file