summaryrefslogtreecommitdiff
path: root/docs/doxygen_filter.py
blob: ed6e6e889466efe95cf74be8ce7f79a9a430640a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/usr/bin/env python3
"""Resolve repository source links to Doxygen reference/example pages.

Markdown keeps ordinary relative links for repository and installed-document
readers. Doxygen gets @ref links so its standalone HTML has no source-tree URLs.
"""

from pathlib import Path
import re
import sys

text = Path(sys.argv[1]).read_text(encoding="utf-8")


def reference(match):
    label, target = match.groups()
    if target.startswith("../include/yasl/") and target.endswith(".h"):
        return f"[{label}](@ref {Path(target).name})"
    if target.startswith("../examples/") and target.endswith(".c"):
        return f"[{label}](@ref {Path(target).name})"
    return match.group(0)


sys.stdout.write(re.sub(r"\[([^\]]+)\]\(([^)]+)\)", reference, text))