Skip to content

Commit 66fb1cd

Browse files
committed
Fix review bugs
1. Deal with stile divider lines better 2. Don't strip non-breaking spaces
1 parent 5295342 commit 66fb1cd

1 file changed

Lines changed: 18 additions & 8 deletions

File tree

src/guiguts/html_tools.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1423,27 +1423,28 @@ def convert(self) -> None:
14231423
table_text = (
14241424
maintext()
14251425
.get(sel_ranges[0].start.index(), sel_ranges[0].end.index())
1426-
.rstrip()
1426+
.rstrip(" ")
14271427
)
14281428
if not table_text:
14291429
return
14301430
multiline = preferences.get(PrefKey.AUTOTABLE_MULTILINE)
1431-
split_row_regex = r"\n[| ]*\n" if multiline else "\n"
1432-
split_col_regex = r"\|" if "|" in table_text else r" +"
1431+
split_row_regex = r"\n[| \u00a0]*\n" if multiline else "\n"
1432+
split_col_regex = r"\|" if "|" in table_text else r"[ \u00a0][ \u00a0]+"
14331433
text_rows: list[str] = re.split(split_row_regex, table_text)
14341434
# For each row of the table
14351435
for text_row in text_rows:
14361436
the_table.append([])
14371437
# For each text line in this row (only one if not multiline)
14381438
text_lines = text_row.split("\n")
14391439
for text_line in text_lines:
1440-
text_line = re.sub(r"^\||\|$", "", text_line.rstrip())
1440+
text_line = re.sub(r"^\||\|$", "", text_line.rstrip(" "))
14411441
# For each cell line in that text line
14421442
for col, cell_line in enumerate(re.split(split_col_regex, text_line)):
1443+
strip_line = cell_line.strip(" ")
14431444
if col >= len(the_table[-1]):
1444-
the_table[-1].append(cell_line.strip()) # Start new cell
1445+
the_table[-1].append(strip_line) # Start new cell
14451446
else:
1446-
the_table[-1][col] += f" {cell_line.strip()}" # Add to existing
1447+
the_table[-1][col] += f" {strip_line}" # Add to existing
14471448
# "Square off" table, making all rows have max_cols columns
14481449
max_cols = max(len(row) for row in the_table)
14491450
for row in the_table:
@@ -1460,9 +1461,18 @@ def convert(self) -> None:
14601461
n_lines = text_row.count("\n") + 1 # No. of lines in original table row
14611462
start_linenum = end_linenum - n_lines
14621463
html = self.html_row_from_text(the_table[-1 - rev_row_num])
1464+
# If multiline, and not the top row of the table, allow for blank line or "| |" line above
1465+
if (
1466+
multiline
1467+
and rev_row_num < len(text_rows) - 1
1468+
and re.fullmatch(
1469+
r"[| \u00a0]*",
1470+
maintext().get(f"{start_linenum}.0 -1l", f"{end_linenum-2}.end"),
1471+
)
1472+
):
1473+
start_linenum -= 1
14631474
maintext().replace(f"{start_linenum}.0", f"{end_linenum-1}.end", html)
1464-
# Allow for blank line if multiline
1465-
end_linenum = start_linenum - 1 if multiline else start_linenum
1475+
end_linenum = start_linenum
14661476
maintext().insert(f"{end_linenum}.0", '<table class="autotable">\n')
14671477
maintext().clear_selection()
14681478
maintext().set_insert_index(IndexRowCol(end_linenum, 0))

0 commit comments

Comments
 (0)