Permalink
Browse files

Merge pull request #7 from choplin/master

Support tables containing East Asian languages, too.
  • Loading branch information...
2 parents 8db3e17 + 4189dce commit 8472e84fe463ee98ff02f6ae0b37e08239ad9907 @nvie committed Oct 1, 2011
Showing with 12 additions and 2 deletions.
  1. +12 −2 ftplugin/rst_tables.vim
View
@@ -20,6 +20,7 @@ python << endpython
import vim
import re
import textwrap
+import unicodedata
from vim_bridge import bridged
@@ -160,8 +161,17 @@ def table_line(widths, header=False):
def get_field_width(field_text):
- return max(map(lambda s: len(s), field_text.split('\n')))
-
+ return max(map(get_string_width, field_text.split('\n')))
+
+def get_string_width(string):
+ width = 0
+ for char in list(string.decode('utf-8')):
+ eaw = unicodedata.east_asian_width(char)
+ if eaw == 'Na' or eaw == 'H':
+ width += 1
+ else:
+ width += 2
+ return width
def split_row_into_lines(row):
row = map(lambda field: field.split('\n'), row)

0 comments on commit 8472e84

Please sign in to comment.