Commit 219e4c8a authored by Miguel Angel Reina Ortega's avatar Miguel Angel Reina Ortega
Browse files

fix for indented table caption

parent de59f62a
Loading
Loading
Loading
Loading
Loading
+11 −8
Changes for generateBaseline/pandocFilter.py: 11 added lines, 8 removed lines.
Original line number Diff line number Diff line
@@ -261,28 +261,31 @@ def replaceTableCaptions(progress:Progress, mdLines:list[str]) -> list[str]:
	_taskID = progress.add_task('[blue]Replacing table captions', total=0)
	resetCodeBlockState()
	# progress.update()
	tableregex = re.compile('^\*\*(Table .*)\*\*')
	tableregex = re.compile(r'^([ \t]*)\*\*(Table .*)\*\*')
	
	_lines:list[str] = []
	for line in mdLines:
		matches = re.findall(tableregex, line)
		_inCodeBlock = checkInCodeBlock(line)
		if _inCodeBlock:
			_lines.append(line)
			continue
		if matches:
			raw_rest = line.replace(matches[0], '')
		match = tableregex.match(line)
		if match:
			indent = match.group(1)
			caption = match.group(2)
			raw_rest = line.replace(match[0], '')
			cleaned_rest = _TARGET_ANCHOR.sub('', raw_rest)
			if cleaned_rest != raw_rest:
				print(f'Removed table anchor markup from caption: {matches[0]}')
				print(f'Removed table anchor markup from caption: {caption}')
			rest_of_line = cleaned_rest.strip().lstrip('*')
			# move the caption to the beginning of the table and add a "Table:" prefix
			# Keep the caption's indent. Move it to the beginning of the table
			# and add a "Table:" prefix.
			_idx = len(_lines) - 1
			while _idx >= 0 and _lines[_idx].startswith('|'):
				_idx -= 1
			#if _idx > 0:
			#	_lines.insert(_idx+1, f'Table: {matches[0]}\n')
			_lines.insert(_idx+1, f'Table: {matches[0]}{rest_of_line}\n')
			#	_lines.insert(_idx+1, f'Table: {caption}\n')
			_lines.insert(_idx+1, f'{indent}Table: {caption}{rest_of_line}\n')
		else:
			_lines.append(line)