Commit 2de59258 authored by ankraft's avatar ankraft
Browse files

Improved <br/> regex. fixed wrong progress usage

parent 09a75388
Loading
Loading
Loading
Loading
+7 −7
Original line number Diff line number Diff line
@@ -14,7 +14,7 @@ from rich.progress import Progress, TextColumn, TimeElapsedColumn
def readMDFile(progress:Progress, document:str) -> list[str]:
	"""	Read the markdown file and return a list of lines.
	"""	
	_taskID = progress.add_task('[blue]Reading document', start=False, total=0)
	_taskID = progress.add_task('[blue]Reading document', total=0)

	# Check if file exists
	if not os.path.exists(document):
@@ -31,7 +31,7 @@ def writeMDFile(progress:Progress, mdLines:list[str], document:str, outDirectory
	"""	Write the markdown file.

	"""
	_taskID = progress.add_task('[blue]Writing document', start=False, total=0)
	_taskID = progress.add_task('[blue]Writing document', total=0)

	# Write the file
	with open(f'{outDirectory}/{os.path.basename(document)}', 'w', encoding='utf-8', errors = 'replace') as f:
@@ -42,7 +42,7 @@ def writeMDFile(progress:Progress, mdLines:list[str], document:str, outDirectory
def correctTOC(progress:Progress, mdLines:list[str], tocSection:str = 'Contents') -> list[str]:
	"""	Correct the TOC to be compatible with pandoc.
	"""
	_taskID = progress.add_task('[blue]Correcting TOC', start=False, total=0)
	_taskID = progress.add_task('[blue]Correcting TOC', total=0)

	_contents = f'# {tocSection}\n'
	tocregex = re.compile('^(.*\[.*\])')
@@ -77,7 +77,7 @@ def correctTOC(progress:Progress, mdLines:list[str], tocSection:str = 'Contents'
def replaceTableCaptions(progress:Progress, mdLines:list[str]) -> list[str]:
	"""	Replace table captions with a pandoc table caption.
	"""
	_taskID = progress.add_task('[blue]Replacing table captions', start=False, total=0)
	_taskID = progress.add_task('[blue]Replacing table captions', total=0)
	# progress.update()
	tableregex = re.compile('^\*\*(Table .*)\*\*')
	
@@ -103,7 +103,7 @@ def replaceTableCaptions(progress:Progress, mdLines:list[str]) -> list[str]:
def replaceFigureCaptions(progress:Progress, mdLines:list[str]) -> list[str]:
	"""	Replace figure captions with a pandoc figure caption.
	"""
	_taskID = progress.add_task('[blue]Replacing figure captions', start=False, total=0)
	_taskID = progress.add_task('[blue]Replacing figure captions', total=0)
	# progress.update()
	figureregex = re.compile('^\*\*(Figure .*)\*\*')
	nocaptionfigureregex = re.compile('!\[~~CAPTION~~\].*')
@@ -130,9 +130,9 @@ def replaceFigureCaptions(progress:Progress, mdLines:list[str]) -> list[str]:
def replaceLineBreaks(progress: Progress, mdLines: list[str]) -> list[str]:
	"""	Replace <br /> linebreaks by pandoc escaped_line_breaks extension \(newline).
	"""
	_taskID = progress.add_task('[blue]Replacing linebreaks', start=False, total=0)
	_taskID = progress.add_task('[blue]Replacing linebreaks', total=0)
	# progress.update()
	linebreaksregex = re.compile('<br\s*/?\s*>')
	linebreaksregex = re.compile('<\s*br\s*/?\s*>')

	_lines: list[str] = []
	_inCodeBlock = False