diff --git a/generateChangemarks/pandocFilter.py b/generateChangemarks/pandocFilter.py
index a07b778f87588a8ba801cb18f39aa6fbbb77a006..41b6ca57a29cd69e397036c6cafdf168119044b0 100644
--- a/generateChangemarks/pandocFilter.py
+++ b/generateChangemarks/pandocFilter.py
@@ -65,6 +65,8 @@ def correctTOC(progress:Progress, mdLines:list[str], tocSection:str = 'Contents'
 			if matches:
 				_lines.append(f'{matches[0]}  \n')
 				continue
+			else:
+				_lines.append(line)
 		else:
 			_lines.append(line)
 
@@ -112,11 +114,10 @@ def replaceFigureCaptions(progress:Progress, mdLines:list[str]) -> list[str]:
 		if matches:
 			# Replace the previous figure markdown name with the captions
 			_idx = len(_lines) - 1
-			while _idx >= 0 and not _lines[_idx].startswith('!['):
+			while _idx >= 0 and _lines[_idx].count('![') == 0:
 				_idx -= 1
 			if _idx > 0:
-				_lines[_idx] = re.sub(r'^.*?]', f'![{matches[0]}]', _lines[_idx])
-
+				_lines[_idx] = re.sub(r'!.*]', f'![{matches[0]}]', _lines[_idx])
 		elif re.findall(nocaptionfigureregex, line):
 			_lines.append(re.sub(r'^.*?]', f'![]', line))
 		else: