@@ -7,20 +7,53 @@ def get_name
7
7
8
8
def additional_entries
9
9
entries = [ ]
10
-
10
+ used_fns = [ ]
11
+
11
12
css ( 'h2.section' ) . each do |node |
12
13
type = get_type
13
-
14
14
# Linkable anchor sits above <h2>.
15
15
a = node . xpath ( 'preceding-sibling::a' ) . last
16
16
header_text = extract_header_text ( node . content )
17
17
18
- if type == 'Zsh Modules'
19
- module_name = header_text . match ( /The (zsh\/ .*) Module/ ) &.captures &.first
18
+ case type
19
+ when 'Zsh Modules'
20
+ module_name = header_text . match ( /The (zsh\/ .* Module)/ ) &.captures &.first
20
21
header_text = module_name if module_name . present?
22
+ when 'Calendar Function System'
23
+ header_text << ' (Calendar)'
21
24
end
22
25
23
- entries << [ header_text , a [ 'name' ] , type ] if header_text != 'Description'
26
+ entries << [ header_text , a [ 'name' ] , type ] unless header_text . start_with? ( 'Description' )
27
+ end
28
+
29
+ # Functions are documented within <dl> elements.
30
+ # Names are wrapped in <dt>, details within <dd>.
31
+ # <dd> can also contain anchors for the next function.
32
+ doc . css ( '> dl' ) . each do |node |
33
+ type = get_type
34
+ fn_names = node . css ( '> dt' )
35
+ node . css ( 'dd a[name]' ) . each_with_index do |anchor , i |
36
+ if fn_names [ i ] . present? && anchor [ 'name' ] . present?
37
+ fn_names [ i ] [ 'id' ] = anchor [ 'name' ]
38
+
39
+ # Groups of functions are sometimes comma-delimited.
40
+ # Strip arguments, flags, etc. from function name.
41
+ # Skip flag-only headers.
42
+ fn_names [ i ] . inner_html . split ( ', ' ) . each do |fn |
43
+ fn . gsub! ( /<(?:tt|var)>(.+?)<\/ (?:tt|var)>/ , '\1' )
44
+ fn = fn . split ( ' ' ) . first
45
+ fn . gsub! ( /(?:[\[ \( ]).*(?:[\] \) ]).*$/ , '' )
46
+
47
+ # Add context for operators.
48
+ fn << " (#{ type } )" if fn . length == 1
49
+
50
+ if fn . present? && !fn . match? ( /^[\- \[ ]/ ) && !used_fns . include? ( fn )
51
+ used_fns << fn
52
+ entries << [ fn , anchor [ 'name' ] , type ]
53
+ end
54
+ end
55
+ end
56
+ end
24
57
end
25
58
26
59
entries
0 commit comments