Commit 3a462976 authored by ankraft's avatar ankraft
Browse files

Improved marking of hanging paragraphs

parent dbce0546
Loading
Loading
Loading
Loading
+9 −6
Original line number Original line Diff line number Diff line
@@ -34,7 +34,7 @@ class LineType(Enum):
@dataclass
@dataclass
class Line:
class Line:
	"""	Represents a line in the markdown file. """
	"""	Represents a line in the markdown file. """
	text:str = ''
	text:str = '\n'
	lineType:LineType = LineType.TEXT
	lineType:LineType = LineType.TEXT




@@ -128,12 +128,13 @@ class Clause:




	def __len__(self) -> int:
	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:
			Returns:
				The number of characters in the clause.
				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)
_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
			# Check if there is a sub-clause in the next clause
			if i + 1 < len(clauses) and clauses[i+1].level > clause.level:
			if i + 1 < len(clauses) and clauses[i+1].level > clause.level:
				# This is a hanging paragraph. Remove the text from the current clause.
				# 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:
				if not includeHangingParagraphs:
					clauses[i].lines = []
					clauses[i].lines = []
				else:
				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.
	# Repair wrong markdown for indented lines.
	# Add 2 spaces to existing 2-space indentions
	# Add 2 spaces to existing 2-space indentions
@@ -510,7 +511,9 @@ def writeClauses(outClauses:list[Clause], filename:str, navTitle:str, addNavTitl
			else:
			else:
				file.write(f"{indentation}{'  '*f.level}- '{_title}':\n")
				file.write(f"{indentation}{'  '*f.level}- '{_title}':\n")
				if len(f) > 0:
				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:
def copyMediaFiles(filename:str, navTitle:str, mediaDirectory:str = 'media') -> None: