diff --git a/tools/generate_dynamic_docs.py b/tools/generate_dynamic_docs.py index 92e65cc..4b79315 100644 --- a/tools/generate_dynamic_docs.py +++ b/tools/generate_dynamic_docs.py @@ -12,6 +12,40 @@ import html import re from pathlib import Path +def transform_doc_links(docstring, format='html', base_url=''): + """Transform MCRF_LINK patterns based on output format. + + Detects pattern: "See also: TEXT (docs/path.md)" + Transforms to appropriate format for output type. + """ + if not docstring: + return docstring + + link_pattern = r'See also: ([^(]+) \(([^)]+)\)' + + def replace_link(match): + text, ref = match.group(1).strip(), match.group(2).strip() + + if format == 'html': + # Convert docs/foo.md → foo.html + href = ref.replace('docs/', '').replace('.md', '.html') + return f'

See also: {text}

' + + elif format == 'web': + # Link to hosted docs + web_path = ref.replace('docs/', '').replace('.md', '') + return f'

See also: {text}

' + + elif format == 'markdown': + # Markdown link + return f'\n**See also:** [{text}]({ref})' + + else: # 'python' or default + # Keep as plain text for Python docstrings + return match.group(0) + + return re.sub(link_pattern, replace_link, docstring) + # Must be run with McRogueFace as interpreter try: import mcrfpy @@ -304,8 +338,9 @@ def generate_html_docs(): html_content += f"""

{func_name}{parsed['signature'] if parsed['signature'] else '(...)'}

-

{html.escape(parsed['description'])}

""" + description = transform_doc_links(parsed['description'], format='html') + html_content += f"

{description}

\n" if parsed['args']: html_content += "

Arguments:

\n