Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions dashtable/dashutils/center_line.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import math

from wcwidth import wcswidth


def center_line(space, line):
"""
Expand All @@ -21,8 +23,8 @@ def center_line(space, line):
"""
line = line.strip()

left_length = math.floor((space - len(line)) / 2)
right_length = math.ceil((space - len(line)) / 2)
left_length = math.floor((space - wcswidth(line)) / 2)
right_length = math.ceil((space - wcswidth(line)) / 2)

left_space = " " * int(left_length)
right_space = " " * int(right_length)
Expand Down
7 changes: 5 additions & 2 deletions dashtable/dashutils/get_longest_line_length.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
from wcwidth import wcswidth


def get_longest_line_length(text):
"""Get the length longest line in a paragraph"""
lines = text.split("\n")
length = 0

for i in range(len(lines)):
if len(lines[i]) > length:
length = len(lines[i])
if wcswidth(lines[i]) > length:
length = wcswidth(lines[i])

return length
5 changes: 4 additions & 1 deletion dashtable/data2md/get_column_width.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from wcwidth import wcswidth


def get_column_width(column, table):
"""
Get the character width of a column in a table
Expand All @@ -17,7 +20,7 @@ def get_column_width(column, table):
width = 3

for row in range(len(table)):
cell_width = len(table[row][column])
cell_width = wcswidth(table[row][column])
if cell_width > width:
width = cell_width

Expand Down
7 changes: 5 additions & 2 deletions dashtable/data2rst/cell/center_cell_text.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import math

from wcwidth import wcswidth

from .get_longest_line_length import get_longest_line_length

def center_cell_text(cell):
Expand All @@ -20,7 +23,7 @@ def center_cell_text(cell):
cell : dashtable.data2rst.Cell
"""
lines = cell.text.split('\n')
cell_width = len(lines[0]) - 2
cell_width = wcswidth(lines[0]) - 2

truncated_lines = ['']
for i in range(1, len(lines) - 1):
Expand All @@ -37,7 +40,7 @@ def center_cell_text(cell):

for i in range(len(truncated_lines)):
truncated_lines[i] = left_space + truncated_lines[i]
right_width = cell_width - len(truncated_lines[i])
right_width = cell_width - wcswidth(truncated_lines[i])
truncated_lines[i] += right_width * ' '

for i in range(1, len(lines) - 1):
Expand Down
7 changes: 5 additions & 2 deletions dashtable/data2rst/cell/get_longest_line_length.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
from wcwidth import wcswidth


def get_longest_line_length(text):
"""Get the length longest line in a paragraph"""
lines = text.split("\n")
length = 0

for i in range(len(lines)):
if len(lines[i]) > length:
length = len(lines[i])
if wcswidth(lines[i]) > length:
length = wcswidth(lines[i])

return length
4 changes: 3 additions & 1 deletion dashtable/data2rst/cell/v_center_cell_text.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import math

from wcwidth import wcswidth


def v_center_cell_text(cell):
"""
Expand All @@ -24,7 +26,7 @@ def v_center_cell_text(cell):
cell : dashtable.data2rst.Cell
"""
lines = cell.text.split('\n')
cell_width = len(lines[0]) - 2
cell_width = wcswidth(lines[0]) - 2

truncated_lines = []
for i in range(1, len(lines) - 1):
Expand Down
4 changes: 3 additions & 1 deletion dashtable/data2rst/make_cell.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from wcwidth import wcswidth

from ..dashutils import get_span_char_width
from ..dashutils import get_span_char_height
from ..dashutils import get_span_row_count
Expand Down Expand Up @@ -35,7 +37,7 @@ def make_cell(table, span, widths, heights, use_headers):

lines = text.split("\n")
for i in range(len(lines)):
width_difference = width - len(lines[i])
width_difference = width - wcswidth(lines[i])
lines[i] = ''.join([lines[i], " " * width_difference])

height_difference = height - len(lines)
Expand Down
5 changes: 4 additions & 1 deletion dashtable/html2data/restructify/converters/convert_h1.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
from wcwidth import wcswidth


def convert_h1(element, text):
"""
Add '=' to the bottom of text
"""
if text:
text = text + '\n' + '=' * len(text)
text = text + '\n' + '=' * wcswidth(text)
return text
5 changes: 4 additions & 1 deletion dashtable/html2data/restructify/converters/convert_h2.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
from wcwidth import wcswidth


def convert_h2(element, text):
"""
Adds '-' to the bottom of the text
"""
if text:
text = text + '\n' + '-' * len(text)
text = text + '\n' + '-' * wcswidth(text)
return text
5 changes: 4 additions & 1 deletion dashtable/html2data/restructify/converters/convert_h3.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
from wcwidth import wcswidth


def convert_h3(element, text):
"""
Adds '~' to the bottom of the text
"""
if text:
text = text + '\n' + '~' * len(text) + '\n'
text = text + '\n' + '~' * wcswidth(text) + '\n'
return text
5 changes: 4 additions & 1 deletion dashtable/html2data/restructify/converters/convert_li.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from wcwidth import wcswidth


def get_bullet_depth(element):
depth = -1
while element:
Expand All @@ -21,7 +24,7 @@ def convert_li(element, text):
for i in range(len(children)):
if parent.index(children[i]) == index:
number = str(i + 1)
interspace = (space - len(number)) * ' '
interspace = (space - wcswidth(number)) * ' '
text = number + '.' + interspace + text

depth = get_bullet_depth(element)
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@
url='https://github.com/doakey3/DashTable',
download_url='https://github.com/doakey3/DashTable/tarball/1.4.5',
license='MIT',
install_requires=['wcwidth'],
)
18 changes: 18 additions & 0 deletions tests/static/cjk.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<table>
<caption>Testing tables with CJK text</caption>
<tr>
<td>This is</td>
<td>some text</td>
<td>in English.</td>
</tr>
<tr>
<td>This text</td>
<td>是用中文写的</td>
<td>instead.</td>
</tr>
<tr>
<td>This is</td>
<td>some more text</td>
<td>in English.</td>
</tr>
</table>
4 changes: 4 additions & 0 deletions tests/static/cjk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
| This is | some text | in English. |
|-----------|----------------|-------------|
| This text | 是用中文写的 | instead. |
| This is | some more text | in English. |
7 changes: 7 additions & 0 deletions tests/static/cjk.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
+-----------+----------------+-------------+
| This is | some text | in English. |
+-----------+----------------+-------------+
| This text | 是用中文写的 | instead. |
+-----------+----------------+-------------+
| This is | some more text | in English. |
+-----------+----------------+-------------+