Highlight
Keyword highlighting: splits the content into plain text and hit segments by keyword (splitByKeywords); hit segments render as <mark class="lh-highlight__mark">. Case-insensitive matching (by default), longest match for overlapping keywords, and regex metacharacter escaping (keywords treated as literals) are all pure logic in @lh-ui/share/core/highlight, with zero visual divergence. When nothing hits, the root node gets the lh-highlight--plain modifier.
Basic Usage
<script setup lang="ts">
import { LhHighlight } from '@lh-ui/vue3'
const content = 'lh-ui is a cross-platform component library family with a two-bloodline architecture and eight repositories'
</script>
<template>
<LhHighlight :content="content" keywords="cross-platform" />
<LhHighlight :content="content" :keywords="['two bloodlines', 'eight repositories']" />
</template>Case sensitivity
By default matching is case-insensitive (hit text is output as-is); with caseSensitive on, only exact matches hit:
Content truncation
When maxLength > 0, the content is truncated first (appending …) and then split, so the ellipsis position is stable and does not drift with keyword distribution:
Custom hit-segment styling
highlightClass / highlightStyle pass through to every mark:
Scoped slot
The highlight slot receives { keyword, index, segment } for custom hit-segment rendering (replacing the default mark text):
<LhHighlight :content="content" keywords="cross-platform">
<template #highlight="{ keyword, index, segment }">
<b>{{ index }}: {{ keyword }} ({{ segment.text }})</b>
</template>
</LhHighlight>API
Highlight Props
| Prop | Description | Type | Default |
|---|---|---|---|
| content | Text content (required) | string | — |
| keywords | Highlight keywords (one or many; the longest match wins at the same position when overlapping) | string | string[] | — |
| caseSensitive | Case sensitive (case-insensitive matching by default) | boolean | false |
| highlightClass | Class name appended to the mark | string | — |
| highlightStyle | Inline style string for the mark | string | — |
| maxLength | Max content length (>0 truncates and appends …, then splits) | number | — |
| highlightLabel | Accessible name (falls back to a 40-character summary of the content when not passed) | string | — |
| sx | sx quick-layout props | LhSxProps | — |
Highlight Slots
| Slot | Description | Scoped props |
|---|---|---|
| highlight | Custom hit-segment rendering (replaces the default mark text) | { keyword: string, index: number, segment: LhHighlightSegment } |
Accessibility
The root node's aria-label comes from highlightLabel or a 40-character summary of the content; hit segments are semantic <mark> elements.

