MCPcopy Create free account
hub / github.com/AcademySoftwareFoundation/MaterialX / parseMarkdownTable

Function parseMarkdownTable

python/Scripts/comparenodedefs.py:340–375  ·  view source on GitHub ↗

Parse a markdown table. Returns (rows, columnMismatchCount, endIndex).

(lines, startIdx)

Source from the content-addressed store, hash-verified

338# -----------------------------------------------------------------------------
339
340def parseMarkdownTable(lines, startIdx):
341 '''Parse a markdown table. Returns (rows, columnMismatchCount, endIndex).'''
342 table = []
343 headers = []
344 columnMismatchCount = 0
345 idx = startIdx
346
347 # Parse header row
348 if idx < len(lines) and '|' in lines[idx]:
349 headerLine = lines[idx].strip()
350 headers = [h.strip().strip('`') for h in headerLine.split('|')[1:-1]]
351 idx += 1
352 else:
353 return [], 0, startIdx
354
355 # Skip separator row
356 if idx < len(lines) and '|' in lines[idx] and '-' in lines[idx]:
357 idx += 1
358 else:
359 return [], 0, startIdx
360
361 # Parse data rows
362 while idx < len(lines):
363 line = lines[idx].strip()
364 if not line or not line.startswith('|'):
365 break
366
367 cells = [c.strip().strip('`') for c in line.split('|')[1:-1]]
368 if len(cells) == len(headers):
369 row = {headers[i].lower(): cells[i] for i in range(len(headers))}
370 table.append(row)
371 else:
372 columnMismatchCount += 1
373 idx += 1
374
375 return table, columnMismatchCount, idx
376
377
378# -----------------------------------------------------------------------------

Callers 1

parseSpecDocumentFunction · 0.85

Calls 3

lenFunction · 0.85
rangeFunction · 0.85
appendMethod · 0.45

Tested by

no test coverage detected