diff --git a/devListener.py b/devListener.py index 10b1bb8..34e32ff 100644 --- a/devListener.py +++ b/devListener.py @@ -7,7 +7,6 @@ import os.path class MLPDevListener(sublime_plugin.EventListener): def on_post_save(self, view): - # return if not (os.path.dirname(__file__) in view.file_name() and view.file_name().endswith('.py')): return diff --git a/lib/pre_tables.py b/lib/pre_tables.py index 381455c..f4f4abc 100644 --- a/lib/pre_tables.py +++ b/lib/pre_tables.py @@ -29,8 +29,18 @@ def pre_table(s_table): text += '|\n' for j, cell in enumerate(row): - text += '| ' + ''.join(str(node) for node in cell.contents) \ - + ' ' * (cols_width[j] - len(cell.text) + 1) + text += '| ' + if cell.name == 'th': + title = ' ' * ((cols_width[j] - len(cell.text)) // 2) \ + + ''.join(str(node) for node in cell.contents) \ + + ' ' * int(round((cols_width[j] - len(cell.text)) / 2 ) + 1) + # + 1 because of the added space before the closing | of each cell + if cols_width[j] + 1 != len(title): + title += ' ' + text += title + else: + text += ''.join(str(node) for node in cell.contents) \ + + ' ' * (cols_width[j] - len(cell.text) + 1) text += '|\n' text += '' return text @@ -40,7 +50,3 @@ def pre_tables(html): for table in soup.find_all('table'): table.replace_with(BeautifulSoup(pre_table(table), 'html.parser')) return str(soup) - -if __name__ == "__main__": - # CSW: ignore - print(pre_tables(html))