Browse Source

Add LaTeX documentation from https://latexref.xyz

From https://ctan.org/pkg/latex2e-help-texinfo, the license is Public Domain.
Cimbali 6 năm trước cách đây
mục cha
commit
776ec5a35d

+ 20 - 0
lib/docs/filters/latex/clean_html.rb

@@ -0,0 +1,20 @@
+module Docs
+  class Latex
+    class CleanHtmlFilter < Filter
+      def call
+        css('hr, div.header, div.referenceinfo').remove
+        css('div.shortcontents, div.contents, h2.shortcontents-heading, h2.contents-heading, h1.settitle').remove if root_page?
+
+        css('span[id] + h1, span[id] + h2, span[id] + h3, span[id] + h4, span[id] + h5, span[id] + h6').each do |node|
+          id = node.previous['id']
+          node.previous.remove
+          node['id'] = id.sub(/-\d$/, '') if id
+        end
+
+        css('h1, h2, h3, h4').each { |node| node.content = node.content.sub /^[0-9A-Z]+(\.[0-9]+)* /, '' }
+
+        doc
+      end
+    end
+  end
+end

+ 46 - 0
lib/docs/filters/latex/entries.rb

@@ -0,0 +1,46 @@
+module Docs
+  class Latex
+    class EntriesFilter < Docs::EntriesFilter
+
+      @@entries = Hash.new
+
+      def initialize(*)
+        super
+
+        return unless root_page?
+
+        css('.contents > ul > li').each do |node|
+          lev1 = node.at_css('> a:first-child').text.sub /^[0-9A-Z]+(\.[0-9]+)* /, ''
+          node.css('a').each do |link|
+            href = link['href'].split('#')[0].parameterize.downcase
+            @@entries[href] = lev1
+          end
+        end
+
+      end
+
+      def get_name
+        at_css('h1, h2, h3, h4, h5, h6').content.sub /^[0-9A-Z]+(\.[0-9]+)* /, ''
+      end
+
+      def get_type
+        begin
+          return @@entries[slug.downcase]
+        rescue
+          return "Missing type with slug #{slug}"
+        end
+      end
+
+      def include_default_entry?
+        true
+      end
+
+      def additional_entries
+        return []
+      end
+
+      private
+
+    end
+  end
+end

+ 22 - 0
lib/docs/scrapers/latex.rb

@@ -0,0 +1,22 @@
+module Docs
+  class Latex < UrlScraper
+    self.name = 'LaTeX'
+    self.slug = 'latex'
+    self.type = 'simple'
+    self.links = {
+        home: 'https://ctan.org/pkg/latex2e-help-texinfo/'
+    }
+
+    self.base_url = 'http://latexref.xyz'
+
+    html_filters.push 'latex/entries', 'latex/clean_html'
+
+    options[:skip_patterns] = [/^\/dev\//, /\.(dvi|pdf)$/]
+
+    options[:attribution] = <<-HTML
+      &copy; 2007–2018 Karl Berry<br>
+      Public Domain Software
+    HTML
+
+  end
+end

BIN
public/icons/docs/latex/16.png


BIN
public/icons/docs/latex/16@2x.png


+ 1 - 0
public/icons/docs/latex/SOURCE

@@ -0,0 +1 @@
+Compiling \LaTeX with pdflatex https://www.tug.org/applications/pdftex/