| @@ -102,7 +102,6 @@ module Docs · 101 unmodified lines |
| 102 | 102 | end |
| 103 | 103 | |
| 104 | 104 | attributes = at_css('.attributes') |
| 105 | | − attributes.add_previous_sibling('<h3>Metadata</h3>') |
| 106 | 105 | |
| 107 | 106 | tabs_names = css('.tabs.single .names .tab') |
| 108 | 107 | tabs_contents = css('.tabs.single .contents .tab') |
| @@ -112,7 +111,11 @@ module Docs · 3 unmodified lines |
| 112 | 111 | attributes.add_child("<dt>#{name.content}</dt>") |
| 113 | 112 | attributes.add_child("<dd>#{contents.inner_html.strip}</dd>") |
| 114 | 113 | end |
| 115 | | − at_css('.tabs').remove |
| 114 | + |
| 115 | + convert_dl_to_table(attributes) |
| 116 | + |
| 117 | + tabs = at_css('.tabs') |
| 118 | + tabs.remove unless tabs.nil? || tabs.parent['class'] == 'membersList' |
| 116 | 119 | end |
| 117 | 120 | |
| 118 | 121 | def format_members |
| @@ -138,7 +141,7 @@ module Docs · 19 unmodified lines |
| 138 | 141 | |
| 139 | 142 | id = element['id'] |
| 140 | 143 | element.remove_attribute('id') |
| 141 | | − header['id'] = id |
| 144 | + header['id'] = id unless id.nil? |
| 142 | 145 | |
| 143 | 146 | annotations = element.at_css('.annotations') |
| 144 | 147 | annotations.name = 'small' |
| @@ -158,6 +161,10 @@ module Docs · 13 unmodified lines |
| 158 | 161 | dd.remove |
| 159 | 162 | end |
| 160 | 163 | |
| 164 | + # Format attributes as a table |
| 165 | + dl = element.at_css('.attributes') |
| 166 | + convert_dl_to_table(dl) unless dl.nil? |
| 167 | + |
| 161 | 168 | # Remove the unnecessary wrapper element |
| 162 | 169 | element.replace(element.inner_html) |
| 163 | 170 | end |
| @@ -176,6 +183,26 @@ module Docs · 12 unmodified lines |
| 176 | 183 | end |
| 177 | 184 | end |
| 178 | 185 | |
| 186 | + def convert_dl_to_table(dl) |
| 187 | + table = Nokogiri::XML::Node.new('table', doc) |
| 188 | + table['class'] = 'attributes' |
| 189 | + |
| 190 | + dl.css('> dt').each do |dt| |
| 191 | + dd = dt.next_element |
| 192 | + has_dd = dd.name == 'dd' rescue false |
| 193 | + |
| 194 | + tr = Nokogiri::XML::Node.new('tr', doc) |
| 195 | + colspan = has_dd ? '' : ' colspan="2"' # handle <dt> without following <dt> |
| 196 | + tr.add_child("<th#{colspan}>#{dt.inner_html.sub(/:$/, '')}</th>") |
| 197 | + |
| 198 | + tr.add_child("<td>#{dd.inner_html}</td>") if has_dd |
| 199 | + |
| 200 | + table.add_child(tr) |
| 201 | + end |
| 202 | + |
| 203 | + dl.replace(table) |
| 204 | + end |
| 205 | + |
| 179 | 206 | end |
| 180 | 207 | end |
| 181 | 208 | end |