MCPcopy Index your code
hub / github.com/codeaashu/claude-code / squashTextNodesToSegments

Function squashTextNodesToSegments

src/ink/squash-text-nodes.ts:18–63  ·  view source on GitHub ↗
(
  node: DOMElement,
  inheritedStyles: TextStyles = {},
  inheritedHyperlink?: string,
  out: StyledSegment[] = [],
)

Source from the content-addressed store, hash-verified

16 * This allows structured styling without relying on ANSI string transforms.
17 */
18export function squashTextNodesToSegments(
19 node: DOMElement,
20 inheritedStyles: TextStyles = {},
21 inheritedHyperlink?: string,
22 out: StyledSegment[] = [],
23): StyledSegment[] {
24 const mergedStyles = node.textStyles
25 ? { ...inheritedStyles, ...node.textStyles }
26 : inheritedStyles
27
28 for (const childNode of node.childNodes) {
29 if (childNode === undefined) {
30 continue
31 }
32
33 if (childNode.nodeName === '#text') {
34 if (childNode.nodeValue.length > 0) {
35 out.push({
36 text: childNode.nodeValue,
37 styles: mergedStyles,
38 hyperlink: inheritedHyperlink,
39 })
40 }
41 } else if (
42 childNode.nodeName === 'ink-text' ||
43 childNode.nodeName === 'ink-virtual-text'
44 ) {
45 squashTextNodesToSegments(
46 childNode,
47 mergedStyles,
48 inheritedHyperlink,
49 out,
50 )
51 } else if (childNode.nodeName === 'ink-link') {
52 const href = childNode.attributes['href'] as string | undefined
53 squashTextNodesToSegments(
54 childNode,
55 mergedStyles,
56 href || inheritedHyperlink,
57 out,
58 )
59 }
60 }
61
62 return out
63}
64
65/**
66 * Squash text nodes into a plain string (without styles).

Callers 1

renderNodeToOutputFunction · 0.85

Calls 1

pushMethod · 0.45

Tested by

no test coverage detected