Skip to content

Commit

Permalink
Merge pull request #105 from Nerixyz/fix/inherited-links
Browse files Browse the repository at this point in the history
  • Loading branch information
JakubAndrysek authored May 11, 2024
2 parents 78f261d + bced434 commit ae20023
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 48 deletions.
23 changes: 12 additions & 11 deletions mkdoxy/doxygen.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from mkdoxy.cache import Cache
from mkdoxy.constants import Kind, Visibility
from mkdoxy.node import Node
from mkdoxy.project import ProjectContext
from mkdoxy.xml_parser import XmlParser

log: logging.Logger = logging.getLogger("mkdocs")
Expand All @@ -19,13 +20,13 @@ def __init__(self, index_path: str, parser: XmlParser, cache: Cache):
xml = ElementTree.parse(path_xml).getroot()

self.parser = parser
self.cache = cache
self.ctx = ProjectContext(cache)

self.root = Node("root", None, self.cache, self.parser, None)
self.groups = Node("root", None, self.cache, self.parser, None)
self.files = Node("root", None, self.cache, self.parser, None)
self.pages = Node("root", None, self.cache, self.parser, None)
self.examples = Node("root", None, self.cache, self.parser, None)
self.root = Node("root", None, self.ctx, self.parser, None)
self.groups = Node("root", None, self.ctx, self.parser, None)
self.files = Node("root", None, self.ctx, self.parser, None)
self.pages = Node("root", None, self.ctx, self.parser, None)
self.examples = Node("root", None, self.ctx, self.parser, None)

