fix newline handling

This commit is contained in:
Robert Kaussow 2019-12-02 15:00:32 +01:00
parent 5da5539254
commit c5833fc12a
2 changed files with 13 additions and 11 deletions

View File

@ -119,9 +119,10 @@ 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 = ""
while True: while True:
next_line = self._file_handler.readline() next_line = self._file_handler.readline().lstrip()
if not next_line.strip(): if not next_line.strip():
self._file_handler.seek(current_file_position) self._file_handler.seek(current_file_position)
@ -132,22 +133,22 @@ class Annotation:
self._file_handler.seek(current_file_position) self._file_handler.seek(current_file_position)
break 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 # match if does not start with comment
test_line2 = next_line.strip() test_line2 = next_line.strip()
if test_line2[:1] != "#": if test_line2[:1] != "#":
self._file_handler.seek(current_file_position) self._file_handler.seek(current_file_position)
break break
final = next_line.replace("#", "").rstrip() final = newline + next_line.replace("#", "").strip()
if final[:1] == " ": # match if empty line or commented empty line
final = final[1:] test_line = next_line.replace("#", "").strip()
multiline.append(final) if len(test_line) == 0:
newline = "\n\n"
continue
else:
newline = ""
multiline.append(newline + final)
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

@ -6,6 +6,7 @@ type: docs
--- ---
{% endif %} {% endif %}
{% if description | deep_get(meta, "description.value") %} {% if description | deep_get(meta, "description.value") %}
{{ meta.description.value | save_join(" ") }} {{ meta.description.value | save_join(" ") }}
{% endif %} {% endif %}