- Add elisp.rb, clean_html.rb and entries.rb
Unified · Split
| @@ -0,0 +1,56 @@ | ||
| 1 | +module Docs | |
| 2 | + class Elisp | |
| 3 | + class CleanHtmlFilter < Filter | |
| 4 | + def call | |
| 5 | + | |
| 6 | + if current_url == root_url | |
| 7 | + # remove copyright header | |
| 8 | + css('table ~ p').remove | |
| 9 | + | |
| 10 | + # remove "Detailed Node Listing" header | |
| 11 | + css('h3').remove | |
| 12 | + | |
| 13 | + # remove "Detailed Node Listing" table | |
| 14 | + css('table')[1].remove | |
| 15 | + | |
| 16 | + # remove copyright | |
| 17 | + css('blockquote').remove | |
| 18 | + | |
| 19 | + # remove index page in the index table | |
| 20 | + css('tbody tr:last-child').remove | |
| 21 | + end | |
| 22 | + | |
| 23 | + # remove navigation bar | |
| 24 | + css('.node').remove | |
| 25 | + | |
| 26 | + # Remove content in headers | |
| 27 | + css('h2', 'h3', 'h4', 'h5', 'h6').each do |node| | |
| 28 | + | |
| 29 | + # remove numbers at the beginning of all headers | |
| 30 | + node.content = node.content.slice(/[[:alpha:]]...*/) | |
| 31 | + | |
| 32 | + # remove 'Appendix' word | |
| 33 | + node.content = node.content.sub(/Appendix.{2}/, '') if node.content.include?('Appendix') | |
| 34 | + | |
| 35 | + # remove 'E.' notation for appendixes | |
| 36 | + if node.content.match?(/[[:upper:]]\./) | |
| 37 | + # remove 'E.' | |
| 38 | + node.content = node.content.sub(/[[:upper:]]\./, '') | |
| 39 | + # remove all dots (.) | |
| 40 | + node.content = node.content.gsub(/\./, '') | |
| 41 | + # remove all numbers | |
| 42 | + node.content = node.content.gsub(/[[:digit:]]/, '') | |
| 43 | + end | |
| 44 | + | |
| 45 | + end | |
| 46 | + | |
| 47 | + # add id to each defun section that contains a functions, macro, etc. | |
| 48 | + css('.defun').each do |node| | |
| 49 | + node['id']= node.first_element_child.content | |
| 50 | + end | |
| 51 | + | |
| 52 | + doc | |
| 53 | + end | |
| 54 | + end | |
| 55 | + end | |
| 56 | +end | |
| @@ -0,0 +1,50 @@ | ||
| 1 | +module Docs | |
| 2 | + class Elisp | |
| 3 | + class EntriesFilter < Docs::EntriesFilter | |
| 4 | + def get_name | |
| 5 | + # remove numbers at the beginnig | |
| 6 | + name = at_css('h2', 'h3', 'h4', 'h5', 'h6').content.slice(/[[:alpha:]]...*/) | |
| 7 | + | |
| 8 | + # remove 'Appendix' word | |
| 9 | + name = name.sub(/Appendix.{2}/, '') if name.include?('Appendix') | |
| 10 | + | |
| 11 | + # remove 'E.' notation for appendixes | |
| 12 | + if name.match?(/[[:upper:]]\./) | |
| 13 | + # remove 'E.' | |
| 14 | + name = name.sub(/[[:upper:]]\./, '') | |
| 15 | + # remove all dots (.) | |
| 16 | + name = name.gsub(/\./, '') | |
| 17 | + # remove all numbers | |
| 18 | + name = name.gsub(/[[:digit:]]/, '') | |
| 19 | + end | |
| 20 | + | |
| 21 | + name | |
| 22 | + end | |
| 23 | + | |
| 24 | + def get_type | |
| 25 | + 'Manual' | |
| 26 | + end | |
| 27 | + | |
| 28 | + def additional_entries | |
| 29 | + entries = [] | |
| 30 | + | |
| 31 | + css('.defun').each do |node| | |
| 32 | + entry_type = 'Builtin Functions' if node.content.include?('Function') | |
| 33 | + entry_type = 'Builtin Macros' if node.content.include?('Macro') | |
| 34 | + entry_type = 'Builtin Variables' if node.content.include?('Variable') | |
| 35 | + entry_type = 'Builtin User Options' if node.content.include?('User Option') | |
| 36 | + entry_type = 'Builtin Special Forms' if node.content.include?('Special Form') | |
| 37 | + entry_type = 'Builtin Commands' if node.content.include?('Command') | |
| 38 | + entry_type = 'Builtin Constants' if node.content.include?('Constant') | |
| 39 | + | |
| 40 | + entry_name = node.first_element_child.content | |
| 41 | + entry_path = slug + '#' + entry_name | |
| 42 | + entries << [entry_name, entry_path.downcase, entry_type] | |
| 43 | + end | |
| 44 | + | |
| 45 | + entries | |
| 46 | + end | |
| 47 | + | |
| 48 | + end | |
| 49 | + end | |
| 50 | +end | |
| @@ -0,0 +1,65 @@ | ||
| 1 | +module Docs | |
| 2 | + class Elisp < UrlScraper | |
| 3 | + self.type = 'elisp' | |
| 4 | + self.release = '26.3' | |
| 5 | + self.base_url= 'https://www.gnu.org/software/emacs/manual/html_node/elisp/' | |
| 6 | + self.root_path = 'index.html' | |
| 7 | + self.links = { | |
| 8 | + home:'https://www.gnu.org/software/emacs/manual/elisp', | |
| 9 | + code: 'https://git.savannah.gnu.org/cgit/emacs.git' | |
| 10 | + } | |
| 11 | + | |
| 12 | + html_filters.push 'elisp/entries', 'elisp/clean_html' | |
| 13 | + | |
| 14 | + # some file that were not skipped by skip patterns | |
| 15 | + options[:skip] = [ | |
| 16 | + 'Coding-Conventions.html', | |
| 17 | + 'Key-Binding-Conventions.html', | |
| 18 | + 'Library-Headers.html' | |
| 19 | + ] | |
| 20 | + | |
| 21 | + # some non essential sections | |
| 22 | + options[:skip_patterns] = [ | |
| 23 | + /Introduction.html/, | |
| 24 | + /Antinews.html/, | |
| 25 | + /GNU-Free-Documentation-License.html/, | |
| 26 | + /GPL.html/, | |
| 27 | + /Tips.html/, | |
| 28 | + /Definition-of-/ | |
| 29 | + ] | |
| 30 | + | |
| 31 | + # fix duplicates | |
| 32 | + options[:fix_urls]= -> (url) do | |
| 33 | + url.sub!('Window-Group.html', 'Basic-Windows.html') | |
| 34 | + url.sub!('Local-defvar-example.html', 'Using-Lexical-Binding.html') | |
| 35 | + url.sub!('Defining-Lisp-variables-in-C.html', 'Writing-Emacs-Primitives.html') | |
| 36 | + url.sub!('describe_002dsymbols-example.html', 'Accessing-Documentation.html') | |
| 37 | + url.sub!('The-interactive_002donly-property.html', 'Defining-Commands.html') | |
| 38 | + url.sub!('Text-help_002decho.html', 'Special-Properties.html') | |
| 39 | + url.sub!('Help-display.html', 'Special-Properties.html') | |
| 40 | + url.sub!('autoload-cookie.html', 'Autoload.html') | |
| 41 | + url.sub!('external_002ddebugging_002doutput.html', 'Output-Streams.html') | |
| 42 | + url.sub!('modifier-bits.html', 'Other-Char-Bits.html') | |
| 43 | + url.sub!('message_002dbox.html', 'Displaying-Messages.html') | |
| 44 | + url.sub!('abbreviate_002dfile_002dname.html', 'Directory-Names.html') | |
| 45 | + url.sub!('Inhibit-point-motion-hooks.html', 'Special-Properties.html') | |
| 46 | + url.sub!('Coding-systems-for-a-subprocess.html', 'Process-Information.html') | |
| 47 | + url.sub!('Process-Filter-Example.html', 'Filter-Functions.html') | |
| 48 | + url.sub!('Docstring-hyperlinks.html', 'Documentation-Tips.html') | |
| 49 | + url.sub!('seq_002dlet.html', 'Sequence-Functions.html') | |
| 50 | + url.sub!('should_005fquit.html', 'Module-Misc.html') | |
| 51 | + url.sub!('Display-Face-Attribute-Testing.html', 'Display-Feature-Testing.html') | |
| 52 | + url.sub!('module-initialization-function.html', 'Module-Initialization.html') | |
| 53 | + url.sub!('pcase_002dsymbol_002dcaveats.html', 'pcase-Macro.html') | |
| 54 | + url.sub!('intern.html', 'Module-Misc.html') | |
| 55 | + url.sub!('pcase_002dexample_002d1.html', 'pcase-Macro.html') | |
| 56 | + url | |
| 57 | + end | |
| 58 | + | |
| 59 | + options[:attribution]= <<-HTML | |
| 60 | + Copyright © 1990-1996, 1998-2019 Free Software Foundation, Inc. <br> | |
| 61 | + Licensed under the GNU GPL license. | |
| 62 | + HTML | |
| 63 | + | |
| 64 | + end | |
| 65 | +end | |