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

Merge branch 'correctLinks' into 'main'

Corrected internal links generation

See merge request !2
parents 91afbe99 c2efcd51
Loading
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -953,17 +953,19 @@ def processDocuments(documents:list[str],
			#	Map internal references
			#
			_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)):
				line = lines[i]
				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)}"></span><a name="_ref_{m.group(1)}">[{m.group(1)}]</a> {m.group(2).strip()}'
			
			def _repl(m:re.Match) -> str|None:
				if m.group(1) == '"':
					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)):
				line = lines[i]
@@ -1063,7 +1065,7 @@ def processDocuments(documents:list[str],
						_print(f'Converting EMF file: {fn} to "{format}"', highlight = False)
						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]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

			if not skipImageConversion: