From 245a5ee46eabb4f57a3786f083ba68064cb6eb3b Mon Sep 17 00:00:00 2001 From: RunasSudo Date: Wed, 11 Sep 2019 11:25:33 +1000 Subject: [PATCH] Render table row number in separate column --- example.pdf | Bin 12718 -> 12719 bytes legalmd/latex_renderer.py | 27 +++++++++++++++------------ 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/example.pdf b/example.pdf index 05b92a0025e7070c0e5cf1cebca4c3af09c28165..200abca909f6a3a11c14af6e134bb69eb8e87dc1 100644 GIT binary patch delta 1062 zcmV+>1ljwpW3OYdCISI5lYt2plRN?%f5@ptPR*gG{(ec#YG>>;hB1&VX-K|D@@aOb z&9|qVLyk2AVmQ5RFo69qh(@gxa@9yI;q)F}9sno-Wa&_Bjt2nVcUzx}*u2_4b=#DS zt#I*w_Uyaqa2+?(lf7c5(jGvMZl*uXHrL1Q_4MpZw6W&=fCn==5&}%^FmWJ;6iWl6si(uUrfAU&e@KV0^l{+kajJuf^EH2kqiPMR6f5ahI3E)0$0jEQ zR-GUxBR5@oN!-WSN)o1$JYT&TJywV{>80VbWUrI#Eu~bW82AzNej?d3HdIm_Nrk?U z8s|Ab%qt!!4P^OC)@YwnZjG!cF+rMQ)>cy>*`h$MLlnvTX4ec(pphaKe+^>b3-QF} zt}lwdb?0!rty}-Yg%#_9>Rf1K&C4(x&@zmJr@hBWW!;D+7?&nIi5Dh($z_HH+Nexa z&2@q?Qwm0yjkBhVlAy+?TvH|#G_rKO~L(XPdgnQ2tycD?QAf+P6k?Q3|+e~TFOj=betcne0H z8??U3T6Y(ZK64vqZE|zn<2cFzp&Z z&a* zbsGK(Wo~41baG{3vs48$BLp!rH8GQmC?5ndGBq)?t|-O_MMFe1LNz!;GciO$GC4vq zF-1i~LPaq_GB`vrI5apgJ|H|dLqs$}H8?{vF+@T#IYKcpMMXnGMKM7#I7BfxG&nFm zAYGGD8Xf~NH8_)j2^D`8%u7Rmf#NC@E04qlI1L-l*5yqG}`;oJo+&;y>8Qw5=F_VjnJUku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Renderer(mistletoe.latex_renderer.LaTeXRenderer): return ''.join(result) def render_table_header(self, token): - cells1 = ['{\\bfseries Column ' + child.label + '}' for child in token.children] - cells2 = ['{\\bfseries ' + self.render_inner(child) + '}' for child in token.children] + cells1 = [] + 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) + ' \\\\' 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) + ' \\\\' def render_table_cell(self, token): - if token.colnum == 0 and token.label: - return format(r'\makebox[2.2em][l]{.}', - rownum=token.label, - content=self.render_inner(token) - ) - else: - return self.render_inner(token) + return self.render_inner(token) def render_document(self, token): template = r'''