Skip to content

Commit 288098b

Browse files
committed
Fix Openjdk additional entries and style
1 parent 86cdf86 commit 288098b

5 files changed

Lines changed: 52 additions & 38 deletions

File tree

lib/docs/filters/openjdk/clean_html.rb

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ module Docs
55
class Openjdk
66
class CleanHtmlFilter < Filter
77
def call
8-
css('.topNav', '.subNav', '.bottomNav', '.legalCopy', 'noscript', '.subTitle').remove
8+
css('.topNav', '.subNav', '.bottomNav', '.legalCopy', 'noscript', '.subTitle', 'hr').remove
99

1010
# Preserve internal fragment links
1111
# Transform <a name="foo"><!-- --></a><bar>text</bar>
1212
# into <bar id="foo">text</bar>
13-
css('a[name]').each do |node|
13+
css('a[name]','a[id]').each do |node|
1414
if node.children.all?(&:blank?)
15-
node.next_element['id'] = node['name'] if node.next_element
15+
node.next_element['id'] = (node['id'] || node['name'])if node.next_element
1616
node.remove
1717
end
1818
end
@@ -23,11 +23,9 @@ def call
2323
node.remove
2424
end
2525

26-
# Replace summary tables with their detail content
27-
css('h3[id$=".summary"]').each do |node|
28-
id = node['id'].sub('summary', 'detail')
29-
detail = at_css("h3[id='#{id}']") || at_css("h3[id='#{id.remove('optional.').remove('required.')}']")
30-
node.parent.children = detail.parent.children if detail
26+
# remove captions in tables
27+
css('table caption').each do |node|
28+
node.remove
3129
end
3230

3331
css('h3[id$=".summary"]', 'h3[id$=".detail"]').each do |node|

lib/docs/filters/openjdk/clean_html_new.rb

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,7 @@ def call
77
at_css('h1').content = "OpenJDK #{release} Documentation"
88
end
99

10-
css('.header .sub-title').remove
11-
12-
css('blockquote pre').each do |node|
13-
node.parent.name = 'pre'
14-
node.parent['class'] = 'highlight'
15-
node.parent['data-language'] = 'java'
16-
node.parent.content = node.content
17-
node.remove
18-
end
10+
css('.header .sub-title', 'hr', '.table-tabs').remove
1911

2012
# fix ul section that contains summaries or tables
2113
css('ul').each do |node|
@@ -24,6 +16,13 @@ def call
2416
end
2517
end
2618

19+
css('ul.summary-list').each do |node|
20+
node.css('li').each do |subnode|
21+
subnode.name = 'div'
22+
end
23+
node.name = 'div'
24+
end
25+
2726
# add syntax highlight to code blocks
2827
css('pre > code').each do |node|
2928
node.parent['class'] = 'lang-java'

lib/docs/filters/openjdk/entries.rb

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,31 @@ def get_type
2929
def additional_entries
3030
# Only keep the first found entry with a unique name,
3131
# i.e. overloaded methods are skipped in index
32-
css('a[name$=".summary"]').each_with_object({}) do |summary, entries|
33-
next if summary['name'].include?('nested') || summary['name'].include?('constructor') ||
34-
summary['name'].include?('field') || summary['name'].include?('constant')
35-
summary.parent.css('.memberNameLink a').each do |node|
36-
name = node.parent.parent.content.strip
37-
name.sub! %r{\(.+?\)}m, '()'
38-
id = node['href'].remove(%r{.*#})
39-
entries[name] ||= ["#{self.name}.#{name}", id]
40-
end
41-
end.values
32+
if version == '8' || version == '8 Gui' || version == '8 Web'
33+
css('a[name$=".summary"]').each_with_object({}) do |summary, entries|
34+
next if summary['name'].include?('nested') || summary['name'].include?('constructor') ||
35+
summary['name'].include?('field') || summary['name'].include?('constant')
36+
summary.parent.css('.memberNameLink a').each do |node|
37+
name = node.parent.parent.content.strip
38+
name.sub! %r{\(.+?\)}m, '()'
39+
id = node['href'].remove(%r{.*#})
40+
entries[name] ||= ["#{self.name}.#{name}", id]
41+
end
42+
end.values
43+
44+
else
45+
css('a[id$=".summary"]').each_with_object({}) do |summary, entries|
46+
next if summary['id'].include?('nested') || summary['id'].include?('constructor') ||
47+
summary['id'].include?('field') || summary['id'].include?('constant')
48+
summary.parent.css('.memberNameLink a').each do |node|
49+
name = node.parent.parent.content.strip
50+
name.sub! %r{\(.+?\)}m, '()'
51+
id = node['href'].remove(%r{.*#})
52+
entries[name] ||= ["#{self.name}.#{name}", id]
53+
end
54+
end.values
55+
end
56+
4257
end
4358
end
4459
end

lib/docs/filters/openjdk/entries_new.rb

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,14 @@ def get_type
2828
end
2929

3030
def additional_entries
31-
css('a[name$=".summary"]').each_with_object({}) do |summary, entries|
32-
next if summary['name'].include?('nested') || summary['name'].include?('constructor') ||
33-
summary['name'].include?('field') || summary['name'].include?('constant')
34-
summary.parent.css('.memberNameLink a').each do |node|
35-
name = node.parent.parent.content.strip
36-
name.sub! %r{\(.+?\)}m, '()'
37-
id = node['href'].remove(%r{.*#})
38-
entries[name] ||= ["#{self.name}.#{name}", id]
39-
end
40-
end.values
31+
entries = []
32+
33+
css('section[id]').each do |node|
34+
next if !(node['id'].match?(/\(/))
35+
entries << [self.name+ '.' +node.at_css('h3').content + '()', node['id']]
36+
end
37+
38+
entries
4139
end
4240

4341
end

lib/docs/scrapers/openjdk.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ class Openjdk < FileScraper
2222
/\.png/
2323
]
2424

25-
options[:only_patterns] = [/\Ajava\./]
25+
options[:only_patterns] = [
26+
/\Ajava\./,
27+
/\Ajdk\./
28+
]
2629

2730
options[:attribution] = <<-HTML
2831
&copy; 1993, 2020, Oracle and/or its affiliates. All rights reserved.<br>
@@ -37,6 +40,7 @@ class Openjdk < FileScraper
3740
version '15' do
3841
self.release = '15.0.1'
3942
self.root_path = 'index.html'
43+
self.base_url = 'https://docs.oracle.com/en/java/javase/15/docs/api/'
4044

4145
html_filters.push NEWFILTERS
4246

0 commit comments

Comments
 (0)