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
66 .note { @extend %note; }
77 .warning { @extend %note, %note-red; }
88 .note .label, .warning .label { font-weight: var(--boldFontWeight); }
9+
10+ .since {
11+ color: var(--textColorLight);
12+ font-weight: normal;
13+ font-size: small;
14+ }
915 }
lib/docs/filters/erlang/clean_html.rb+29−34
@@ -30,34 +30,47 @@ module Docs · 29 unmodified lines
3030
3131 # others
3232
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+
3339 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']
3740 node.before(node.children).remove
3841 end
3942
4043 css('h3').each do |node|
41− node.name = 'h2'
4244 content = node.content
4345 node.content = content.capitalize if content == content.upcase
4446 end
4547
46− css('p > .bold_code:first-child ~ br:last-child').each do |node|
47− parent = node.parent
48− parent.name = 'h3'
49− parent.css('> br').remove
50− parent.css('> code').each do |code|
51− code.css('*:not(a):not(br)').each { |n| n.before(n.children).remove }
52− code.inner_html = code.inner_html.gsub('<br>', "\n").strip
53− end
48+ # Subsume "Types" heading under function head heading
49+ css('h4.func-head + .fun-types > h3.func-types-title')
50+ .each { |node| node.name = 'h5' }
51+
52+ css('h3', 'h4', 'h5').each do |node|
53+ node.name = node.name.sub(/\d/) { |i| i.to_i - 1 }
5454 end
5555
56− css('pre:not(.REFTYPES) *:not(a)', 'a[href^=javascript]').each do |node|
57− node.before(node.children).remove
56+ # Convert <span/> code blocks to <code/> if inline otherwise
57+ # <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
5871 end
5972
60− css('pre:not(.REFTYPES)').each do |node|
73+ css('*:not(.REFTYPES) > pre').each do |node|
6174 node['data-language'] = 'erlang'
6275 node.inner_html = node.inner_html.strip_heredoc
6376 end
@@ -70,23 +83,7 @@ module Docs · 6 unmodified lines
7083 end
7184 end
7285
73− css('.REFTYPES').each do |node|
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
86+ css('a[href^=javascript]').each { |n| n.before(n.children).remove }
9087
9188 css('table').each do |node|
9289 node.remove_attribute('border')
@@ -99,8 +96,6 @@ module Docs · 6 unmodified lines
9996 node.remove_attribute('valign')
10097 end
10198
102− css('.bold_code').remove_attr('class')
103−
10499 doc
105100 end
106101 end
lib/docs/filters/erlang/entries.rb+2−5
@@ -44,10 +44,9 @@ module Docs · 43 unmodified lines
4444 if subpath.start_with?('lib/')
4545 names = Set.new
4646 entry_nodes.each_with_object [] do |node, entries|
47− id = node['name']
47+ id = node['id']
4848 name = id.remove %r{\-\d*\z}
4949 name << ' (type)' if name.sub!(/\Atype-/, '')
50− name.remove! 'Module:'
5150 name.prepend "#{self.name}:"
5251 entries << [name, id] if names.add?(name)
5352 end
@@ -67,9 +66,7 @@ module Docs · 13 unmodified lines
6766
6867 def entry_nodes
6968 @entry_nodes ||= if subpath.start_with?('lib/')
70− css('p + div.REFBODY').each_with_object [] do |node, result|
71− result.concat(node.previous_element.css('a[name]').to_a)
72− end
69+ css('article.func > h4', 'article.data-types-body > h4').entries
7370 elsif subpath.start_with?('erts')
7471 link = at_css(".flipMenu a[href='#{File.basename(subpath, '.html')}']")
7572 list = link.parent.parent
lib/docs/filters/erlang/pre_clean_html.rb+0−9
@@ -4,15 +4,6 @@ module Docs · 3 unmodified lines
44 def call
55 css('.flipMenu li[title] > a').remove unless subpath.start_with?('erts') # perf
66
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−
167 doc
178 end
189 end