From c5833fc12a2f577f4e62e3937290f16ee4ebd825 Mon Sep 17 00:00:00 2001 From: Robert Kaussow Date: Mon, 2 Dec 2019 15:00:32 +0100 Subject: [PATCH] fix newline handling --- ansibledoctor/Annotation.py | 23 ++++++++++--------- ansibledoctor/templates/hugo-book/index.md.j2 | 1 + 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/ansibledoctor/Annotation.py b/ansibledoctor/Annotation.py index 5664b7a..94deccd 100644 --- a/ansibledoctor/Annotation.py +++ b/ansibledoctor/Annotation.py @@ -119,9 +119,10 @@ class Annotation: multiline = [] stars_with_annotation = r"(\#\ *[\@][\w]+)" current_file_position = self._file_handler.tell() + newline = "" while True: - next_line = self._file_handler.readline() + next_line = self._file_handler.readline().lstrip() if not next_line.strip(): self._file_handler.seek(current_file_position) @@ -132,22 +133,22 @@ class Annotation: self._file_handler.seek(current_file_position) break - # match if empty line or commented empty line - test_line = next_line.replace("#", "").strip() - if len(test_line) == 0: - self._file_handler.seek(current_file_position) - break - # match if does not start with comment test_line2 = next_line.strip() if test_line2[:1] != "#": self._file_handler.seek(current_file_position) break - final = next_line.replace("#", "").rstrip() - if final[:1] == " ": - final = final[1:] - multiline.append(final) + final = newline + next_line.replace("#", "").strip() + # match if empty line or commented empty line + test_line = next_line.replace("#", "").strip() + if len(test_line) == 0: + newline = "\n\n" + continue + else: + newline = "" + + multiline.append(newline + final) if parts[2].startswith("$"): source = "".join([x.strip() for x in multiline]) diff --git a/ansibledoctor/templates/hugo-book/index.md.j2 b/ansibledoctor/templates/hugo-book/index.md.j2 index 7c9a5de..68cb306 100644 --- a/ansibledoctor/templates/hugo-book/index.md.j2 +++ b/ansibledoctor/templates/hugo-book/index.md.j2 @@ -6,6 +6,7 @@ type: docs --- {% endif %} {% if description | deep_get(meta, "description.value") %} + {{ meta.description.value | save_join(" ") }} {% endif %}