namespace BookStack\Entities\Tools;
+use BookStack\Actions\Tag;
use BookStack\Entities\Models\Entity;
use Illuminate\Support\HtmlString;
$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);
+ }
+ }
+ }
}
/**
<div class="tag-item primary-background-light" data-name="{{ $tag->name }}" data-value="{{ $tag->value }}">
@if($linked ?? true)
- <div class="tag-name"><a href="{{ $tag->nameUrl() }}">@icon('tag'){{ $tag->name }}</a></div>
- @if($tag->value) <div class="tag-value"><a href="{{ $tag->valueUrl() }}">{{$tag->value}}</a></div> @endif
+ <div class="tag-name {{ $tag->highlight_name ? 'highlight' : '' }}"><a href="{{ $tag->nameUrl() }}">@icon('tag'){{ $tag->name }}</a></div>
+ @if($tag->value) <div class="tag-value {{ $tag->highlight_value ? 'highlight' : '' }}"><a href="{{ $tag->valueUrl() }}">{{$tag->value}}</a></div> @endif
@else
- <div class="tag-name"><span>@icon('tag'){{ $tag->name }}</span></div>
- @if($tag->value) <div class="tag-value"><span>{{$tag->value}}</span></div> @endif
+ <div class="tag-name {{ $tag->highlight_name ? 'highlight' : '' }}"><span>@icon('tag'){{ $tag->name }}</span></div>
+ @if($tag->value) <div class="tag-value {{ $tag->highlight_value ? 'highlight' : '' }}"><span>{{$tag->value}}</span></div> @endif
@endif
</div>
\ No newline at end of file