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

View File

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