Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions mkdoxy/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"operator<<=",
"operator>>=",
"operator[]",
"operator()",
"operator*",
"operator&",
"operator->",
Expand Down
2 changes: 1 addition & 1 deletion mkdoxy/markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def escape(s: str) -> str:
ret = ret.replace("_", "\\_")
ret = ret.replace("<", "&lt;")
ret = ret.replace(">", "&gt;")
return ret.replace("|", "\|")
return ret.replace("|", "\\|")


class MdRenderer:
Expand Down
25 changes: 22 additions & 3 deletions mkdoxy/node.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
import os
import re
from xml.etree import ElementTree
from xml.etree.ElementTree import Element as Element

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

@property
def operator_num(self) -> int:
stem = "operator" + ("-" * self._name.count("-"))
total = 0
for child in self.parent.children:
if child.is_function and child.name.replace(" ", "") in OVERLOAD_OPERATORS:
child_refid = child.name.replace(" ", "")
# Check if the child is a displayed operator by ensuring:
# 1. Its identifier is in the predefined OVERLOAD_OPERATORS list.
# 2. It starts with the expected 'stem' derived from the parent's naming.
# 3. It does not start with an extra hyphen (stem+'-') to avoid excessive matching.
# 4. It is not private.
if (
child.is_function
and child_refid in OVERLOAD_OPERATORS
and child_refid.startswith(stem)
and not child_refid.startswith(stem + "-")
and child._visibility != Visibility.PRIVATE
):
total += 1
if child.refid == self._refid:
break
Expand All @@ -454,14 +468,19 @@ def operator_num(self) -> int:
@property
def name_url_safe(self) -> str:
name = self.name_tokens[-1]
return name.replace(" ", "-").replace("=", "").replace("~", "").lower()
# Strip special characters that do not appear in anchors
name = re.sub("[=~.,<>]", "", name)
return name.strip(" ").replace(" ", "-").lower()

@property
def anchor(self) -> str:
name = ""
if self._name.replace(" ", "") in OVERLOAD_OPERATORS:
num = self.operator_num
name = f"operator_{str(self.operator_num - 1)}" if num > 1 else "operator"
if self._name.startswith("operator-"):
name = f"operator-_{str(num - 1)}" if num > 1 else "operator-"
else:
name = f"operator_{str(num - 1)}" if num > 1 else "operator"
elif self.is_overloaded:
name = f"{self.name_url_safe}-{str(self.overload_num)}{str(self.overload_total)}"
else:
Expand Down
Loading