Improve Erlang documentation

Fixes #626.
pull/630/head
Thibaut Courouble 8 years ago
parent d126ad9fa2
commit b626a9d574

@ -230,7 +230,7 @@ credits = [
'https://raw.githubusercontent.com/elixir-lang/elixir/master/LICENSE'
], [
'Erlang',
'1999-2016 Ericsson AB',
'2010-2017 Ericsson AB',
'Apache',
'https://raw.githubusercontent.com/erlang/otp/maint/LICENSE.txt'
], [

@ -1066,6 +1066,50 @@ Prism.languages.elixir.string.forEach(function(o) {
});
Prism.languages.erlang = {
'comment': /%.+/,
'string': {
pattern: /"(?:\\?.)*?"/,
greedy: true
},
'quoted-function': {
pattern: /'(?:\\.|[^'\\])+'(?=\()/,
alias: 'function'
},
'quoted-atom': {
pattern: /'(?:\\.|[^'\\])+'/,
alias: 'atom'
},
'boolean': /\b(?:true|false)\b/,
'keyword': /\b(?:fun|when|case|of|end|if|receive|after|try|catch)\b/,
'number': [
/\$\\?./,
/\d+#[a-z0-9]+/i,
/(?:\b|-)\d*\.?\d+([Ee][+-]?\d+)?\b/
],
'function': /\b[a-z][\w@]*(?=\()/,
'variable': {
// Look-behind is used to prevent wrong highlighting of atoms containing "@"
pattern: /(^|[^@])(?:\b|\?)[A-Z_][\w@]*/,
lookbehind: true
},
'operator': [
/[=\/<>:]=|=[:\/]=|\+\+?|--?|[=*\/!]|\b(?:bnot|div|rem|band|bor|bxor|bsl|bsr|not|and|or|xor|orelse|andalso)\b/,
{
// We don't want to match <<
pattern: /(^|[^<])<(?!<)/,
lookbehind: true
},
{
// We don't want to match >>
pattern: /(^|[^>])>(?!>)/,
lookbehind: true
}
],
'atom': /\b[a-z][\w@]*/,
'punctuation': /[()[\]{}:;,.#|]|<<|>>/
};
Prism.languages.go = Prism.languages.extend('clike', {
'keyword': /\b(break|case|chan|const|continue|default|defer|else|fallthrough|for|func|go(to)?|if|import|interface|map|package|range|return|select|struct|switch|type|var)\b/,
'builtin': /\b(bool|byte|complex(64|128)|error|float(32|64)|rune|string|u?int(8|16|32|64|)|uintptr|append|cap|close|complex|copy|delete|imag|len|make|new|panic|print(ln)?|real|recover)\b/,

@ -24,6 +24,7 @@ app.views.DockerPage =
app.views.DrupalPage =
app.views.ElixirPage =
app.views.EmberPage =
app.views.ErlangPage =
app.views.ExpressPage =
app.views.FlowPage =
app.views.GoPage =

@ -1,7 +1,7 @@
._erlang {
@extend %simple;
h3.code { @extend %code; }
h3 > code { display: block; }
code.code { @extend %label; }
.note { @extend %note; }
.warning { @extend %note, %note-red; }

@ -8,7 +8,7 @@ module Docs
css('center:last-child').remove # copyright
css('center').each do |node|
css('center', '.example').each do |node|
node.before(node.children).remove
end
@ -30,12 +30,10 @@ module Docs
# others
# css('p > br:last-child').remove
css('a[name]').each do |node|
parent = node.parent
parent = parent.parent while parent.name == 'span'
parent['id'] = node['name']
# parent = node.parent
# parent = parent.parent while parent.name == 'span'
(node.next_element || node.parent)['id'] ||= node['name']
node.before(node.children).remove
end
@ -48,10 +46,11 @@ module Docs
css('p > .bold_code:first-child ~ br:last-child').each do |node|
parent = node.parent
parent.name = 'h3'
parent['class'] = 'code'
parent.css('*:not(a):not(br)').each { |n| n.before(n.children).remove }
node.remove
parent.inner_html = parent.inner_html.strip
parent.css('> br').remove
parent.css('> code').each do |code|
code.css('*:not(a):not(br)').each { |n| n.before(n.children).remove }
code.inner_html = code.inner_html.gsub('<br>', "\n").strip
end
end
css('pre:not(.REFTYPES) *:not(a)', 'a[href^=javascript]').each do |node|
@ -59,6 +58,7 @@ module Docs
end
css('pre:not(.REFTYPES)').each do |node|
node['data-language'] = 'erlang'
node.inner_html = node.inner_html.strip_heredoc
end
@ -80,6 +80,7 @@ module Docs
node = node.next_element
node.previous_element.remove
end
html.gsub! %r{\n{2,}}, "\n"
html.strip!
html << "</pre>"
node.before(html)
@ -98,6 +99,8 @@ module Docs
node.remove_attribute('valign')
end
css('.bold_code').remove_attr('class')
doc
end
end

@ -42,12 +42,14 @@ module Docs
return [] unless include_default_entry?
if subpath.start_with?('lib/')
entry_nodes.map do |node|
names = Set.new
entry_nodes.each_with_object [] do |node, entries|
id = node['name']
name = id.gsub %r{\-(?<arity>.*)\z}, '/\k<arity>'
name = id.remove %r{\-\d*\z}
name << ' (type)' if name.sub!(/\Atype-/, '')
name.remove! 'Module:'
name.prepend "#{self.name}:"
[name, id]
entries << [name, id] if names.add?(name)
end
elsif subpath.start_with?('doc/')
[]
@ -65,7 +67,9 @@ module Docs
def entry_nodes
@entry_nodes ||= if subpath.start_with?('lib/')
css('div.REFBODY + p > a')
css('p + div.REFBODY').each_with_object [] do |node, result|
result.concat(node.previous_element.css('a[name]').to_a)
end
elsif subpath.start_with?('erts')
link = at_css(".flipMenu a[href='#{File.basename(subpath, '.html')}']")
list = link.parent.parent

@ -36,7 +36,7 @@ module Docs
]
options[:attribution] = <<-HTML
&copy; 1999&ndash;2016 Ericsson AB<br>
&copy; 2010&ndash;2017 Ericsson AB<br>
Licensed under the Apache License, Version 2.0.
HTML

Loading…
Cancel
Save