Skip to content

Commit b3d08dc

Browse files
committed
Add entries for Zsh functions
1 parent fe827b3 commit b3d08dc

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

lib/docs/filters/zsh/entries.rb

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@ def get_name
77

88
def additional_entries
99
entries = []
10-
10+
1111
css('h2.section').each do |node|
1212
type = get_type
13-
1413
# Linkable anchor sits above <h2>.
1514
a = node.xpath('preceding-sibling::a').last
1615
header_text = extract_header_text(node.content)
@@ -23,6 +22,26 @@ def additional_entries
2322
entries << [header_text, a['name'], type] if header_text != 'Description'
2423
end
2524

25+
# Functions are documented within <dl> elements.
26+
# Names are wrapped in <dt>, details within <dd>.
27+
# <dd> can also contain anchors for the next function.
28+
css('dl').each do |node|
29+
type = get_type
30+
fn_names = node.css('dt')
31+
node.css('dd a').each_with_index do |anchor, i|
32+
if fn_names[i].present? && anchor['name'].present?
33+
fn_names[i]['id'] = anchor['name']
34+
35+
# 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+
end
41+
end
42+
end
43+
end
44+
2645
entries
2746
end
2847

lib/docs/scrapers/zsh.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class Zsh < UrlScraper
2727

2828
def get_latest_version(opts)
2929
body = fetch('https://zsh.sourceforge.io/Doc/Release', opts)
30-
body.scan(/, Zsh version ([0-9.]+)/)[0][0][0...-1]
30+
body.scan(/Zsh version ([0-9.]+)/)[0][0]
3131
end
3232
end
3333
end

0 commit comments

Comments
 (0)