Browse Source

Update C/C++ documentation

Fixes #688.
Fixes #736.
Thibaut Courouble 7 years ago
parent
commit
472f03d5b0

+ 2 - 0
assets/stylesheets/pages/_c.scss

@@ -46,6 +46,8 @@
 
       + div { margin-left: .5em; }
     }
+
+    > table { margin: 0; }
   }
 
   .t-dcl-rev-aux > td:empty { padding: 0; }

+ 4 - 1
lib/docs/core/scrapers/file_scraper.rb

@@ -39,7 +39,10 @@ module Docs
     end
 
     def read_file(path)
-      File.read(path) rescue nil
+      File.read(path)
+    rescue
+      puts "Failed to open file: #{path}"
+      nil
     end
   end
 end

+ 11 - 2
lib/docs/filters/c/clean_html.rb

@@ -4,12 +4,17 @@ module Docs
       def call
         css('h1').remove if root_page?
 
+        css('.t-dcl-rev-aux td[rowspan]').each do |node|
+          rowspan = node['rowspan'].to_i
+          node['rowspan'] = node.ancestors('tbody').css('tr').length if rowspan > 3
+        end
+
         css('#siteSub', '#contentSub', '.printfooter', '.t-navbar', '.editsection', '#toc',
             '.t-dsc-sep', '.t-dcl-sep', '#catlinks', '.ambox-notice', '.mw-cite-backlink',
             '.t-sdsc-sep:first-child:last-child', '.t-example-live-link',
             '.t-dcl-rev-num > .t-dcl-rev-aux ~ tr:not(.t-dcl-rev-aux) > td:nth-child(2)').remove
 
-        css('#bodyContent', '.mw-content-ltr', 'span[style]', 'div[class^="t-ref"]',
+        css('#bodyContent', '.mw-content-ltr', 'span[style]', 'div[class^="t-ref"]', '.t-image',
             'th > div', 'td > div', '.t-dsc-see', '.mainpagediv', 'code > b', 'tbody').each do |node|
           node.before(node.children).remove
         end
@@ -78,7 +83,7 @@ module Docs
           end
           node.inner_html = node.inner_html.strip
           node << '.' if node.content =~ /[a-zA-Z0-9\)]\z/
-          node.remove if node.content.blank?
+          node.remove if node.content.blank? && !node.at_css('img')
         end
 
         css('pre').each do |node|
@@ -100,6 +105,10 @@ module Docs
           node.content = node.content
         end
 
+        css('img').each do |node|
+          node['src'] = node['src'].sub! %r{http://en.cppreference.com/common/([^"']+?)\.svg}, 'http://upload.cppreference.com/mwiki/\1.svg'
+        end
+
         doc
       end
     end

+ 0 - 1
lib/docs/filters/cpp/fix_urls.rb

@@ -4,7 +4,6 @@ module Docs
       def call
         html.gsub! File.join(Cpp.base_url, Cpp.root_path), Cpp.base_url[0..-2]
         html.gsub! %r{#{Cpp.base_url}([^"']+?)\.html}, "#{Cpp.base_url}\\1"
-        html.gsub! %r{http://en.cppreference.com/common/([^"']+?)\.svg}, 'http://upload.cppreference.com/mwiki/\1.svg'
         html
       end
     end

+ 7 - 0
lib/docs/scrapers/c.rb

@@ -9,6 +9,7 @@ module Docs
     html_filters.push 'c/entries', 'c/clean_html', 'title'
     text_filters.push 'c/fix_urls'
 
+    options[:decode_and_clean_paths] = true
     options[:container] = '#content'
     options[:title] = false
     options[:root_title] = 'C Programming Language'
@@ -25,5 +26,11 @@ module Docs
       &copy; cppreference.com<br>
       Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
     HTML
+
+    private
+
+    def file_path_for(*)
+      URI.unescape(super)
+    end
   end
 end

+ 7 - 0
lib/docs/scrapers/cpp.rb

@@ -11,6 +11,7 @@ module Docs
     html_filters.push 'cpp/entries', 'c/clean_html', 'title'
     text_filters.push 'cpp/fix_urls'
 
+    options[:decode_and_clean_paths] = true
     options[:container] = '#content'
     options[:title] = false
     options[:root_title] = 'C++ Programming Language'
@@ -33,5 +34,11 @@ module Docs
       &copy; cppreference.com<br>
       Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
     HTML
+
+    private
+
+    def file_path_for(*)
+      URI.unescape(super)
+    end
   end
 end