mirror of
https://github.com/fmtlib/fmt.git
synced 2025-11-25 11:49:52 +01:00
Handle ulink in docs
This commit is contained in:
@@ -34,8 +34,6 @@ tag_map = {
|
|||||||
'emphasis': 'em',
|
'emphasis': 'em',
|
||||||
'computeroutput': 'code',
|
'computeroutput': 'code',
|
||||||
'para': 'p',
|
'para': 'p',
|
||||||
'programlisting': 'pre',
|
|
||||||
'verbatim': 'pre',
|
|
||||||
'itemizedlist': 'ul',
|
'itemizedlist': 'ul',
|
||||||
'listitem': 'li'
|
'listitem': 'li'
|
||||||
}
|
}
|
||||||
@@ -52,24 +50,37 @@ def escape_html(s: str) -> str:
|
|||||||
return s.replace("<", "<")
|
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 += '</' + tag + '>'
|
||||||
|
if node.tail:
|
||||||
|
out += node.tail
|
||||||
|
return out
|
||||||
|
|
||||||
|
|
||||||
def doxyxml2html(nodes: List[ElementTree.Element]):
|
def doxyxml2html(nodes: List[ElementTree.Element]):
|
||||||
out = ''
|
out = ''
|
||||||
for n in nodes:
|
for n in nodes:
|
||||||
tag = tag_map.get(n.tag)
|
tag = tag_map.get(n.tag)
|
||||||
if tag:
|
if tag:
|
||||||
out += '<' + tag + '>'
|
out += convert_node(n, tag)
|
||||||
elif n.tag == 'ulink':
|
continue
|
||||||
out += '<a href="' + n.attrib['url'] + '">'
|
if n.tag == 'programlisting' or n.tag == 'verbatim':
|
||||||
else:
|
out += '<pre>'
|
||||||
|
out += convert_node(n, 'code', {'class': 'language-cpp'})
|
||||||
|
out += '</pre>'
|
||||||
|
continue
|
||||||
|
if n.tag == 'ulink':
|
||||||
|
out += convert_node(n, 'a', {'href': n.attrib['url']})
|
||||||
|
continue
|
||||||
out += tag_text_map[n.tag]
|
out += tag_text_map[n.tag]
|
||||||
out += '<code class="language-cpp">' if tag == 'pre' else ''
|
|
||||||
if n.text:
|
|
||||||
out += escape_html(n.text)
|
|
||||||
out += doxyxml2html(list(n))
|
|
||||||
out += '</code>' if tag == 'pre' else ''
|
|
||||||
out += '</' + tag + '>' if tag else ''
|
|
||||||
if n.tail:
|
|
||||||
out += n.tail
|
|
||||||
return out
|
return out
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user