vcinema/markdown_utils/MarkdownUtils.py

36 lines
734 B
Python

def generate_markdown_link(text, url):
return "[{}]({})".format(text, url)
class MarkdownTable:
headers = []
rows = []
def __init__(self, headers):
self.headers = headers
def add_row(self, row_data):
if len(row_data) != len(self.headers):
raise Exception("Wrong number of row entries.")
else:
self.rows.append(row_data)
def __str__(self):
table = "|"
for header in self.headers:
table += " {} |".format(header)
table += "\n"
table += "|"
table += " - |" * len(self.headers)
for row in self.rows:
table += "\n"
table += " | ".join(map(str, row))
return table