aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVincent Driessen <vincent@datafox.nl>2010-08-19 09:51:42 +0200
committerVincent Driessen <vincent@datafox.nl>2010-08-19 09:51:42 +0200
commit4353027f5c7dd4235151baced074a32545d886b6 (patch)
tree2069097afbd30839ddc9f5d4d272a77e4e1c6fa1 /src
parentfae01af853842a405b52010ea7a2f41fe4243e8c (diff)
downloadvim-rst-tables-4353027f5c7dd4235151baced074a32545d886b6.tar.gz
vim-rst-tables-4353027f5c7dd4235151baced074a32545d886b6.tar.bz2
vim-rst-tables-4353027f5c7dd4235151baced074a32545d886b6.zip
Added ability to parse existing tables.
Diffstat (limited to 'src')
-rw-r--r--src/rst_tables.py16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/rst_tables.py b/src/rst_tables.py
index e1e3842..1cceb91 100644
--- a/src/rst_tables.py
+++ b/src/rst_tables.py
@@ -36,11 +36,19 @@ def unify_table(table):
return output
+def split_table_row(row_string):
+ if row_string.find("|") >= 0:
+ # first, strip off the outer table drawings
+ row_string = re.sub(r'^\s*\||\|\s*$', '', row_string)
+ return re.split(r'\s*\|\s*', row_string.strip())
+ return re.split(r'\s\s+', row_string.rstrip())
+
+
def parse_table(raw_lines):
- mkfields = lambda line: re.split('\s\s+', line.rstrip())
- output = map(mkfields, raw_lines)
- output = unify_table(output)
- return output
+ select_data_lines = lambda line: not re.match('^[\t +=-]+$', line)
+ lines = filter(select_data_lines, raw_lines)
+ lines = map(split_table_row, lines)
+ return unify_table(lines)
def table_line(widths, header=False):