diff --git a/markdownify/__init__.py b/markdownify/__init__.py index 5c008d3..5fdcbf3 100644 --- a/markdownify/__init__.py +++ b/markdownify/__init__.py @@ -237,6 +237,24 @@ class MarkdownConverter(object): return '![%s](%s%s)' % (alt, src, title_part) + def convert_table(self, el, text, convert_as_inline): + rows = el.find_all('tr') + text_data = [] + for row in rows: + headers = row.find_all('th') + columns = row.find_all('td') + if len(headers) > 0: + headers = [head.text.strip() for head in headers] + headers = [head for head in headers if head] + text_data.append(' | '.join(headers)) + text_data.append(' | '.join(['---'] * len(headers))) + elif len(columns) > 0: + columns = [colm.text.strip() for colm in columns] + text_data.append(' | '.join([colm for colm in columns if colm])) + else: + continue + return '\n'.join(text_data) + def markdownify(html, **options): return MarkdownConverter(**options).convert(html)