for compound in xml.findall("compound"):
kind = Kind.from_str(compound.get("kind"))
Expand All @@ -34,7 +35,7 @@ def __init__(self, index_path: str, parser: XmlParser, cache: Cache):
node = Node(
os.path.join(index_path, f"{refid}.xml"),
None,
self.cache,
self.ctx,
self.parser,
self.root,
)
Expand All @@ -44,7 +45,7 @@ def __init__(self, index_path: str, parser: XmlParser, cache: Cache):
node = Node(
os.path.join(index_path, f"{refid}.xml"),
None,
self.cache,
self.ctx,
self.parser,
self.root,
)
Expand All @@ -54,7 +55,7 @@ def __init__(self, index_path: str, parser: XmlParser, cache: Cache):
node = Node(
os.path.join(index_path, f"{refid}.xml"),
None,
self.cache,
self.ctx,
self.parser,
self.root,
)
Expand All @@ -64,7 +65,7 @@ def __init__(self, index_path: str, parser: XmlParser, cache: Cache):
node = Node(
os.path.join(index_path, f"{refid}.xml"),
None,
self.cache,
self.ctx,
self.parser,
self.root,
)
Expand All @@ -74,7 +75,7 @@ def __init__(self, index_path: str, parser: XmlParser, cache: Cache):
node = Node(
os.path.join(index_path, f"{refid}.xml"),
None,
self.cache,
self.ctx,
self.parser,
self.root,
)
Expand Down
32 changes: 15 additions & 17 deletions mkdoxy/generatorSnippets.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def incorrect_argument(self, project: str, argument: str, config: dict, snippet:
project,
config,
f"Incorrect argument: {argument}" if argument else f"Add argument to snippet: {project}",
f"Argument have to be based on this diagram → **:::doxy.{project}.<argument\>**",
f"Argument have to be based on this diagram → **:::doxy.{project}.<argument\\>**",
"A list of available arguments:",
"\n".join(self.doxy_arguments.keys()),
"yaml",
Expand All @@ -162,14 +162,12 @@ def incorrect_argument(self, project: str, argument: str, config: dict, snippet:
def replace_markdown(self, start: int, end: int, replacement: str):
self.markdown = self.markdown[:start] + replacement + "\n" + self.markdown[end:]

def _recurs_setLinkPrefixNode(self, node: Node, linkPrefix: str):
node.setLinkPrefix(linkPrefix)
if node.kind.is_parent():
self._recurs_setLinkPrefixNodes(node.children, linkPrefix)
def _setLinkPrefixNode(self, node: Node, linkPrefix: str):
node.project.linkPrefix = linkPrefix

def _recurs_setLinkPrefixNodes(self, nodes: [Node], linkPrefix: str):
for node in nodes:
self._recurs_setLinkPrefixNode(node, linkPrefix)
def _setLinkPrefixNodes(self, nodes: list[Node], linkPrefix: str):
if nodes:
nodes[0].project.linkPrefix = linkPrefix

def is_project_exist(self, project: str):
return project in self.projects
Expand Down Expand Up @@ -249,7 +247,7 @@ def doxyCode(self, snippet, project: str, config):
f"{snippet}",
"yaml",
)
self._recurs_setLinkPrefixNode(node, self.pageUrlPrefix + project + "/")
self._setLinkPrefixNode(node, self.pageUrlPrefix + project + "/")
return self.generatorBase[project].code(node, config, progCode)
return self.doxyError(
project,
Expand Down Expand Up @@ -281,7 +279,7 @@ def doxyFunction(self, snippet, project: str, config: dict):
return self.doxyNodeIsNone(project, config, snippet)

if isinstance(node, Node):
self._recurs_setLinkPrefixNode(node, self.pageUrlPrefix + project + "/")
self._setLinkPrefixNode(node, self.pageUrlPrefix + project + "/")
return self.generatorBase[project].function(node, config)
return self.doxyError(
project,
Expand All @@ -304,7 +302,7 @@ def doxyClass(self, snippet, project: str, config: dict):
return self.doxyNodeIsNone(project, config, snippet)

if isinstance(node, Node):
self._recurs_setLinkPrefixNode(node, self.pageUrlPrefix + project + "/")
self._setLinkPrefixNode(node, self.pageUrlPrefix + project + "/")
return self.generatorBase[project].member(node, config)
return self.doxyError(
project,
Expand All @@ -327,7 +325,7 @@ def doxyClassMethod(self, snippet, project: str, config):
return self.doxyNodeIsNone(project, config, snippet)

if isinstance(node, Node):
self._recurs_setLinkPrefixNode(node, self.pageUrlPrefix + project + "/")
self._setLinkPrefixNode(node, self.pageUrlPrefix + project + "/")
return self.generatorBase[project].function(node, config)
return self.doxyError(
project,
Expand All @@ -345,39 +343,39 @@ def doxyClassList(self, snippet, project: str, config):
if errorMsg:
return errorMsg
nodes = self.doxygen[project].root.children
self._recurs_setLinkPrefixNodes(nodes, self.pageUrlPrefix + project + "/")
self._setLinkPrefixNodes(nodes, self.pageUrlPrefix + project + "/")
return self.generatorBase[project].annotated(nodes, config)

def doxyClassIndex(self, snippet, project: str, config):
errorMsg = self.checkConfig(snippet, project, config, [])
if errorMsg:
return errorMsg
nodes = self.doxygen[project].root.children
self._recurs_setLinkPrefixNodes(nodes, self.pageUrlPrefix + project + "/")
self._setLinkPrefixNodes(nodes, self.pageUrlPrefix + project + "/")
return self.generatorBase[project].classes(nodes, config)

def doxyClassHierarchy(self, snippet, project: str, config):
errorMsg = self.checkConfig(snippet, project, config, [])
if errorMsg:
return errorMsg
nodes = self.doxygen[project].root.children
self._recurs_setLinkPrefixNodes(nodes, self.pageUrlPrefix + project + "/")
self._setLinkPrefixNodes(nodes, self.pageUrlPrefix + project + "/")
return self.generatorBase[project].hierarchy(nodes, config)

def doxyNamespaceList(self, snippet, project: str, config):
errorMsg = self.checkConfig(snippet, project, config, [])
if errorMsg:
return errorMsg
nodes = self.doxygen[project].root.children
self._recurs_setLinkPrefixNodes(nodes, self.pageUrlPrefix + project + "/")
self._setLinkPrefixNodes(nodes, self.pageUrlPrefix + project + "/")
return self.generatorBase[project].namespaces(nodes, config)

def doxyFileList(self, snippet, project: str, config):
errorMsg = self.checkConfig(snippet, project, config, [])
if errorMsg:
return errorMsg
nodes = self.doxygen[project].files.children
self._recurs_setLinkPrefixNodes(nodes, self.pageUrlPrefix + project + "/")
self._setLinkPrefixNodes(nodes, self.pageUrlPrefix + project + "/")
return self.generatorBase[project].fileindex(nodes, config)

def doxyNodeIsNone(self, project: str, config: dict, snippet: str) -> str:
Expand Down
35 changes: 16 additions & 19 deletions mkdoxy/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
from xml.etree import ElementTree
from xml.etree.ElementTree import Element as Element

from mkdoxy.cache import Cache
from mkdoxy.constants import OVERLOAD_OPERATORS, Kind, Visibility
from mkdoxy.markdown import escape
from mkdoxy.project import ProjectContext
from mkdoxy.property import Property
from mkdoxy.utils import split_safe
from mkdoxy.xml_parser import XmlParser
Expand All @@ -18,18 +18,18 @@ def __init__(
self,
xml_file: str,
xml: Element,
cache: Cache,
project: ProjectContext,
parser: XmlParser,
parent: "Node",
refid: str = None,
debug: bool = False,
):
self._children: ["Node"] = []
self._cache: Cache = cache
self._cache = project.cache
self._parser: XmlParser = parser
self._parent = parent
self.debug = debug
self.linkPrefix = ""
self.project = project

if xml_file == "root":
self._refid = "root"
Expand Down Expand Up @@ -91,9 +91,6 @@ def __init__(
def __repr__(self):
return f"Node: {self.name} refid: {self._refid}"

def setLinkPrefix(self, linkPrefix: str):
self.linkPrefix = linkPrefix

def add_child(self, child: "Node"):
self._children.append(child)

Expand All @@ -113,7 +110,7 @@ def _check_for_children(self):
child = Node(
os.path.join(self._dirname, f"{refid}.xml"),
None,
self._cache,
self.project,
self._parser,
self,
)
Expand All @@ -138,15 +135,15 @@ def _check_for_children(self):
child = Node(
os.path.join(self._dirname, f"{refid}.xml"),
None,
self._cache,
self.project,
self._parser,
self,
)
except FileNotFoundError:
child = Node(
os.path.join(self._dirname, f"{refid}.xml"),
Element("compounddef"),
self._cache,
self.project,
self._parser,
self,
refid=refid,
Expand All @@ -168,7 +165,7 @@ def _check_for_children(self):
child = Node(
os.path.join(self._dirname, f"{refid}.xml"),
None,
self._cache,
self.project,
self._parser,
self,
)
Expand All @@ -188,7 +185,7 @@ def _check_for_children(self):
child = Node(
os.path.join(self._dirname, f"{refid}.xml"),
None,
self._cache,
self.project,
self._parser,
self,
)
Expand All @@ -209,7 +206,7 @@ def _check_for_children(self):
child = Node(
os.path.join(self._dirname, f"{refid}.xml"),
None,
self._cache,
self.project,
self._parser,
self,
)
Expand All @@ -228,7 +225,7 @@ def _check_for_children(self):
continue
except Exception:
pass
child = Node(None, memberdef, self._cache, self._parser, self)
child = Node(None, memberdef, self.project, self._parser, self)
self.add_child(child)

# for detaileddescription in self._xml.findall('detaileddescription'):
Expand Down Expand Up @@ -477,14 +474,14 @@ def anchor(self) -> str:
@property
def url(self) -> str:
if self.is_parent or self.is_group or self.is_file or self.is_dir or self.is_page:
return self.linkPrefix + self._refid + ".md"
return self.project.linkPrefix + self._refid + ".md"
else:
return f"{self._parent.url}#{self.anchor}"

@property
def base_url(self) -> str:
def prefix(page: str):
return self.linkPrefix + page
return self.project.linkPrefix + page

if self.is_group:
return prefix("modules.md")
Expand All @@ -509,13 +506,13 @@ def base_name(self) -> str:
@property
def url_source(self) -> str:
if self.is_parent or self.is_group or self.is_file or self.is_dir:
return self.linkPrefix + self._refid + "_source.md"
return self.project.linkPrefix + self._refid + "_source.md"
else:
return self.linkPrefix + self._refid + ".md"
return self.project.linkPrefix + self._refid + ".md"

@property
def filename(self) -> str:
return self.linkPrefix + self._refid + ".md"
return self.project.linkPrefix + self._refid + ".md"

@property
def root(self) -> "Node":
Expand Down
7 changes: 7 additions & 0 deletions mkdoxy/project.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from mkdoxy.cache import Cache


class ProjectContext:
def __init__(self, cache: Cache) -> None:
self.cache = cache
self.linkPrefix: str = ""
2 changes: 1 addition & 1 deletion mkdoxy/templates/memTab.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ See [{{node.name_long}}]({{node.url}})
{%- elif member.is_class or member.is_interface or member.is_struct -%}
| {{member.kind.value}} | [**{{member.name_long if node.is_group else member.name_short}}**]({{member.url}}) {{member.suffix}}<br>{{member.brief}} |
{%- elif member.is_enum or member.is_function or member.is_variable or member.is_union or member.is_typedef -%}
| {{member.prefix}} {{member.type}} | [**{{member.name_long if node.is_group else member.name_short}}**](#{{member.anchor}}) {{member.params}} {{member.suffix}}<br>{{member.brief}} |
| {{member.prefix}} {{member.type}} | [**{{member.name_long if node.is_group else member.name_short}}**]({%- if parent %}{{member.url}}{%- else -%}#{{member.anchor}}{%- endif -%}) {{member.params}} {{member.suffix}}<br>{{member.brief}} |
{%- else -%}
| {{member.prefix}} {{member.type}} | [**{{member.name_long if node.is_group else member.name_short}}**]({{member.url}}) {{member.params}} {{member.suffix}}<br>{{member.brief}} |
{%- endif %}
Expand Down

0 comments on commit ae20023

Please sign in to comment.