mirror of
https://github.com/hay-kot/mealie.git
synced 2025-08-22 22:43:34 -07:00
fix mangles outputs
This commit is contained in:
parent
8f64f7a603
commit
bd97de30ec
1 changed files with 12 additions and 4 deletions
|
@ -1,5 +1,4 @@
|
||||||
import logging
|
import logging
|
||||||
import re
|
|
||||||
import subprocess
|
import subprocess
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
@ -47,12 +46,21 @@ class CodeSlicer:
|
||||||
|
|
||||||
def push_line(self, string: str) -> None:
|
def push_line(self, string: str) -> None:
|
||||||
self._next_line = self._next_line or self.start + 1
|
self._next_line = self._next_line or self.start + 1
|
||||||
self.text.insert(self._next_line, self.indentation or "" + string + "\n")
|
self.text.insert(self._next_line, (self.indentation or "") + string + "\n")
|
||||||
self._next_line += 1
|
self._next_line += 1
|
||||||
|
|
||||||
|
|
||||||
def get_indentation_of_string(line: str, comment_char: str = "//|#") -> str:
|
def get_indentation_of_string(line: str) -> str:
|
||||||
return re.sub(rf"{comment_char}.*", "", line).removesuffix("\n")
|
# Extract everything before the comment
|
||||||
|
if "//" in line:
|
||||||
|
indentation = line.split("//")[0]
|
||||||
|
elif "#" in line:
|
||||||
|
indentation = line.split("#")[0]
|
||||||
|
else:
|
||||||
|
indentation = line
|
||||||
|
|
||||||
|
# Keep only the whitespace, remove any non-whitespace characters
|
||||||
|
return "".join(c for c in indentation if c.isspace())
|
||||||
|
|
||||||
|
|
||||||
def find_start_end(file_text: list[str], gen_id: str) -> tuple[int, int, str | None]:
|
def find_start_end(file_text: list[str], gen_id: str) -> tuple[int, int, str | None]:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue