diff --git a/doc/fmt.js b/doc/fmt.js index 86e50b93..da7e95b7 100644 --- a/doc/fmt.js +++ b/doc/fmt.js @@ -1,3 +1,4 @@ document$.subscribe(() => { - hljs.highlightAll() + hljs.highlightAll(), + { language: 'c++' } }) diff --git a/support/mkdocstrings_handlers/cxx/__init__.py b/support/mkdocstrings_handlers/cxx/__init__.py index 98e612fc..8b2ebf2b 100644 --- a/support/mkdocstrings_handlers/cxx/__init__.py +++ b/support/mkdocstrings_handlers/cxx/__init__.py @@ -28,6 +28,9 @@ tag_text_map = { 'sp': ' ' } +def escape_html(s: str) -> str: + return s.replace("<", "<") + def doxyxml2html(nodes: list[et.Element]): out = '' for n in nodes: @@ -35,9 +38,9 @@ def doxyxml2html(nodes: list[et.Element]): if not tag: out += tag_text_map[n.tag] out += '<' + tag + '>' if tag else '' - out += '' if tag == 'pre' else '' + out += '' if tag == 'pre' else '' if n.text: - out += n.text + out += escape_html(n.text) out += doxyxml2html(n) out += '' if tag == 'pre' else '' out += '' if tag else '' @@ -65,9 +68,6 @@ def clean_type(type: str) -> str: type = type.replace('< ', '<').replace(' >', '>') return type.replace(' &', '&').replace(' *', '*') -def render_type(type: str) -> str: - return type.replace("<", "<") - def convert_param(param: et.Element) -> Definition: d = Definition(param.find('declname').text) type = param.find('type') @@ -175,7 +175,7 @@ class CxxHandler(BaseHandler): def render(self, d: Definition, config: dict) -> str: text = '
\n' - text += '
'
+    text += '
'
     if d.template_params is not None:
       text += 'template <'
       text += ', '.join(
@@ -184,15 +184,14 @@ class CxxHandler(BaseHandler):
     text += d.type + ' ' + d.name
     if d.params is not None:
       params = ', '.join(
-        [f'{render_type(p.type)} {p.name}' for p in d.params])
+        [f'{escape_html(p.type)} {p.name}' for p in d.params])
       text += '(' + params + ')'
       if d.trailing_return_type:
-        text += ' -> ' + render_type(d.trailing_return_type)
+        text += ' -> ' + escape_html(d.trailing_return_type)
     text += ';'
     text += '
\n' text += '
\n' - desc = doxyxml2html(d.desc) - text += desc + text += doxyxml2html(d.desc) text += '
\n' text += '
\n' return text