@@ -7,20 +7,53 @@ def get_name
77
88 def additional_entries
99 entries = [ ]
10-
10+ used_fns = [ ]
11+
1112 css ( 'h2.section' ) . each do |node |
1213 type = get_type
13-
1414 # Linkable anchor sits above <h2>.
1515 a = node . xpath ( 'preceding-sibling::a' ) . last
1616 header_text = extract_header_text ( node . content )
1717
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
2021 header_text = module_name if module_name . present?
22+ when 'Calendar Function System'
23+ header_text << ' (Calendar)'
2124 end
2225
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
2457 end
2558
2659 entries
0 commit comments