Mark
A thin inline-flow primitive — reach for it instead of Badge/Code when you need to highlight a substring inside flowing text without breaking baseline alignment or vertical rhythm.
Renders the native <mark> element so assistive tech announces the content as highlighted. Falls back to system Mark/MarkText colours under forced-colors.
import { Mark, Text } from '@arshad-shah/cynosure-react';
export default function Example() {
return (
<Text>
The quick brown <Mark>fox</Mark> jumps over the lazy dog.
</Text>
);
}
Variants
Section titled “Variants”Four visual treatments. marker (default) paints a soft highlighter-pen background; underline lays a thick rule under the text; chip flows a pill inline; bold colours and bolds the text with no decoration.
import { Mark, Stack, Text } from '@arshad-shah/cynosure-react';
export default function Example() {
return (
<Stack gap="2">
<Text>
marker — the <Mark variant="marker">highlighted</Mark> phrase.
</Text>
<Text>
underline — the <Mark variant="underline">highlighted</Mark> phrase.
</Text>
<Text>
chip — the <Mark variant="chip">highlighted</Mark> phrase.
</Text>
<Text>
bold — the <Mark variant="bold">highlighted</Mark> phrase.
</Text>
</Stack>
);
}
Color schemes
Section titled “Color schemes”Six token palettes: accent, success, warning (default), danger, info, neutral. All track light/dark themes automatically — no hand-rolled CSS variables required.
import { Mark, Text } from '@arshad-shah/cynosure-react';
export default function Example() {
return (
<Text>
<Mark colorScheme="accent">accent</Mark>, <Mark colorScheme="success">success</Mark>,{' '}
<Mark colorScheme="warning">warning</Mark>, <Mark colorScheme="danger">danger</Mark>,{' '}
<Mark colorScheme="info">info</Mark>, <Mark colorScheme="neutral">neutral</Mark>.
</Text>
);
}
Intensities
Section titled “Intensities”subtle (default) uses the soft surface token; solid switches to the saturated solid + on-solid pair for stronger emphasis.
import { Mark, Stack, Text } from '@arshad-shah/cynosure-react';
export default function Example() {
return (
<Stack gap="2">
<Text>
subtle <Mark intensity="subtle">amber</Mark> / solid <Mark intensity="solid">amber</Mark>
</Text>
<Text>
subtle{' '}
<Mark colorScheme="danger" intensity="subtle">
red
</Mark>{' '}
/ solid{' '}
<Mark colorScheme="danger" intensity="solid">
red
</Mark>
</Text>
</Stack>
);
}
Wraps across lines
Section titled “Wraps across lines”Mark sets box-decoration-break: clone so the background, padding, and corner radius repaint on each wrapped line. No bookkeeping required.
import { Box, Mark, Text } from '@arshad-shah/cynosure-react';
export default function Example() {
return (
<Box maxWidth="320px">
<Text>
Cynosure exposes a <Mark>thin inline-flow primitive that wraps text in a styled mark</Mark>{' '}
— the highlight wraps with each line, with padding and rounded corners painted on every
line.
</Text>
</Box>
);
}
HighlightedText
Section titled “HighlightedText”For the common “highlight these ranges inside this string” case, HighlightedText takes a text plus an array of { start, length } (or { start, end }) ranges and renders them as Mark spans interleaved with the surrounding text. Overlapping ranges are merged; out-of-range indices are clamped; empty ranges are dropped.
import { HighlightedText, Text } from '@arshad-shah/cynosure-react';
const text = 'the quick brown fox jumps over the lazy dog';
const pattern = /\bthe\b|quick|lazy/gi;
function findRanges(source: string, re: RegExp) {
const out: { start: number; length: number }[] = [];
for (const m of source.matchAll(re)) {
if (m.index != null) out.push({ start: m.index, length: m[0].length });
}
return out;
}
export default function Example() {
return (
<Text>
<HighlightedText text={text} ranges={findRanges(text, pattern)} />
</Text>
);
}
import { HighlightedText } from '@arshad-shah/cynosure-react';
<HighlightedText text={input} ranges={matches.map((m) => ({ start: m.index, length: m[0].length }))} variant="marker" colorScheme="warning"/>HighlightedText
Section titled “HighlightedText”Accessibility
Section titled “Accessibility”- Renders a native
<mark>by default — assistive tech announces the content as highlighted. Passas="span"when the highlight is purely decorative and the surrounding context already conveys meaning. - Pair colour with copy: never rely on the highlight alone to communicate meaning (e.g. “deprecated” highlights should still include a textual indicator).
- Pass a
titlefor the common tooltip case (title="Match #3"). - Under
forced-colors(Windows High Contrast and similar)Markfalls back to the systemMark/MarkTextcolour pair so highlights stay visible when the token palette is overridden.
Recipes
Section titled “Recipes”- Search hits — feed regex match ranges into
HighlightedTextto highlight every occurrence in a snippet. - Diff hunks —
variant="chip"withcolorScheme="success"/colorScheme="danger"reads as add/remove without needing a full diff viewer. - Form validation — point at the invalid slice of an input with
variant="underline"andcolorScheme="danger"; surface atitlefor the rule that fired. - Inline syntax —
variant="bold"colours keywords/numbers in a one-liner without dragging in a syntax-highlighting dependency.