Skip to content

Commit 8cc174f

Browse files
committed
Add entries for function calls and operators
1 parent b3d08dc commit 8cc174f

File tree

1 file changed

+24
-10
lines changed

1 file changed

+24
-10
lines changed

lib/docs/filters/zsh/entries.rb

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,36 +7,50 @@ def get_name
77

88
def additional_entries
99
entries = []
10+
used_fns = []
1011

1112
css('h2.section').each do |node|
1213
type = get_type
1314
# Linkable anchor sits above <h2>.
1415
a = node.xpath('preceding-sibling::a').last
1516
header_text = extract_header_text(node.content)
1617

17-
if type == 'Zsh Modules'
18-
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
1921
header_text = module_name if module_name.present?
22+
when 'Calendar Function System'
23+
header_text << ' (Calendar)'
2024
end
2125

22-
entries << [header_text, a['name'], type] if header_text != 'Description'
26+
entries << [header_text, a['name'], type] unless header_text.start_with?('Description')
2327
end
2428

2529
# Functions are documented within <dl> elements.
2630
# Names are wrapped in <dt>, details within <dd>.
2731
# <dd> can also contain anchors for the next function.
28-
css('dl').each do |node|
32+
doc.css('> dl').each do |node|
2933
type = get_type
30-
fn_names = node.css('dt')
31-
node.css('dd a').each_with_index do |anchor, i|
34+
fn_names = node.css('> dt')
35+
node.css('dd a[name]').each_with_index do |anchor, i|
3236
if fn_names[i].present? && anchor['name'].present?
3337
fn_names[i]['id'] = anchor['name']
3438

3539
# Groups of functions are sometimes comma-delimited.
36-
# Strip arguments from function header.
37-
fn_names[i].content.split(', ').each do |fn|
38-
fn.gsub!(/\W*\[.*\]$/, '')
39-
entries << [fn, anchor['name'], type] if fn.present?
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
4054
end
4155
end
4256
end

0 commit comments

Comments
 (0)