Skip to content

Commit

Permalink
Merge duplicate empty lines in the final documents
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanLovato committed Feb 7, 2020
1 parent a50e38d commit 42ce3c8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ This document lists new features, improvements, changes, and bug fixes in every
- Add GDScript code highlighting for the hugo export format.
- Add support for enums.

### Improvements ###

- The documents now only have 1 empty line betweens paragraphs, headings, etc. instead of 2 to 4.

## GDScript Docs Maker 1.1 ##

### Features ###
Expand Down
2 changes: 1 addition & 1 deletion gdscript_docs_maker/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def save(
path: str = os.path.join(dirpath, document.get_filename())
with open(path, "w") as file_out:
LOGGER.debug("Saving markdown file " + path)
file_out.writelines("\n".join(document.content))
file_out.write(document.as_string())


if __name__ == "__main__":
Expand Down
6 changes: 6 additions & 0 deletions gdscript_docs_maker/modules/convert_to_markdown.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Parses the JSON data from Godot as a dictionary and outputs markdown documents"""
import re
from argparse import Namespace
from dataclasses import dataclass
from typing import List
Expand All @@ -18,6 +19,11 @@ class MarkdownDocument:
def get_filename(self):
return self.title + ".md"

def as_string(self) -> str:
"""Removes duplicate empty lines from the document and returns it as a string."""
text: str = "\n".join(self.content)
return re.sub(r"\n\n+", "\n\n", text)

def __repr__(self):
return "MarkdownDocument(title={}, content={})".format(
self.title, "\\n".join(self.content)[:120] + "..."
Expand Down

0 comments on commit 42ce3c8

Please sign in to comment.