Commit 088a94e4 authored by Miguel Angel Reina Ortega's avatar Miguel Angel Reina Ortega
Browse files

Add replacement of bulleted letters lists (remove the preceding dash)

parent 1c038dc4
Loading
Loading
Loading
Loading
Loading
+35 −6
Original line number Diff line number Diff line
@@ -297,7 +297,7 @@ def instertLineAfterTableOrCodeBlock(progress:Progress, mdLines:list[str]) -> li
		if matchCodefenceEnd.match(line):
			inCodefence = False
			_lines.append(line)
			_lines.append(f'\n') # insert a blank line after the code block
			_lines.append("<br />") # insert a blank line after the code block
			continue
		if inCodefence:
			_lines.append(line)
@@ -320,7 +320,8 @@ def instertLineAfterTableOrCodeBlock(progress:Progress, mdLines:list[str]) -> li
				inTable = False
				tableHasSeparator = False
				# Mark the previous line as the last row in the table
				_lines.append(f'\n') # insert a blank line after the table
				_lines.append("<br />") # insert a blank line after the table
				continue
				# continue with other matches

		#Detect grid tables and convert them to html table
@@ -343,7 +344,8 @@ def instertLineAfterTableOrCodeBlock(progress:Progress, mdLines:list[str]) -> li
			else:
				inGridTable = False
				#processGridTable()
				_lines.append(f'\n') # insert a blank line after the grid table
				_lines.append("<br />") # insert a blank line after the grid table
				continue
		# continue with other matches

		# Detect notes
@@ -353,10 +355,10 @@ def instertLineAfterTableOrCodeBlock(progress:Progress, mdLines:list[str]) -> li
			_lines.append(line)
			continue
		# Note ends with a blank line
		if inNote and line == '\n':
		if inNote and line == "":
			inNote = False
			_lines.append(line)
			_lines.append(f'\n') # insert a blank line after the note
			_lines.append("<br />") # insert a blank line after the note
			continue
		if inNote:
			_lines.append(line)
@@ -368,6 +370,32 @@ def instertLineAfterTableOrCodeBlock(progress:Progress, mdLines:list[str]) -> li
	progress.stop_task(_taskID)
	return _lines


def replaceBulletedLettersLists(progress:Progress, mdLines:list[str]) -> list[str]:
	"""	Replace bulleted letters lists with numbered lists.
	"""
	_taskID = progress.add_task('[blue]Replacing bulleted letters lists', total=0)
	# progress.update()
	
	# Match "- " only when followed by a letter and ")" (e.g. "- a) text").
	bulletedLettersListRegex = re.compile(r'^([ \t]*)- (?=[A-Za-z]+\))')
	_lines:list[str] = []
	for line in mdLines:
		# If we are in a code block, we are not in a list
		if checkInCodeBlock(line):
			_lines.append(line)
			continue

		if (m := bulletedLettersListRegex.match(line)):
			# Keep indentation and remove only "- ".
			_lines.append(f'{m.group(1)}{line[m.end():]}')
		else:
			_lines.append(line)

	#print(f'{_lines}')
	progress.stop_task(_taskID)
	return _lines

def process(args) -> None:
	with Progress(TextColumn('{task.description}'),  TimeElapsedColumn()) as progress:
		mdLines = readMDFile(progress, args.document)
@@ -376,11 +404,12 @@ def process(args) -> None:
		mdLines = replaceFigureCaptions(progress, mdLines)
		if args.figure_paths:
			mdLines = replaceFiguresPathSvgToPng(progress, mdLines)
		mdLines = replaceLineBreaks(progress, mdLines)
		if args.table_separators:
			mdLines = correctTableSeparators(progress, mdLines)
		mdLines = instertLineBeforeStartOfList(progress, mdLines)
		mdLines = replaceBulletedLettersLists(progress, mdLines)
		#mdLines = instertLineAfterTableOrCodeBlock(progress, mdLines)
		mdLines = replaceLineBreaks(progress, mdLines)
		writeMDFile(progress, mdLines, args.document, args.outDirectory)