Skip to content

Commit

Permalink
feature: determine how many trailing spaces to add or remove
Browse files Browse the repository at this point in the history
  • Loading branch information
mecaneer23 committed Jan 29, 2024
1 parent ca2380a commit 3fdebf9
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/md_to_py.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@ def _pad_columns(row: str, widths: tuple[int, ...] | int, delimiter: str = "|")
column_count = row.count(delimiter) - 1

if isinstance(widths, tuple) and len(widths) != column_count:
raise ValueError("`widths` cannot be a tuple of arbitrary length")
raise ValueError(
"`widths` cannot be a tuple of arbitrary length. "\
f"Is {len(widths)}, should be {column_count}."
)

if isinstance(widths, int):
widths = tuple(repeat(widths, column_count))
Expand All @@ -88,6 +91,7 @@ def _pad_columns(row: str, widths: tuple[int, ...] | int, delimiter: str = "|")
backward_count = 1
trailing_space_start = 0
prev_delimiter_index = 0
change_amount = 0
new_row = ""

while count < len(row):
Expand All @@ -100,20 +104,19 @@ def _pad_columns(row: str, widths: tuple[int, ...] | int, delimiter: str = "|")
widths[column] < non_space_len
): # maybe off by 1 error, as doesn't account for one trailing space
raise ValueError(
f"Width of column `{column}` cannot be less than\
{non_space_len}, is {widths[column]}"
f"Width of column `{column}` cannot be less than "\
f"{non_space_len}, is {widths[column]}"
)
prev_delimiter_index = count
if widths[column] == non_space_len:
backward_count = 1
count += 1
column += 1
continue
if non_space_len + backward_count > widths[column]:
raise NotImplementedError("Make the amount of spaces smaller")
backward_count = 1
continue
raise NotImplementedError("Make the amount of spaces larger")
change_amount = widths[column] - non_space_len - backward_count + 1
print(f"change the amount of spaces by {change_amount}")
backward_count = 1
column += 1
count += 1
# - add or remove trailing spaces based on that value
# (and the value of widths for that column)
Expand Down

0 comments on commit 3fdebf9

Please sign in to comment.