MCPcopy Create free account
hub / github.com/TailGrids/tailgrids / splitTextWithHighlight

Function splitTextWithHighlight

apps/docs/src/components/code-block.tsx:47–78  ·  view source on GitHub ↗
(
  value: string,
  pattern: RegExp,
  bgColor: string
)

Source from the content-addressed store, hash-verified

45}
46
47function splitTextWithHighlight(
48 value: string,
49 pattern: RegExp,
50 bgColor: string
51): rendererNode[] {
52 const out: rendererNode[] = [];
53 let lastIndex = 0;
54 for (const m of value.matchAll(pattern)) {
55 const start = m.index ?? 0;
56 if (start > lastIndex) {
57 out.push({ type: "text", value: value.slice(lastIndex, start) });
58 }
59 out.push({
60 type: "element",
61 tagName: "span",
62 properties: {
63 style: {
64 backgroundColor: bgColor,
65 borderRadius: 2,
66 paddingInline: 4
67 },
68 className: ["inline-highlight"]
69 },
70 children: [{ type: "text", value: m[0] }]
71 });
72 lastIndex = start + m[0].length;
73 }
74 if (lastIndex < value.length) {
75 out.push({ type: "text", value: value.slice(lastIndex) });
76 }
77 return out;
78}
79
80function rewriteNode(
81 node: rendererNode,

Callers 1

rewriteNodeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected