mirror of
https://github.com/thegeeklab/ansible-doctor.git
synced 2024-11-24 13:50:42 +00:00
fix: allow to force line breaks using '\' in multiline strings (#255)
This commit is contained in:
parent
ba2383d894
commit
6a4328d6d5
@ -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])
|
||||
|
@ -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"))
|
||||
|
Loading…
Reference in New Issue
Block a user