Commit 19a20723 authored by Naum Spaseski's avatar Naum Spaseski Committed by Miguel Angel Reina Ortega
Browse files

Corrected internal links generation

parent c7254b09
Loading
Loading
Loading
Loading
Loading
+6 −4
Original line number Original line Diff line number Diff line
@@ -953,17 +953,19 @@ def processDocuments(documents:list[str],
			#	Map internal references
			#	Map internal references
			#
			#
			_definitionExpression = re.compile(r'^[`]?\[([\d]+|i.[\d]+)\]([^`]*)[`]?')
			_definitionExpression = re.compile(r'^[`]?\[([\d]+|i.[\d]+)\]([^`]*)[`]?')
			_referenceExpression = re.compile(r'([^>])\[([\d]+|i.[\d]+)\](?!</a>)')
			_referenceExpression = re.compile(r'([^>])\[([\d]+|i.[\d]+)\](?!</a>|\(#_ref_)')


			for i in range(len(lines)):
			for i in range(len(lines)):
				line = lines[i]
				line = lines[i]
				if (m := _definitionExpression.match(line)) is not None:
				if (m := _definitionExpression.match(line)) is not None:
					lines[i] = f'- <a name="_ref_{m.group(1)}"[{m.group(1)}]">[{m.group(1)}]</a>{m.group(2)}'
					# Use HTML anchor for definitions with span wrapper: <span id="_ref_1"><a name="_ref_1">[1]</a></span>
					lines[i] = f'- <span id="_ref_{m.group(1)}"><a name="_ref_{m.group(1)}">[{m.group(1)}]</a></span>{m.group(2)}'
			
			
			def _repl(m:re.Match) -> str|None:
			def _repl(m:re.Match) -> str|None:
				if m.group(1) == '"':
				if m.group(1) == '"':
					return None
					return None
				return f'{m.group(1)}<a href="#_ref_{m.group(2)}">[{m.group(2)}]</a>'
				# Use markdown link format: [\[1\]](#_ref_1)
				return f'{m.group(1)}[\\[{m.group(2)}\\]](#_ref_{m.group(2)})'


			for i in range(len(lines)):
			for i in range(len(lines)):
				line = lines[i]
				line = lines[i]
@@ -1063,7 +1065,7 @@ def processDocuments(documents:list[str],
						_print(f'Converting EMF file: {fn} to "{format}"', highlight = False)
						_print(f'Converting EMF file: {fn} to "{format}"', highlight = False)
						if (res := subprocess.run(cmd, shell = True, capture_output = True)).returncode != 0:
						if (res := subprocess.run(cmd, shell = True, capture_output = True)).returncode != 0:
							_print(f'[red]Error running command: {res.stderr.decode("utf-8")}')
							_print(f'[red]Error running command: {res.stderr.decode("utf-8")}')
							_print(f'[red]Please check the configuration file -> section "\[media]" for the converter command: {converter}')
							_print(f'[red]Please check the configuration file -> section "[media]" for the converter command: {converter}')
							break
							break


			if not skipImageConversion:
			if not skipImageConversion: