Merge pull request #3 from devopsec/newline-fix

Fix Cells With Linefeeds
This commit is contained in:
kennytm 2020-12-02 12:09:33 +08:00 committed by GitHub
commit 92b731f5ad
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -19,9 +19,7 @@
from __future__ import print_function from __future__ import print_function
import ezodf import ezodf, sys, re, unicodedata
import sys
import unicodedata
# Ref: http://stackoverflow.com/a/31666966/224671 # Ref: http://stackoverflow.com/a/31666966/224671
DISPLAY_WIDTH = { DISPLAY_WIDTH = {
@ -33,6 +31,8 @@ DISPLAY_WIDTH = {
'W': 2, 'W': 2,
} }
LINEFEED_REGEX=re.compile('\r\n|[\r\n]')
def display_text(cell): def display_text(cell):
v = cell.value v = cell.value
if isinstance(v, float): if isinstance(v, float):
@ -40,7 +40,7 @@ def display_text(cell):
elif v is None: elif v is None:
return '' return ''
else: else:
return str(v) return LINEFEED_REGEX.sub('<br>', str(v))
def display_len(s): def display_len(s):
return sum(DISPLAY_WIDTH[unicodedata.east_asian_width(c)] for c in s) return sum(DISPLAY_WIDTH[unicodedata.east_asian_width(c)] for c in s)