Skip to content

Commit 29088c0

Browse files
authored
Merge pull request #2552 from freeCodeCamp/bash
Update Bash documentation (5.3)
2 parents fe38cf9 + 598ad20 commit 29088c0

3 files changed

Lines changed: 28 additions & 34 deletions

File tree

lib/docs/filters/bash/clean_html.rb

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ class CleanHtmlFilter < Filter
44
def call
55
@doc = at_css('> div[id]') if at_css('> div[id]')
66
# Remove the navigation header and footer and the lines underneath and above it
7-
at_css('.header + hr').remove
7+
at_css('.nav-panel + hr').try(:remove)
88
line_above = at_xpath('//div[@class="header"]/preceding::hr[1]')
99
line_above.remove unless line_above.nil?
10-
css('.header').remove
10+
css('.nav-panel').remove
1111

12-
css('.copiable-anchor').remove
12+
css('.copiable-anchor', '.copiable-link').remove
1313

1414
# Remove chapter and section numbers from title
1515
title_node = at_css('h1, h2, h3, h4, h5, h6')
16-
title_node.content = title_node.content.gsub(/(\d+\.?)+/, '').strip
16+
title_node.content = title_node.content.gsub(/(\d+\.?)+/, '').gsub('¶', '').strip
1717
title_node.name = 'h1'
1818

1919
# Remove the "D. " from names like "D. Concept Index" and "D. Function Index"
@@ -23,39 +23,32 @@ def call
2323
# In the original reference they are used to add width between two columns
2424
xpath('//td[text()=" " and not(descendant::*)]').remove
2525

26-
# Add id's to additional entry nodes
27-
css('dl > dt > code').each do |node|
28-
# Only take the direct text (i.e. "<div>Hello <span>World</span></div>" becomes "Hello")
29-
node['id'] = node.xpath('text()').to_s.strip
30-
end
31-
32-
# Fix hashes of index entries so they link to the correct hash on the linked page
33-
css('table[class^=index-] td[valign=top] > a').each do |node|
34-
path = node['href'].split('#')[0]
35-
hash = node.content
36-
37-
# Fix the index entries linking to the Special Parameters page
38-
# There are multiple index entries that should link to the same paragraph on that page
39-
# Example: the documentation for "$!" is equal to the documentation for "!"
40-
if path.downcase.include?('special-parameters')
41-
if hash.size > 1 && hash[0] == '$'
42-
hash = hash[1..-1]
43-
end
26+
# The manual marks index targets with empty anchors (<a id="index-…"></a>), which the
27+
# clean_text filter strips. Move their ids onto the enclosing node so the index entries
28+
# keep linking to the right paragraph.
29+
css('a[id]').each do |node|
30+
next unless node.content.strip.empty?
31+
parent = node.parent
32+
if parent && parent['id'].blank?
33+
parent['id'] = node['id']
34+
else
35+
# Several anchors can share a parent; keep the extra ones alive by giving
36+
# them content the clean_text filter doesn't consider empty
37+
node.content = "​"
4438
end
45-
46-
node['href'] = path + '#' + hash
47-
end
48-
49-
# Fix index table letter hashes (the "Jump to" hashes)
50-
css('table[class^=index-] th > a').each do |node|
51-
node['id'] = node['name']
5239
end
5340

5441
# Remove the rows with a horizontal line in them from the index tables
55-
css('td[colspan="4"]').remove
42+
css('td[colspan="3"]').remove
43+
44+
# Remove the empty spacer cells of the index tables
45+
css('td.printindex-index-entry').each do |node|
46+
previous = node.previous_element
47+
previous.remove if previous && previous.name == 'td' && previous.content.strip.empty?
48+
end
5649

5750
# Remove additional text from menu entry and index entry cells
58-
css('td[valign=top]').each do |node|
51+
css('td.printindex-index-entry, td.printindex-index-section').each do |node|
5952
link = node.at_css('a')
6053
node.children = link unless link.nil?
6154
end

lib/docs/filters/bash/entries.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@ def get_name
1515
name.gsub!(/[[:digit:]]/, '')
1616
end
1717

18+
name.remove! '¶'
1819
name.strip
1920

2021
end
2122

2223
def get_type
2324
return 'Manual: Appendices' if name.start_with?('Appendix')
24-
return 'Manual: Indexes' if at_css('a[rel=up]').content.include?("Index")
25+
return 'Manual: Indexes' if at_css('a[rel=up]').try(:content).to_s.include?("Index")
2526
"Manual"
2627
end
2728

@@ -38,7 +39,7 @@ def additional_entries
3839

3940
entries = []
4041

41-
css('table[class^=index-] td[valign=top] > a').each_slice(2) do |entry_node, section_node|
42+
css('td.printindex-index-entry > a').each do |entry_node|
4243
entry_name = entry_node.content
4344
entry_path = entry_node['href']
4445
entries << [entry_name, entry_path, entry_type]

lib/docs/scrapers/bash.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module Docs
22
class Bash < FileScraper
33
self.type = 'bash'
4-
self.release = '5.2'
4+
self.release = '5.3'
55
self.base_url = 'https://www.gnu.org/software/bash/manual/html_node'
66
self.root_path = 'index.html'
77
self.links = {

0 commit comments

Comments
 (0)