Commit 53875876 authored by ankraft's avatar ankraft Committed by Miguel Angel Reina Ortega
Browse files

Fixed problem with removed first line for non-header clauses (ie. the first...

Fixed problem with removed first line for non-header clauses (ie. the first text in a document or a document without any header)
parent 2e0270c6
Loading
Loading
Loading
Loading
+11 −3
Original line number Diff line number Diff line
@@ -181,6 +181,7 @@ def analyseMarkdown(filename:str) -> list[Clause]:
	with open(filename, 'r', encoding = 'utf-8', errors = 'replace') as file:
		inLines = file.readlines()
	
	# The list of clauses. The first clause contains the text before the first heading.
	outClauses:list[Clause] = [Clause(0, '', '', [])]

	# Go through the lines and detect headers and codefences
@@ -262,6 +263,10 @@ def splitMarkdownDocument(clauses:list[Clause],
		# Add the lines to the output clause
		outClauses[-1].extend(clause)
	
	# Remove the first clauses if they contain no lines AND the title is empty
	while outClauses[0].linesCount == 0 and not len(outClauses[0].title):
		outClauses.pop(0)
	
	# Remove the first clause if it has no title
	if not includeUntilFirstHeading:
		while len(outClauses[0].title) == 0:
@@ -281,11 +286,13 @@ def prepareForMkdocs(clauses:list[Clause]) -> list[Clause]:
			The list of clauses.
	"""

	# Remove the heading from the lines. The heading is the first line
	# Remove the heading from the lines. The heading is (usually) the first line
	# in the clause. This is done because MkDocs repeats the heading when
	# displaying the page.
	for clause in clauses:
		if clause.linesCount > 0:
			# Remove the first line from the clause if it is a heading
			if clause.lines[0].lineType == LineType.HEADING:
				clause.lines.pop(0)
			# Also, remove the first empty lines if they exist
			while clause.linesCount > 0 and clause.lines[0].text.strip() == '':
@@ -484,7 +491,8 @@ def processDocument(args:argparse.Namespace) -> None:
	clauses = analyseMarkdown(document)
	clauses = splitMarkdownDocument(clauses, 
								 	[ t.casefold() for t in args.ignore_clause ], 
									args.split_level,args.include_title)
									args.split_level,
									args.include_title)
	clauses = updateLinks(clauses)
	clauses = updateNotes(clauses)
	clauses = prepareForMkdocs(clauses)