Fix Cells With Linefeeds
- convert linefeeds to `<br>` before outputting markdown
This commit is contained in:
parent
b407d8ab21
commit
c78eea2b00
1 changed files with 5 additions and 5 deletions
10
ods2md.py
10
ods2md.py
|
@ -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,14 +31,16 @@ DISPLAY_WIDTH = {
|
||||||
'W': 2,
|
'W': 2,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LINEFEED_REGEX=re.compile('(\r\n|\r|\n)', flags=re.MULTILINE)
|
||||||
|
|
||||||
def display_text(cell):
|
def display_text(cell):
|
||||||
v = cell.value
|
v = cell.value
|
||||||
if isinstance(v, float):
|
if isinstance(v, float):
|
||||||
return '{:g}'.format(v)
|
return LINEFEED_REGEX.sub('<br>', '{:g}'.format(v))
|
||||||
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)
|
||||||
|
|
Loading…
Reference in a new issue