Skip to content

Instantly share code, notes, and snippets.

@bsweger
Last active August 22, 2024 16:25
Show Gist options
  • Save bsweger/177aa1b3214636862350 to your computer and use it in GitHub Desktop.
Save bsweger/177aa1b3214636862350 to your computer and use it in GitHub Desktop.
Convert markdown table rows to html (we converted some markdown tables to html so we could use the "scope" attribute in the header rows for accessibility).
#tabedata.txt is a file that contains the piped markdown table rows
with open ('markdownrows.txt') as f:
content = f.readlines()
rows = []
for c in content:
cells = c.split('|')
cells = ['<td>{}</td>'.format(cell.strip()) for cell in cells]
rows.append(cells)
#htmltable.txt contains the html table rows
file = open('htmlrows.txt', 'w+')
for r in rows:
file.write('<tr>\n')
for c in r:
file.write(' {}\n'.format(c))
file.write('</tr>\n')
file.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment