Render table row number in separate column

This commit is contained in:
RunasSudo 2019-09-11 11:25:33 +10:00
parent 8f1b233dbe
commit 245a5ee46e
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A
2 changed files with 15 additions and 12 deletions

Binary file not shown.

View File

@ -145,10 +145,10 @@ class LaTeXRenderer(mistletoe.latex_renderer.LaTeXRenderer):
) )
def render_table(self, token): def render_table(self, token):
align = ['X' for col in token.column_align] align = [r'l@{\hspace{1ex}}'] + ['X' for col in token.column_align]
if hasattr(token, 'header'): if hasattr(token, 'header'):
for i, col in enumerate(token.header.children): for i, col in enumerate(token.header.children):
align[i] += '[{}]'.format(col.weight) align[i+1] += '[{}]'.format(col.weight)
result = [ result = [
format('{\\footnotesize\\begin{longtabu} to \\dimexpr\\columnwidth-<lmarg>\\relax [r] {'), format('{\\footnotesize\\begin{longtabu} to \\dimexpr\\columnwidth-<lmarg>\\relax [r] {'),
@ -168,21 +168,24 @@ class LaTeXRenderer(mistletoe.latex_renderer.LaTeXRenderer):
return ''.join(result) return ''.join(result)
def render_table_header(self, token): def render_table_header(self, token):
cells1 = ['{\\bfseries Column ' + child.label + '}' for child in token.children] cells1 = []
cells2 = ['{\\bfseries ' + self.render_inner(child) + '}' for child in token.children] cells2 = []
for cell in token.children:
if cell.colnum == 0:
cells1.append('\\multicolumn{2}{l}{\\bfseries Column ' + cell.label + '}')
cells2.append('\\multicolumn{2}{l}{\\bfseries ' + self.render_inner(cell) + '}')
else:
cells1.append('{\\bfseries Column ' + cell.label + '}')
cells2.append('{\\bfseries ' + self.render_inner(cell) + '}')
return ' & '.join(cells1) + ' \\\\\\midrule\n' + ' & '.join(cells2) + ' \\\\' return ' & '.join(cells1) + ' \\\\\\midrule\n' + ' & '.join(cells2) + ' \\\\'
def render_table_row(self, token): def render_table_row(self, token):
cells = [self.render_table_cell(child) for child in token.children] cells = [(token.children[0].label + '.') if token.children[0].label else ''] + [self.render_table_cell(child) for child in token.children]
return ' & '.join(cells) + ' \\\\' return ' & '.join(cells) + ' \\\\'
def render_table_cell(self, token): def render_table_cell(self, token):
if token.colnum == 0 and token.label:
return format(r'\makebox[2.2em][l]{<rownum>.}<content>',
rownum=token.label,
content=self.render_inner(token)
)
else:
return self.render_inner(token) return self.render_inner(token)
def render_document(self, token): def render_document(self, token):