aboutsummaryrefslogtreecommitdiff
path: root/support
diff options
context:
space:
mode:
authorVictor Zverovich <victor.zverovich@gmail.com>2018-09-13 07:15:18 -0700
committerVictor Zverovich <victor.zverovich@gmail.com>2018-09-13 07:15:18 -0700
commit465a59353628463db1a98ad84b7ecfb1240fcbca (patch)
tree60f59ee48e0bca213190637f14af8b84697fd9c6 /support
parentd62f4c3bc11ab161ca3bb642ea765f2b32f54c8d (diff)
downloadfmtlib-465a59353628463db1a98ad84b7ecfb1240fcbca.tar.gz
Add table support to rst2md
Diffstat (limited to 'support')
-rw-r--r--support/rst2md.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/support/rst2md.py b/support/rst2md.py
index 00ee93d9..59187ced 100644
--- a/support/rst2md.py
+++ b/support/rst2md.py
@@ -109,6 +109,30 @@ class Translator(nodes.NodeVisitor):
def depart_image(self, node):
pass
+ def write_row(self, row, widths):
+ for i, entry in enumerate(row):
+ text = entry[0][0] if len(entry) > 0 else ''
+ if i != 0:
+ self.write(' ')
+ self.write('{:{}}'.format(text, widths[i]))
+
+ def visit_table(self, node):
+ table = node.children[0]
+ colspecs = table[:-2]
+ thead = table[-2]
+ tbody = table[-1]
+ widths = [int(cs['colwidth']) for cs in colspecs]
+ sep = ' '.join(['-' * w for w in widths])
+ self.write(sep)
+ self.write_row(thead[0], widths)
+ self.write(sep)
+ for row in tbody:
+ self.write_row(row, widths)
+ self.write(sep)
+ raise nodes.StopTraversal
+
+ def depart_table(self, node):
+ pass
class MDWriter(writers.Writer):
"""GitHub-flavored markdown writer"""