Skip to content
API 风格:

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 ​

Single keyword / multiple keywords highlighting
lh-ui is a cross-platform component library family with a two-bloodline architecture and eight repositories shipped together, ten docs sites in placelh-ui is a cross-platform component library family with a two-bloodline architecture and eight repositories shipped together, ten docs sites in place
vue
<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:

Case sensitive
LH-UI cross-platform component library lh-uiLH-UI cross-platform component library lh-ui

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:

maxLength truncation
lh-ui is a…

Custom hit-segment styling ​

highlightClass / highlightStyle pass through to every mark:

Class name and inline style
lh-ui is a cross-platform component library family with a two-bloodline architecture and eight repositories shipped together, ten docs sites in place

Scoped slot ​

The highlight slot receives { keyword, index, segment } for custom hit-segment rendering (replacing the default mark text):

highlight scoped slot
lh-ui is a cross-platform component library family with a two-bloodline architecture and [0]eight repositories shipped together, ten docs sites in place
vue
<LhHighlight :content="content" keywords="cross-platform">
  <template #highlight="{ keyword, index, segment }">
    <b>{{ index }}: {{ keyword }} ({{ segment.text }})</b>
  </template>
</LhHighlight>

API ​

Highlight Props ​

PropDescriptionTypeDefault
contentText content (required)string—
keywordsHighlight keywords (one or many; the longest match wins at the same position when overlapping)string | string[]—
caseSensitiveCase sensitive (case-insensitive matching by default)booleanfalse
highlightClassClass name appended to the markstring—
highlightStyleInline style string for the markstring—
maxLengthMax content length (>0 truncates and appends …, then splits)number—
highlightLabelAccessible name (falls back to a 40-character summary of the content when not passed)string—
sxsx quick-layout propsLhSxProps—

Highlight Slots ​

SlotDescriptionScoped props
highlightCustom 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.

Beauty of tradition, foundation of code