* Parses a markdown table and extracts values from the first column. * Handles backtick-wrapped names like `propName`. * * @param content - The full MDX file content * @param headerPattern - Regex to match the table header row * @returns Array of names extracted from the first data column
(content: string, headerPattern: RegExp)
| 219 | * @returns Array of names extracted from the first data column |
| 220 | */ |
| 221 | function parseTableColumn(content: string, headerPattern: RegExp): string[] { |
| 222 | const names: string[] = []; |
| 223 | const lines = content.split('\n'); |
| 224 | |
| 225 | for (let i = 0; i < lines.length; i++) { |
| 226 | const line = lines[i].trim(); |
| 227 | |
| 228 | // Find a table header matching the pattern |
| 229 | if (!headerPattern.test(line)) continue; |
| 230 | |
| 231 | // Skip the separator row (|---|---|...) |
| 232 | const separatorIndex = i + 1; |
| 233 | if (separatorIndex >= lines.length) break; |
| 234 | const separatorLine = lines[separatorIndex].trim(); |
| 235 | if (!separatorLine.startsWith('|') || !separatorLine.includes('---')) break; |
| 236 | |
| 237 | // Parse data rows |
| 238 | for (let j = separatorIndex + 1; j < lines.length; j++) { |
| 239 | const dataLine = lines[j].trim(); |
| 240 | if (!dataLine.startsWith('|')) break; // End of table |
| 241 | |
| 242 | const cells = dataLine |
| 243 | .split('|') |
| 244 | .map((c) => c.trim()) |
| 245 | .filter((c) => c.length > 0); |
| 246 | |
| 247 | if (cells.length > 0) { |
| 248 | // Strip backticks from the name |
| 249 | const name = cells[0].replace(/`/g, '').trim(); |
| 250 | if (name && !name.startsWith('---')) { |
| 251 | names.push(name); |
| 252 | } |
| 253 | } |
| 254 | } |
| 255 | } |
| 256 | |
| 257 | return names; |
| 258 | } |
| 259 | |
| 260 | /** |
| 261 | * Extracts documented property names from the Properties table(s) in an MDX file. |
no test coverage detected