Skip to content

Commit 482e2b6

Browse files
Merge pull request #132 from EmilyBourne/ebourne-131-bad-anchors
2 parents 85615c0 + a72dbcc commit 482e2b6

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

mkdoxy/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"operator<<=",
3838
"operator>>=",
3939
"operator[]",
40+
"operator()",
4041
"operator*",
4142
"operator&",
4243
"operator->",

mkdoxy/markdown.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ def escape(s: str) -> str:
66
ret = ret.replace("_", "\\_")
77
ret = ret.replace("<", "&lt;")
88
ret = ret.replace(">", "&gt;")
9-
return ret.replace("|", "\|")
9+
return ret.replace("|", "\\|")
1010

1111

1212
class MdRenderer:

mkdoxy/node.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import logging
22
import os
3+
import re
34
from xml.etree import ElementTree
45
from xml.etree.ElementTree import Element as Element
56

@@ -443,9 +444,22 @@ def operators_total(self) -> int:
443444

444445
@property
445446
def operator_num(self) -> int:
447+
stem = "operator" + ("-" * self._name.count("-"))
446448
total = 0
447449
for child in self.parent.children:
448-
if child.is_function and child.name.replace(" ", "") in OVERLOAD_OPERATORS:
450+
child_refid = child.name.replace(" ", "")
451+
# Check if the child is a displayed operator by ensuring:
452+
# 1. Its identifier is in the predefined OVERLOAD_OPERATORS list.
453+
# 2. It starts with the expected 'stem' derived from the parent's naming.
454+
# 3. It does not start with an extra hyphen (stem+'-') to avoid excessive matching.
455+
# 4. It is not private.
456+
if (
457+
child.is_function
458+
and child_refid in OVERLOAD_OPERATORS
459+
and child_refid.startswith(stem)
460+
and not child_refid.startswith(stem + "-")
461+
and child._visibility != Visibility.PRIVATE
462+
):
449463
total += 1
450464
if child.refid == self._refid:
451465
break
@@ -454,14 +468,19 @@ def operator_num(self) -> int:
454468
@property
455469
def name_url_safe(self) -> str:
456470
name = self.name_tokens[-1]
457-
return name.replace(" ", "-").replace("=", "").replace("~", "").lower()
471+
# Strip special characters that do not appear in anchors
472+
name = re.sub("[=~.,<>]", "", name)
473+
return name.strip(" ").replace(" ", "-").lower()
458474

459475
@property
460476
def anchor(self) -> str:
461477
name = ""
462478
if self._name.replace(" ", "") in OVERLOAD_OPERATORS:
463479
num = self.operator_num
464-
name = f"operator_{str(self.operator_num - 1)}" if num > 1 else "operator"
480+
if self._name.startswith("operator-"):
481+
name = f"operator-_{str(num - 1)}" if num > 1 else "operator-"
482+
else:
483+
name = f"operator_{str(num - 1)}" if num > 1 else "operator"
465484
elif self.is_overloaded:
466485
name = f"{self.name_url_safe}-{str(self.overload_num)}{str(self.overload_total)}"
467486
else:

0 commit comments

Comments
 (0)