fix: allow to force line breaks using '\' in multiline strings (#255)

This commit is contained in:
Robert Kaussow 2022-03-02 14:33:37 +01:00 committed by GitHub
parent ba2383d894
commit 6a4328d6d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 8 deletions

View File

@ -131,7 +131,8 @@ class Annotation:
multiline = []
stars_with_annotation = r"(\#\ *[\@][\w]+)"
current_file_position = self._file_handler.tell()
newline = ""
before = ""
after = ""
while True:
next_line = self._file_handler.readline().lstrip()
@ -154,17 +155,23 @@ class Annotation:
final = re.findall(r"\#(.*)", next_line)[0].rstrip()
if final[:1] == " ":
final = final[1:]
final = newline + final
final = before + final
# match if empty line or commented empty line
test_line = next_line.replace("#", "").strip()
if len(test_line) == 0:
newline = "\n\n"
before = "\n\n"
continue
else:
newline = ""
before = ""
multiline.append(newline + final)
if test_line.endswith("\\"):
final = final.rstrip("\\").strip()
after = "\n"
else:
after = ""
multiline.append(before + final + after)
if parts[2].startswith("$"):
source = "".join([x.strip() for x in multiline])

View File

@ -160,9 +160,11 @@ class Generator:
if isinstance(value, str):
value = [value]
joined = jinja2.filters.do_join(eval_ctx, value, d, attribute=None)
nornalized = re.sub(r" +(\n|\t| )", "\\1", joined)
return nornalized
normalized = jinja2.filters.do_join(eval_ctx, value, d, attribute=None)
for s in [r" +(\n|\t| )", r"(\n|\t) +"]:
normalized = re.sub(s, "\\1", normalized)
return normalized
def render(self):
self.logger.info("Using output dir: " + self.config.config.get("output_dir"))