diff --git a/spec2md.py b/spec2md.py index c2f9d581ec51e7f5d2fcbe129a63be814e6572ee..99c8429c8521fc4ce66b328f8ecfb21eb4eaad32 100644 --- a/spec2md.py +++ b/spec2md.py @@ -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]+)\](?!)') + _referenceExpression = re.compile(r'([^>])\[([\d]+|i.[\d]+)\](?!|\(#_ref_)') for i in range(len(lines)): line = lines[i] if (m := _definitionExpression.match(line)) is not None: - lines[i] = f'- [{m.group(1)}]{m.group(2)}' + # Use HTML anchor for definitions with span wrapper: [1] + lines[i] = f'[{m.group(1)}] {m.group(2).strip()}' def _repl(m:re.Match) -> str|None: if m.group(1) == '"': return None - return f'{m.group(1)}[{m.group(2)}]' + # 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: