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.
pull/1839/head
Axel Forsman 2 years ago
parent ffde393d75
commit a2ae1b3a3f

@ -6,4 +6,10 @@
.note { @extend %note; } .note { @extend %note; }
.warning { @extend %note, %note-red; } .warning { @extend %note, %note-red; }
.note .label, .warning .label { font-weight: var(--boldFontWeight); } .note .label, .warning .label { font-weight: var(--boldFontWeight); }
.since {
color: var(--textColorLight);
font-weight: normal;
font-size: small;
}
} }

@ -30,34 +30,47 @@ module Docs
# others # others
# Remove JS on-hover highlighting
css('h3.title-link', 'h4.data-type-name', 'h4.func-head').each do |node|
node.remove_attribute('onmouseover')
node.remove_attribute('onmouseout')
end
css('a[name]').each do |node| css('a[name]').each do |node|
# parent = node.parent
# parent = parent.parent while parent.name == 'span'
(node.next_element || node.parent)['id'] ||= node['name']
node.before(node.children).remove node.before(node.children).remove
end end
css('h3').each do |node| css('h3').each do |node|
node.name = 'h2'
content = node.content content = node.content
node.content = content.capitalize if content == content.upcase node.content = content.capitalize if content == content.upcase
end end
css('p > .bold_code:first-child ~ br:last-child').each do |node| # Subsume "Types" heading under function head heading
parent = node.parent css('h4.func-head + .fun-types > h3.func-types-title')
parent.name = 'h3' .each { |node| node.name = 'h5' }
parent.css('> br').remove
parent.css('> code').each do |code| css('h3', 'h4', 'h5').each do |node|
code.css('*:not(a):not(br)').each { |n| n.before(n.children).remove } node.name = node.name.sub(/\d/) { |i| i.to_i - 1 }
code.inner_html = code.inner_html.gsub('<br>', "\n").strip
end
end end
css('pre:not(.REFTYPES) *:not(a)', 'a[href^=javascript]').each do |node| # Convert <span/> code blocks to <code/> if inline otherwise
node.before(node.children).remove # <pre><code/></pre>.
css('span.bold_code', 'span.code', '.func-head > span.title-name').each do |node|
node.remove_attribute('class')
node.css('span.bold_code', 'span.code')
.each { |n| n.before(n.children).remove }
if node.at_css('br') then
node.name = 'pre'
node.inner_html = "<code>" +
node.inner_html.remove(/\n/).gsub('<br>', "\n").strip +
"</code>"
else
node.name = 'code'
node.inner_html = node.inner_html.strip.gsub(/\s+/, ' ')
end
end end
css('pre:not(.REFTYPES)').each do |node| css('*:not(.REFTYPES) > pre').each do |node|
node['data-language'] = 'erlang' node['data-language'] = 'erlang'
node.inner_html = node.inner_html.strip_heredoc node.inner_html = node.inner_html.strip_heredoc
end end
@ -70,23 +83,7 @@ module Docs
end end
end end
css('.REFTYPES').each do |node| css('a[href^=javascript]').each { |n| n.before(n.children).remove }
next unless node.parent
html = "<pre>"
while node['class'] == 'REFTYPES'
node.inner_html = node.inner_html.remove(/\n/).gsub('<br>', "\n")
node.css('*:not(a)').each { |n| n.before(n.children).remove }
html << node.inner_html.strip + "\n"
node = node.next_element
node.previous_element.remove
end
html.gsub! %r{\n{2,}}, "\n"
html.strip!
html << "</pre>"
node.before(html)
end
css('.REFTYPES').remove
css('table').each do |node| css('table').each do |node|
node.remove_attribute('border') node.remove_attribute('border')
@ -99,8 +96,6 @@ module Docs
node.remove_attribute('valign') node.remove_attribute('valign')
end end
css('.bold_code').remove_attr('class')
doc doc
end end
end end

@ -44,10 +44,9 @@ module Docs
if subpath.start_with?('lib/') if subpath.start_with?('lib/')
names = Set.new names = Set.new
entry_nodes.each_with_object [] do |node, entries| entry_nodes.each_with_object [] do |node, entries|
id = node['name'] id = node['id']
name = id.remove %r{\-\d*\z} name = id.remove %r{\-\d*\z}
name << ' (type)' if name.sub!(/\Atype-/, '') name << ' (type)' if name.sub!(/\Atype-/, '')
name.remove! 'Module:'
name.prepend "#{self.name}:" name.prepend "#{self.name}:"
entries << [name, id] if names.add?(name) entries << [name, id] if names.add?(name)
end end
@ -67,9 +66,7 @@ module Docs
def entry_nodes def entry_nodes
@entry_nodes ||= if subpath.start_with?('lib/') @entry_nodes ||= if subpath.start_with?('lib/')
css('p + div.REFBODY').each_with_object [] do |node, result| css('article.func > h4', 'article.data-types-body > h4').entries
result.concat(node.previous_element.css('a[name]').to_a)
end
elsif subpath.start_with?('erts') elsif subpath.start_with?('erts')
link = at_css(".flipMenu a[href='#{File.basename(subpath, '.html')}']") link = at_css(".flipMenu a[href='#{File.basename(subpath, '.html')}']")
list = link.parent.parent list = link.parent.parent

@ -4,15 +4,6 @@ module Docs
def call def call
css('.flipMenu li[title] > a').remove unless subpath.start_with?('erts') # perf css('.flipMenu li[title] > a').remove unless subpath.start_with?('erts') # perf
css('.REFTYPES').each do |node|
node.name = 'pre'
end
css('span.bold_code', 'span.code').each do |node|
node.name = 'code'
node.inner_html = node.inner_html.strip.gsub(/\s+/, ' ')
end
doc doc
end end
end end

Loading…
Cancel
Save