History

Fix Erlang lib/ entries and func Types sec

This commit * Makes lib/ entries get indexed correctly; * Stops the types associated with functions from being filtered away, and orders their "Types" heading under the function heading; and * Cleans out onmouseover/onmouseout attributes.

Axel Forsman committed 4 years ago

Commit a2ae1b31 parent ffde3934 files · +37 −48Browse files

Unified · Split

4 files
  1. assets/stylesheets/pages/_erlang.scss +6 −0
  2. lib/docs/filters/erlang/clean_html.rb +29 −34
  3. lib/docs/filters/erlang/entries.rb +2 −5
  4. lib/docs/filters/erlang/pre_clean_html.rb +0 −9
assets/stylesheets/pages/_erlang.scss+6−0
@@ -6,4 +6,10 @@ · 5 unmodified lines
6 .note { @extend %note; }6 .note { @extend %note; }
7 .warning { @extend %note, %note-red; }7 .warning { @extend %note, %note-red; }
8 .note .label, .warning .label { font-weight: var(--boldFontWeight); }8 .note .label, .warning .label { font-weight: var(--boldFontWeight); }
9
10 .since {
11 color: var(--textColorLight);
12 font-weight: normal;
13 font-size: small;
14 }
9}15}
lib/docs/filters/erlang/clean_html.rb+29−34
@@ -30,34 +30,47 @@ module Docs · 29 unmodified lines
30 30
31 # others31 # others
32 32
33 # Remove JS on-hover highlighting
34 css('h3.title-link', 'h4.data-type-name', 'h4.func-head').each do |node|
35 node.remove_attribute('onmouseover')
36 node.remove_attribute('onmouseout')
37 end
38
33 css('a[name]').each do |node|39 css('a[name]').each do |node|
34 # parent = node.parent
35 # parent = parent.parent while parent.name == 'span'
36 (node.next_element || node.parent)['id'] ||= node['name']
37 node.before(node.children).remove40 node.before(node.children).remove
38 end41 end
39 42
40 css('h3').each do |node|43 css('h3').each do |node|
41 node.name = 'h2'
42 content = node.content44 content = node.content
43 node.content = content.capitalize if content == content.upcase45 node.content = content.capitalize if content == content.upcase
44 end46 end
45 47
46 css('p > .bold_code:first-child ~ br:last-child').each do |node|48 # Subsume "Types" heading under function head heading
47 parent = node.parent49 css('h4.func-head + .fun-types > h3.func-types-title')
48 parent.name = 'h3'50 .each { |node| node.name = 'h5' }
49 parent.css('> br').remove51
50 parent.css('> code').each do |code|52 css('h3', 'h4', 'h5').each do |node|
51 code.css('*:not(a):not(br)').each { |n| n.before(n.children).remove }53 node.name = node.name.sub(/\d/) { |i| i.to_i - 1 }
52 code.inner_html = code.inner_html.gsub('<br>', "\n").strip
53 end
54 end54 end
55 55
56 css('pre:not(.REFTYPES) *:not(a)', 'a[href^=javascript]').each do |node|56 # Convert <span/> code blocks to <code/> if inline otherwise
57 node.before(node.children).remove57 # <pre><code/></pre>.
58 css('span.bold_code', 'span.code', '.func-head > span.title-name').each do |node|
59 node.remove_attribute('class')
60 node.css('span.bold_code', 'span.code')
61 .each { |n| n.before(n.children).remove }
62 if node.at_css('br') then
63 node.name = 'pre'
64 node.inner_html = "<code>" +
65 node.inner_html.remove(/\n/).gsub('<br>', "\n").strip +
66 "</code>"
67 else
68 node.name = 'code'
69 node.inner_html = node.inner_html.strip.gsub(/\s+/, ' ')
70 end
58 end71 end
59 72
60 css('pre:not(.REFTYPES)').each do |node|73 css('*:not(.REFTYPES) > pre').each do |node|
61 node['data-language'] = 'erlang'74 node['data-language'] = 'erlang'
62 node.inner_html = node.inner_html.strip_heredoc75 node.inner_html = node.inner_html.strip_heredoc
63 end76 end
@@ -70,23 +83,7 @@ module Docs · 6 unmodified lines
70 end83 end
71 end84 end
72 85
73 css('.REFTYPES').each do |node|86 css('a[href^=javascript]').each { |n| n.before(n.children).remove }
74 next unless node.parent
75 html = "<pre>"
76 while node['class'] == 'REFTYPES'
77 node.inner_html = node.inner_html.remove(/\n/).gsub('<br>', "\n")
78 node.css('*:not(a)').each { |n| n.before(n.children).remove }
79 html << node.inner_html.strip + "\n"
80 node = node.next_element
81 node.previous_element.remove
82 end
83 html.gsub! %r{\n{2,}}, "\n"
84 html.strip!
85 html << "</pre>"
86 node.before(html)
87 end
88
89 css('.REFTYPES').remove
90 87
91 css('table').each do |node|88 css('table').each do |node|
92 node.remove_attribute('border')89 node.remove_attribute('border')
@@ -99,8 +96,6 @@ module Docs · 6 unmodified lines
99 node.remove_attribute('valign')96 node.remove_attribute('valign')
100 end97 end
101 98
102 css('.bold_code').remove_attr('class')
103
104 doc99 doc
105 end100 end
106 end101 end
lib/docs/filters/erlang/entries.rb+2−5
@@ -44,10 +44,9 @@ module Docs · 43 unmodified lines
44 if subpath.start_with?('lib/')44 if subpath.start_with?('lib/')
45 names = Set.new45 names = Set.new
46 entry_nodes.each_with_object [] do |node, entries|46 entry_nodes.each_with_object [] do |node, entries|
47 id = node['name']47 id = node['id']
48 name = id.remove %r{\-\d*\z}48 name = id.remove %r{\-\d*\z}
49 name << ' (type)' if name.sub!(/\Atype-/, '')49 name << ' (type)' if name.sub!(/\Atype-/, '')
50 name.remove! 'Module:'
51 name.prepend "#{self.name}:"50 name.prepend "#{self.name}:"
52 entries << [name, id] if names.add?(name)51 entries << [name, id] if names.add?(name)
53 end52 end
@@ -67,9 +66,7 @@ module Docs · 13 unmodified lines
67 66
68 def entry_nodes67 def entry_nodes
69 @entry_nodes ||= if subpath.start_with?('lib/')68 @entry_nodes ||= if subpath.start_with?('lib/')
70 css('p + div.REFBODY').each_with_object [] do |node, result|69 css('article.func > h4', 'article.data-types-body > h4').entries
71 result.concat(node.previous_element.css('a[name]').to_a)
72 end
73 elsif subpath.start_with?('erts')70 elsif subpath.start_with?('erts')
74 link = at_css(".flipMenu a[href='#{File.basename(subpath, '.html')}']")71 link = at_css(".flipMenu a[href='#{File.basename(subpath, '.html')}']")
75 list = link.parent.parent72 list = link.parent.parent
lib/docs/filters/erlang/pre_clean_html.rb+0−9
@@ -4,15 +4,6 @@ module Docs · 3 unmodified lines
4 def call4 def call
5 css('.flipMenu li[title] > a').remove unless subpath.start_with?('erts') # perf5 css('.flipMenu li[title] > a').remove unless subpath.start_with?('erts') # perf
6 6
7 css('.REFTYPES').each do |node|
8 node.name = 'pre'
9 end
10
11 css('span.bold_code', 'span.code').each do |node|
12 node.name = 'code'
13 node.inner_html = node.inner_html.strip.gsub(/\s+/, ' ')
14 end
15
16 doc7 doc
17 end8 end
18 end9 end