| 80 | |
| 81 | def _convert_refs(text: str) -> str: |
| 82 | def repl(match: re.Match[str]) -> str: |
| 83 | raw = match.group(1) |
| 84 | if "<" in raw and raw.endswith(">"): |
| 85 | label, target = raw.split("<", 1) |
| 86 | target = target[:-1] |
| 87 | label = label.replace("\n", " ").strip() |
| 88 | else: |
| 89 | label, target = None, raw.strip() |
| 90 | info = REF_MAP.get(target) |
| 91 | if not info: |
| 92 | return (label or target).replace("\n", " ").strip() |
| 93 | path, anchor = info |
| 94 | if path.endswith(".md"): |
| 95 | if path == "reference/settings.md" and anchor: |
| 96 | href = f"#{anchor}" |
| 97 | else: |
| 98 | href = path + (f"#{anchor}" if anchor else "") |
| 99 | else: |
| 100 | href = path + (f"#{anchor}" if anchor else "") |
| 101 | text = (label or target).replace("\n", " ").strip() |
| 102 | return f"[{text}]({href})" |
| 103 | |
| 104 | return REF_PATTERN.sub(repl, text) |
| 105 | |