mirror of
https://github.com/fmtlib/fmt.git
synced 2024-11-09 12:50:05 +00:00
Improve apidoc formatting
This commit is contained in:
parent
933d8ba352
commit
e5c07c8356
@ -1,3 +1,4 @@
|
|||||||
document$.subscribe(() => {
|
document$.subscribe(() => {
|
||||||
hljs.highlightAll()
|
hljs.highlightAll(),
|
||||||
|
{ language: 'c++' }
|
||||||
})
|
})
|
||||||
|
@ -28,6 +28,9 @@ tag_text_map = {
|
|||||||
'sp': ' '
|
'sp': ' '
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def escape_html(s: str) -> str:
|
||||||
|
return s.replace("<", "<")
|
||||||
|
|
||||||
def doxyxml2html(nodes: list[et.Element]):
|
def doxyxml2html(nodes: list[et.Element]):
|
||||||
out = ''
|
out = ''
|
||||||
for n in nodes:
|
for n in nodes:
|
||||||
@ -35,9 +38,9 @@ def doxyxml2html(nodes: list[et.Element]):
|
|||||||
if not tag:
|
if not tag:
|
||||||
out += tag_text_map[n.tag]
|
out += tag_text_map[n.tag]
|
||||||
out += '<' + tag + '>' if tag else ''
|
out += '<' + tag + '>' if tag else ''
|
||||||
out += '<code>' if tag == 'pre' else ''
|
out += '<code class="language-cpp">' if tag == 'pre' else ''
|
||||||
if n.text:
|
if n.text:
|
||||||
out += n.text
|
out += escape_html(n.text)
|
||||||
out += doxyxml2html(n)
|
out += doxyxml2html(n)
|
||||||
out += '</code>' if tag == 'pre' else ''
|
out += '</code>' if tag == 'pre' else ''
|
||||||
out += '</' + tag + '>' if tag else ''
|
out += '</' + tag + '>' if tag else ''
|
||||||
@ -65,9 +68,6 @@ def clean_type(type: str) -> str:
|
|||||||
type = type.replace('< ', '<').replace(' >', '>')
|
type = type.replace('< ', '<').replace(' >', '>')
|
||||||
return type.replace(' &', '&').replace(' *', '*')
|
return type.replace(' &', '&').replace(' *', '*')
|
||||||
|
|
||||||
def render_type(type: str) -> str:
|
|
||||||
return type.replace("<", "<")
|
|
||||||
|
|
||||||
def convert_param(param: et.Element) -> Definition:
|
def convert_param(param: et.Element) -> Definition:
|
||||||
d = Definition(param.find('declname').text)
|
d = Definition(param.find('declname').text)
|
||||||
type = param.find('type')
|
type = param.find('type')
|
||||||
@ -175,7 +175,7 @@ class CxxHandler(BaseHandler):
|
|||||||
|
|
||||||
def render(self, d: Definition, config: dict) -> str:
|
def render(self, d: Definition, config: dict) -> str:
|
||||||
text = '<div class="docblock">\n'
|
text = '<div class="docblock">\n'
|
||||||
text += '<pre><code>'
|
text += '<pre><code class="language-cpp">'
|
||||||
if d.template_params is not None:
|
if d.template_params is not None:
|
||||||
text += 'template <'
|
text += 'template <'
|
||||||
text += ', '.join(
|
text += ', '.join(
|
||||||
@ -184,15 +184,14 @@ class CxxHandler(BaseHandler):
|
|||||||
text += d.type + ' ' + d.name
|
text += d.type + ' ' + d.name
|
||||||
if d.params is not None:
|
if d.params is not None:
|
||||||
params = ', '.join(
|
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 + ')'
|
text += '(' + params + ')'
|
||||||
if d.trailing_return_type:
|
if d.trailing_return_type:
|
||||||
text += ' -> ' + render_type(d.trailing_return_type)
|
text += ' -> ' + escape_html(d.trailing_return_type)
|
||||||
text += ';'
|
text += ';'
|
||||||
text += '</code></pre>\n'
|
text += '</code></pre>\n'
|
||||||
text += '<div class="docblock-desc">\n'
|
text += '<div class="docblock-desc">\n'
|
||||||
desc = doxyxml2html(d.desc)
|
text += doxyxml2html(d.desc)
|
||||||
text += desc
|
|
||||||
text += '</div>\n'
|
text += '</div>\n'
|
||||||
text += '</div>\n'
|
text += '</div>\n'
|
||||||
return text
|
return text
|
||||||
|
Loading…
Reference in New Issue
Block a user