Skip to content
Snippets Groups Projects
Commit 3a462976 authored by Andreas Kraft's avatar Andreas Kraft
Browse files

Improved marking of hanging paragraphs

parent dbce0546
No related branches found
No related tags found
No related merge requests found
......@@ -34,7 +34,7 @@ class LineType(Enum):
@dataclass
class Line:
""" Represents a line in the markdown file. """
text:str = ''
text:str = '\n'
lineType:LineType = LineType.TEXT
......@@ -128,12 +128,13 @@ class Clause:
def __len__(self) -> int:
""" Return the number of characters in the clause.
""" Return the number of characters in the clause. This does not include
empty lines or lines that contain only whitespace.
Returns:
The number of characters in the clause.
"""
return sum([ len(l.text) for l in self.lines ])
return sum([ len(l.text.strip()) for l in self.lines ])
_matchHeader = re.compile(r'(#+)\s+(.*)', re.IGNORECASE)
......@@ -341,11 +342,11 @@ def prepareForMkdocs(clauses:list[Clause], includeHangingParagraphs:bool = False
# Check if there is a sub-clause in the next clause
if i + 1 < len(clauses) and clauses[i+1].level > clause.level:
# This is a hanging paragraph. Remove the text from the current clause.
print(f'[yellow]Hanging paragraph in clause "{clause.title}" {"(removed)" if not includeHangingParagraphs else "(kept)"}')
print(f'[yellow]Hanging paragraph in clause "{clause.title}" {"(removed)" if not includeHangingParagraphs else "(kept + warning)"}')
if not includeHangingParagraphs:
clauses[i].lines = []
else:
clauses[i].lines = [Line("<mark>Editor note: This is a hanging paragraph and it must be moved to its own clause</mark>")] + [Line()] + clauses[i].lines
clauses[i].lines = [Line('<mark>Editor note: This is a hanging paragraph and it must be moved to its own clause</mark>\n'), Line()] + clauses[i].lines
# Repair wrong markdown for indented lines.
# Add 2 spaces to existing 2-space indentions
......@@ -510,7 +511,9 @@ def writeClauses(outClauses:list[Clause], filename:str, navTitle:str, addNavTitl
else:
file.write(f"{indentation}{' '*f.level}- '{_title}':\n")
if len(f) > 0:
file.write(f"{indentation}{' '*nextClause.level}- 'Hanging paragraph': '{navTitle}/{f.clauseNumber}.md'\n")
file.write(f"{indentation}{' '*nextClause.level}- '<mark>Hanging paragraph</mark>': '{navTitle}/{f.clauseNumber}.md'\n")
if verbose:
print(f'[dim]Added hanging paragraph to navigation for clause "{f.title}"')
def copyMediaFiles(filename:str, navTitle:str, mediaDirectory:str = 'media') -> None:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment