(
node: any,
parentColor: string = theme.default,
)
| 96 | let keyCounter = 0; |
| 97 | |
| 98 | function processNode( |
| 99 | node: any, |
| 100 | parentColor: string = theme.default, |
| 101 | ): React.ReactNode { |
| 102 | if (node.type === "text") { |
| 103 | const text = node.value; |
| 104 | if (text) { |
| 105 | return React.createElement( |
| 106 | Text, |
| 107 | { |
| 108 | key: `text-${keyCounter++}`, |
| 109 | color: parentColor, |
| 110 | }, |
| 111 | text, |
| 112 | ); |
| 113 | } |
| 114 | return null; |
| 115 | } |
| 116 | |
| 117 | if (node.type === "element") { |
| 118 | const className = node.properties?.className || []; |
| 119 | |
| 120 | // Extract token type from class names |
| 121 | let tokenType = ""; |
| 122 | for (const cls of className) { |
| 123 | if (tokenColorMap[cls]) { |
| 124 | tokenType = cls; |
| 125 | break; |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | // Get color from theme |
| 130 | const colorKey = tokenColorMap[tokenType] || "default"; |
| 131 | const color = theme[colorKey]; |
| 132 | |
| 133 | if (node.children && node.children.length > 0) { |
| 134 | // Process child nodes with this color |
| 135 | const children: React.ReactNode[] = []; |
| 136 | for (let i = 0; i < node.children.length; i++) { |
| 137 | const child = processNode(node.children[i], color); |
| 138 | if (!child) continue; |
| 139 | |
| 140 | if (Array.isArray(child)) { |
| 141 | children.push(...child); |
| 142 | } else { |
| 143 | children.push(child); |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | return children; |
| 148 | } |
| 149 | |
| 150 | const textContent = getTextContent(node); |
| 151 | if (textContent) { |
| 152 | return React.createElement( |
| 153 | Text, |
| 154 | { |
| 155 | key: `element-${keyCounter++}`, |
no test coverage detected