-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdoc_utils.jl
More file actions
84 lines (67 loc) · 2.32 KB
/
Copy pathdoc_utils.jl
File metadata and controls
84 lines (67 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
"""
Helper module to read Doxygen documentation metadata from libssh_jll.
This is used by the bindings and documentation generators.
"""
module DocUtils
import XML
import libssh_jll
"""
Get the element children of a node. Note that we can't rely on the positions of
elements because XML.jl also returns the whitespace between them as text nodes.
"""
function _elements(node)
children = XML.children(node)
if isnothing(children)
return XML.Node[]
end
return filter(c -> XML.nodetype(c) == XML.Element, children)
end
"""
Find the first child element of `node` with the given tag, or `nothing`.
"""
function _find_element(node, tag::String)
idx = findfirst(c -> XML.tag(c) == tag, _elements(node))
return isnothing(idx) ? nothing : _elements(node)[idx]
end
"""
Read the function info from a Doxygen tag file into a dict.
In particular, the anchor file and the anchor itself.
"""
function read_tags()
doc = read(libssh_jll.doxygen_tags, XML.Node)
tagfile = _find_element(doc, "tagfile")
if isnothing(tagfile)
error("Couldn't find a <tagfile> element in $(libssh_jll.doxygen_tags)")
end
tags = Dict{Symbol, Any}()
for compound in _elements(tagfile)
attrs = XML.attributes(compound)
if isnothing(attrs) || get(attrs, "kind", "") != "group"
continue
end
for member in _elements(compound)
member_attrs = XML.attributes(member)
if XML.tag(member) != "member" || isnothing(member_attrs) ||
get(member_attrs, "kind", "") != "function"
continue
end
name = _find_element(member, "name")
anchorfile = _find_element(member, "anchorfile")
anchor = _find_element(member, "anchor")
if any(isnothing, (name, anchorfile, anchor))
continue
end
tags[Symbol(XML.simplevalue(name))] = (XML.simplevalue(anchorfile),
XML.simplevalue(anchor))
end
end
if isempty(tags)
error("No function tags found in $(libssh_jll.doxygen_tags), the tag file format may have changed")
end
return tags
end
function get_url(name::Symbol, tags)
anchorfile, anchor = tags[name]
return "https://api.libssh.org/stable/$(anchorfile)#$(anchor)"
end
end