Skip to content

Highlight ​

Keyword highlighting: the content is split into plain text and hit segments by keywords (splitByKeywords: case normalization, longest match, non-overlapping scan); hit segments render as lh-highlight__mark. Serves search-result summaries, log keyword annotation and similar scenarios.

Platform differences (registered): no platform specialization on this port — splitting, hit math and the accessibility label all reuse share-core pure functions; the view renders Segment[] as a text loop (uni-app inline text nodes), and the mark visuals come from the share style source.

Basic usage ​

vue
<template>
  <lh-highlight content="lh-ui 是一个跨端组件库家族" keywords="跨端" />
  <lh-highlight content="LH-UI 跨端组件库,lh-ui 家族" keywords="lh-ui" />
</template>

Multiple keywords and case sensitivity ​

keywords accepts an array of strings; when several keywords match at the same position the longest wins. caseSensitive defaults to false (case-normalized matching, the hit text is emitted as-is):

vue
<lh-highlight
  content="lh-ui 跨端组件库家族,双血脉架构,八仓齐发"
  :keywords="['lh-ui', '跨端组件库', '组件库']"
/>
<lh-highlight content="LH-UI 跨端组件库,lh-ui 家族" keywords="lh-ui" case-sensitive />

Content truncation and custom highlight styles ​

When maxLength > 0 the content is truncated and suffixed with … before splitting (stable ellipsis position); highlightClass / highlightStyle are forwarded to the hit mark:

vue
<lh-highlight
  content="lh-ui 是一个跨端组件库家族,双血脉架构,八仓齐发"
  keywords="双血脉"
  :max-length="20"
/>
<lh-highlight
  content="自定义类名与内联样式"
  keywords="自定义"
  highlight-class="my-highlight"
  highlight-style="color: #B87800; text-decoration: underline;"
/>

Props ​

PropDescriptionTypeDefault
contentText content (required)string—
keywordsKeywords (string or array; empty strings are ignored)string | string[]—
caseSensitiveCase sensitive (false matches case-normalized)booleanfalse
highlightClassExtra class appended to the hit markstring—
highlightStyleInline style string for the hit markstring—
maxLengthMax content length (>0 truncates and appends … before splitting)number—
highlightLabelAccessibility label (falls back to a 40-char content summary)string—
customClassCustom class (forwarded to the root node)string—
sxsx quick layout propsLhSxProps—

Accessibility ​

The root aria-label defaults to a 40-char content summary and can be customized with highlightLabel; when nothing matches, the root gets the lh-highlight--plain modifier so consumers can tell the "no hit" state apart.