diff --git a/toMkdocs/toMkdocs.py b/toMkdocs/toMkdocs.py
index 92fdb4cf13d60195d62a5419041774e918b15f0f..531b97e9d3ab3feb7fb4c94ef094eca3c0e6c245 100644
--- a/toMkdocs/toMkdocs.py
+++ b/toMkdocs/toMkdocs.py
@@ -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,12 +286,14 @@ 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:
-			clause.lines.pop(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() == '':
 				clause.lines.pop(0)
@@ -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)