Skip to content

Instantly share code, notes, and snippets.

@Rajinsharwar
Created May 21, 2024 21:18
Show Gist options
  • Save Rajinsharwar/ac18218c356c2fc69ccf90e7c05dea01 to your computer and use it in GitHub Desktop.
Save Rajinsharwar/ac18218c356c2fc69ccf90e7c05dea01 to your computer and use it in GitHub Desktop.
Convert TSV to MD for Docusaures
def generate_mdx_table(input_file):
with open(input_file, 'r', encoding='utf-8') as file:
lines = file.readlines()
headers = [header.strip() for header in lines[0].split('\t')]
rows = [row.split('\t') for row in lines[1:]]
mdx_table = "| " + " | ".join(headers) + " |\n"
mdx_table += "| " + " | ".join(["-" * len(header) for header in headers]) + " |\n"
for row in rows:
mdx_table += "| " + " | ".join(row) + " |\n"
return mdx_table
if __name__ == "__main__":
input_file = "input.tsv"
mdx_output = generate_mdx_table(input_file)
print(mdx_output)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment