From c78eea2b0089f67fb0b6a11855b3d094f45d03ef Mon Sep 17 00:00:00 2001 From: Tyler Moore Date: Tue, 24 Nov 2020 16:19:34 -0500 Subject: [PATCH] Fix Cells With Linefeeds - convert linefeeds to `
` before outputting markdown --- ods2md.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ods2md.py b/ods2md.py index 18dd95f..54dd60c 100755 --- a/ods2md.py +++ b/ods2md.py @@ -19,9 +19,7 @@ from __future__ import print_function -import ezodf -import sys -import unicodedata +import ezodf, sys, re, unicodedata # Ref: http://stackoverflow.com/a/31666966/224671 DISPLAY_WIDTH = { @@ -33,14 +31,16 @@ DISPLAY_WIDTH = { 'W': 2, } +LINEFEED_REGEX=re.compile('(\r\n|\r|\n)', flags=re.MULTILINE) + def display_text(cell): v = cell.value if isinstance(v, float): - return '{:g}'.format(v) + return LINEFEED_REGEX.sub('
', '{:g}'.format(v)) elif v is None: return '' else: - return str(v) + return LINEFEED_REGEX.sub('
', str(v)) def display_len(s): return sum(DISPLAY_WIDTH[unicodedata.east_asian_width(c)] for c in s)