diff --git a/lib/docs/filters/html/entries.rb b/lib/docs/filters/html/entries.rb index b2e7428d..ef8a80be 100644 --- a/lib/docs/filters/html/entries.rb +++ b/lib/docs/filters/html/entries.rb @@ -3,13 +3,17 @@ module Docs class EntriesFilter < Docs::EntriesFilter HTML5 = %w(content element video) OBSOLETE = %w(frame frameset hgroup noframes) - ADDITIONAL_ENTRIES = { 'Heading_Elements' => (1..6).map { |n| ["h#{n}"] } } + ADDITIONAL_ENTRIES = { 'Element/Heading_Elements' => (1..6).map { |n| ["h#{n}"] } } def get_name - super.downcase + name = super + name.remove!('Element.').try(:downcase!) + name end def get_type + slug = self.slug.remove('Element/') + if at_css('.obsoleteHeader', '.deprecatedHeader', '.nonStandardHeader') || OBSOLETE.include?(slug) 'Obsolete' else @@ -23,11 +27,21 @@ module Docs end def include_default_entry? - slug != 'Heading_Elements' + !%w(Attributes Element/Heading_Elements).include?(slug) end def additional_entries - ADDITIONAL_ENTRIES[slug] || [] + return ADDITIONAL_ENTRIES[slug] if ADDITIONAL_ENTRIES.key?(slug) + + if slug == 'Attributes' + css('.standard-table td:first-child').map do |node| + name = node.content.strip + id = node.parent['id'] = name.parameterize + [name, id, 'Attributes'] + end + else + [] + end end def html5_spec?(spec) diff --git a/lib/docs/scrapers/mdn/html.rb b/lib/docs/scrapers/mdn/html.rb index 27fa998b..a63aff06 100644 --- a/lib/docs/scrapers/mdn/html.rb +++ b/lib/docs/scrapers/mdn/html.rb @@ -1,26 +1,32 @@ module Docs class Html < Mdn self.name = 'HTML' - self.base_url = 'https://developer.mozilla.org/en-US/docs/Web/HTML/Element' + self.base_url = 'https://developer.mozilla.org/en-US/docs/Web/HTML' + self.root_path = '/Element' + self.initial_paths = %w(/Attributes) html_filters.push 'html/clean_html', 'html/entries', 'title' options[:root_title] = 'HTML' options[:title] = ->(filter) do - if filter.slug == 'Heading_Elements' + if filter.slug == 'Element/Heading_Elements' 'Heading Elements' + elsif filter.slug == 'Attributes' + 'Attributes' else "<#{filter.default_title}>" end end + options[:only_patterns] = [/\A\/Element/] + options[:replace_paths] = { - '/h1' => '/Heading_Elements', - '/h2' => '/Heading_Elements', - '/h3' => '/Heading_Elements', - '/h4' => '/Heading_Elements', - '/h5' => '/Heading_Elements', - '/h6' => '/Heading_Elements' } + '/Element/h1' => '/Element/Heading_Elements', + '/Element/h2' => '/Element/Heading_Elements', + '/Element/h3' => '/Element/Heading_Elements', + '/Element/h4' => '/Element/Heading_Elements', + '/Element/h5' => '/Element/Heading_Elements', + '/Element/h6' => '/Element/Heading_Elements' } end end