From 23c13b306087696c1a5f52fbb60325a8ee1b5248 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Mon, 3 Nov 2025 13:14:48 -1000 Subject: [PATCH] Handle ulink in docs --- .../mkdocstrings_handlers/cxx/__init__.py | 41 ++++++++++++------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/support/python/mkdocstrings_handlers/cxx/__init__.py b/support/python/mkdocstrings_handlers/cxx/__init__.py index 64f9aea6..2f057941 100644 --- a/support/python/mkdocstrings_handlers/cxx/__init__.py +++ b/support/python/mkdocstrings_handlers/cxx/__init__.py @@ -34,8 +34,6 @@ tag_map = { 'emphasis': 'em', 'computeroutput': 'code', 'para': 'p', - 'programlisting': 'pre', - 'verbatim': 'pre', 'itemizedlist': 'ul', 'listitem': 'li' } @@ -52,24 +50,37 @@ def escape_html(s: str) -> str: return s.replace("<", "<") +# Converts a node from doxygen to HTML format. +def convert_node(node: ElementTree.Element, tag: str, attrs: dict = {}): + out = '<' + tag + for key, value in attrs.items(): + out += ' ' + key + '="' + value + '"' + out += '>' + if node.text: + out += escape_html(node.text) + out += doxyxml2html(list(node)) + out += '' + if node.tail: + out += node.tail + return out + + def doxyxml2html(nodes: List[ElementTree.Element]): out = '' for n in nodes: tag = tag_map.get(n.tag) if tag: - out += '<' + tag + '>' - elif n.tag == 'ulink': - out += '' - else: - out += tag_text_map[n.tag] - out += '' if tag == 'pre' else '' - if n.text: - out += escape_html(n.text) - out += doxyxml2html(list(n)) - out += '' if tag == 'pre' else '' - out += '' if tag else '' - if n.tail: - out += n.tail + out += convert_node(n, tag) + continue + if n.tag == 'programlisting' or n.tag == 'verbatim': + out += '
'
+            out += convert_node(n, 'code', {'class': 'language-cpp'})
+            out += '
' + continue + if n.tag == 'ulink': + out += convert_node(n, 'a', {'href': n.attrib['url']}) + continue + out += tag_text_map[n.tag] return out