def _table_sub(self, match):
        head, underline, body = match.groups()

        # Determine aligns for columns.
        cols = [cell.strip() for cell in underline.strip('| \t\n').split('|')]
        align_from_col_idx = {}
        for col_idx, col in enumerate(cols):
            if col[0] == ':' and col[-1] == ':':
                align_from_col_idx[col_idx] = ' align="center"'
            elif col[0] == ':':
                align_from_col_idx[col_idx] = ' align="left"'
            elif col[-1] == ':':
                align_from_col_idx[col_idx] = ' align="right"'

        # thead
        hlines = ['<table%s>' % self._html_class_str_from_tag('table'), '<thead>', '<tr>']
        cols = [cell.strip() for cell in head.strip('| \t\n').split('|')]
        for col_idx, col in enumerate(cols):
            hlines.append('  <th%s>%s</th>' % (
                align_from_col_idx.get(col_idx, ''),
                self._run_span_gamut(col)
            ))
        hlines.append('</tr>')
        hlines.append('</thead>')

        # tbody
        hlines.append('<tbody>')
        for line in body.strip('\n').split('\n'):
            hlines.append('<tr>')
            cols = [cell.strip() for cell in line.strip('| \t\n').split('|')]
            for col_idx, col in enumerate(cols):
                hlines.append('  <td%s>%s</td>' % (
                    align_from_col_idx.get(col_idx, ''),
                    self._run_span_gamut(col)
                ))
            hlines.append('</tr>')
        hlines.append('</tbody>')
        hlines.append('</table>')

        return '\n'.join(hlines) + '\n'
dataset/ETHPy150Open an0/Letterpress/code/markdown2/lib/markdown2.py/Markdown._table_sub/original