@@ -2,97 +2,107 @@ module Docs
2
2
class Scala
3
3
class CleanHtmlFilter < Filter
4
4
def call
5
+ @doc = at_css ( '#content' )
6
+
5
7
always
8
+ add_title
6
9
7
- if slug == 'index'
8
- root
9
- else
10
- other
11
- end
10
+ doc
12
11
end
13
12
14
13
def always
15
- # remove deprecated sections
14
+ # Remove deprecated sections
16
15
css ( '.members' ) . each do |members |
17
16
header = members . at_css ( 'h3' )
18
17
members . remove if header . text . downcase . include? 'deprecate'
19
18
end
20
- # Some of this is just for 2.12
21
- # These are things that provide interactive features, which are not supported yet.
22
- css ( '#subpackage-spacer, #search, #mbrsel, .diagram-btn' ) . remove
23
- css ( '#footer' ) . remove
24
- css ( '.toggleContainer' ) . remove
19
+
20
+ css ( '#mbrsel, #footer' ) . remove
21
+
22
+ css ( '.diagram-container' ) . remove
23
+ css ( '.toggleContainer > .toggle' ) . each do |node |
24
+ title = node . at_css ( 'span' )
25
+ next if title . nil?
26
+
27
+ content = node . at_css ( '.hiddenContent' )
28
+ next if content . nil?
29
+
30
+ title . name = 'dt'
31
+
32
+ content . remove_attribute ( 'class' )
33
+ content . remove_attribute ( 'style' )
34
+ content . name = 'dd'
35
+
36
+ attributes = at_css ( '.attributes' )
37
+ unless attributes . nil?
38
+ title . parent = attributes
39
+ content . parent = attributes
40
+ end
41
+ end
25
42
26
43
signature = at_css ( '#signature' )
27
- signature . replace %Q|
28
- <h2 id="signature">#{ signature . inner_html } </h2>
29
- |
44
+ signature . replace "<h2 id=\" signature\" >#{ signature . inner_html } </h2>"
30
45
31
46
css ( 'div.members > h3' ) . each do |node |
32
- change_tag! 'h2' , node
47
+ node . name = 'h2'
33
48
end
34
49
35
50
css ( 'div.members > ol' ) . each do |list |
36
51
list . css ( 'li' ) . each do |li |
37
52
h3 = doc . document . create_element 'h3'
53
+ h3 [ 'id' ] = li [ 'name' ] . rpartition ( '#' ) . last unless li [ 'name' ] . nil?
54
+
38
55
li . prepend_child h3
39
56
li . css ( '.shortcomment' ) . remove
57
+
40
58
modifier = li . at_css ( '.modifier_kind' )
41
- modifier . parent = h3 if modifier
59
+ modifier . parent = h3 unless modifier . nil?
60
+
61
+ kind = li . at_css ( '.modifier_kind .kind' )
62
+ kind . content = kind . content + ' ' unless kind . nil?
63
+
42
64
symbol = li . at_css ( '.symbol' )
43
- symbol . parent = h3 if symbol
65
+ symbol . parent = h3 unless symbol . nil?
66
+
44
67
li . swap li . children
45
68
end
69
+
46
70
list . swap list . children
47
71
end
48
72
49
- pres = css ( '.fullcomment pre, .fullcommenttop pre' )
50
- pres . each do |pre |
73
+ css ( '.fullcomment pre, .fullcommenttop pre' ) . each do |pre |
51
74
pre [ 'data-language' ] = 'scala'
75
+ pre . content = pre . content
52
76
end
53
- pres . add_class 'language-scala'
54
-
55
-
56
-
57
- doc
58
-
59
- end
60
-
61
- def root
62
- css ( '#filter' ) . remove # these are filters to search through the types and packages
63
- css ( '#library' ) . remove # these are icons at the top
64
- doc
65
- end
66
77
67
- def other
68
- # these are sections of the documentation which do not seem useful
78
+ # Sections of the documentation which do not seem useful
69
79
%w( #inheritedMembers #groupedMembers .permalink .hiddenContent .material-icons ) . each do |selector |
70
80
css ( selector ) . remove
71
81
end
72
82
73
- # This is the kind of thing we have, class, object, trait
74
- kind = at_css ( '.modifier_kind .kind ') . content
75
- # this image replacement doesn't do anything on 2.12 docs
76
- img = at_css ( 'img' )
77
- img . replace %Q|<span class="img_kind"> #{ kind } </span>| unless img . nil?
78
- class_to_add = kind == 'object' ? 'value' : 'type'
83
+ # Things that are not shown on the site, like deprecated members
84
+ css ( 'li[visbl=prt] ') . remove
85
+ end
86
+
87
+ def add_title
88
+ css ( '.permalink' ) . remove
79
89
80
- # for 2.10, 2.11, the kind class is associated to the body. we have to
81
- # add it somewhere, so we do that with the #definition.
82
- definition = css ( '#definition' )
83
- definition . css ( '.big_circle' ) . remove
84
- definition . add_class class_to_add
90
+ definition = at_css ( '#definition' )
91
+ return if definition . nil?
85
92
86
- # this is something that is not shown on the site, such as deprecated members
87
- css ( 'li[visbl=prt]' ) . remove
93
+ type_full_name = { a : 'Annotation' , c : 'Class' , t : 'Trait' , o : 'Object' , p : 'Package' }
94
+ type = type_full_name [ definition . at_css ( '.big-circle' ) . text . to_sym ]
95
+ name = CGI . escapeHTML definition . at_css ( 'h1' ) . text
88
96
89
- doc
90
- end
97
+ package = definition . at_css ( '#owner' ) . text rescue ''
98
+ package = package + '.' unless name . empty? || package . empty?
91
99
92
- private
100
+ other = definition . at_css ( '.morelinks' ) . dup
101
+ other_content = other ? "<h3>#{ other . to_html } </h3>" : ''
93
102
94
- def change_tag! ( new_tag , node )
95
- node . replace %Q|<#{ new_tag } >#{ node . inner_html } </#{ new_tag } >|
103
+ title_content = root_page? ? 'Package root' : "#{ type } #{ package } #{ name } " . strip
104
+ title = "<h1>#{ title_content } </h1>"
105
+ definition . replace title + other_content
96
106
end
97
107
end
98
108
end
0 commit comments