mirror of https://github.com/freeCodeCamp/devdocs
commit
2488740dfb
@ -0,0 +1,74 @@
|
|||||||
|
module Docs
|
||||||
|
class GnuCobol
|
||||||
|
class CleanHtmlFilter < Filter
|
||||||
|
def call
|
||||||
|
# Replace the title
|
||||||
|
at_css('.settitle').content = 'GnuCOBOL'
|
||||||
|
|
||||||
|
# Remove the Table of Contents
|
||||||
|
# It's huge and the DevDocs sidebar is basically a direct copy
|
||||||
|
css('.contents, .contents-heading').remove
|
||||||
|
|
||||||
|
# Remove the changelog
|
||||||
|
at_css('p').remove
|
||||||
|
at_css('ol').remove
|
||||||
|
|
||||||
|
# Remove horizontal lines
|
||||||
|
css('hr').remove
|
||||||
|
|
||||||
|
# Remove acronym tags but keep the content
|
||||||
|
css('acronym').each {|node| node.name = 'span'}
|
||||||
|
|
||||||
|
# Remove everything after Appendix B
|
||||||
|
# This includes the license text, the document changelog, the compiler changelog and the footnote
|
||||||
|
current_element = at_css('a[name="Appendix-C-_002d-GNU-Free-Documentation-License"]').previous
|
||||||
|
until current_element.nil?
|
||||||
|
next_element = current_element.next
|
||||||
|
current_element.remove
|
||||||
|
current_element = next_element
|
||||||
|
end
|
||||||
|
|
||||||
|
# Make headers bigger
|
||||||
|
css('h4').each {|node| node.name = 'h3'}
|
||||||
|
css('h3.unnumberedsec').each {|node| node.name = 'h2'}
|
||||||
|
|
||||||
|
# Remove the newlines
|
||||||
|
# All paragraphs are inside <p> tags already anyways
|
||||||
|
css('br').remove
|
||||||
|
|
||||||
|
# The original document contains sub-headers surrounded by equal signs
|
||||||
|
# Convert those to actual header elements
|
||||||
|
css('div[align="center"]').each do |node|
|
||||||
|
if node.content.include?('=' * 50)
|
||||||
|
previous = node.previous_element
|
||||||
|
if !previous.nil? && previous.name == 'div' && previous['align'] == 'center'
|
||||||
|
previous.name = 'h4'
|
||||||
|
end
|
||||||
|
|
||||||
|
node.remove
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Remove align="center" attributes
|
||||||
|
css('[align="center"]').remove_attribute('align')
|
||||||
|
|
||||||
|
# Convert tt tags into inline code blocks and remove any surrounding quotes
|
||||||
|
css('tt').each do |node|
|
||||||
|
node.name = 'code'
|
||||||
|
|
||||||
|
previous_node = node.previous
|
||||||
|
if !previous_node.nil? && previous_node.text?
|
||||||
|
previous_node.content = previous_node.content.sub(/([^"]?")\Z/, '')
|
||||||
|
end
|
||||||
|
|
||||||
|
next_node = node.next
|
||||||
|
if !next_node.nil? && next_node.text?
|
||||||
|
next_node.content = next_node.content.sub(/\A("[^"]?)/, '')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
doc
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,50 @@
|
|||||||
|
module Docs
|
||||||
|
class GnuCobol
|
||||||
|
class EntriesFilter < Docs::EntriesFilter
|
||||||
|
# The entire reference is one big page, so get_name and get_type are not necessary
|
||||||
|
|
||||||
|
def additional_entries
|
||||||
|
entries = []
|
||||||
|
|
||||||
|
css('.contents > ul > li:not(:last-child)').each do |node|
|
||||||
|
parent = node.at_css('a')
|
||||||
|
|
||||||
|
entries << create_entry(parent, parent)
|
||||||
|
|
||||||
|
node.css('ul a').each do |link|
|
||||||
|
entries << create_entry(parent, link)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
entries.compact
|
||||||
|
end
|
||||||
|
|
||||||
|
def create_entry(parent_link, current_link)
|
||||||
|
name = current_link.content
|
||||||
|
id = current_link['href'][1..-1]
|
||||||
|
type = parent_link.content
|
||||||
|
|
||||||
|
# The navigation link don't actually navigate to the correct header
|
||||||
|
# Instead, it references an `a` tag above it
|
||||||
|
# The `a` tag it is referencing is removed by a filter further down the pipeline
|
||||||
|
# This adds the id to the correct header element
|
||||||
|
target_node = at_css("a[name='#{id}']")
|
||||||
|
target_node.next_element.next_element['id'] = id
|
||||||
|
|
||||||
|
if name.start_with?('Appendix')
|
||||||
|
type = 'Appendices'
|
||||||
|
end
|
||||||
|
|
||||||
|
# Everything after Appendix B is removed by the clean_html filter
|
||||||
|
ignored_names = [
|
||||||
|
'Appendix C - GNU Free Documentation License',
|
||||||
|
'Appendix D - Summary of Document Changes',
|
||||||
|
'Appendix E - Summary of Compiler Changes since 2009 and version v1-1',
|
||||||
|
'Index'
|
||||||
|
]
|
||||||
|
|
||||||
|
ignored_names.include?(name) ? nil : [name, id, type]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,26 @@
|
|||||||
|
module Docs
|
||||||
|
class GnuCobol < UrlScraper
|
||||||
|
self.name = 'GnuCOBOL'
|
||||||
|
self.slug = 'gnu_cobol'
|
||||||
|
self.type = 'simple'
|
||||||
|
self.release = '2.2'
|
||||||
|
self.base_url = 'https://open-cobol.sourceforge.io/HTML/gnucobpg.html'
|
||||||
|
self.links = {
|
||||||
|
home: 'https://sourceforge.net/projects/open-cobol/',
|
||||||
|
code: 'https://sourceforge.net/p/open-cobol/code/HEAD/tree/trunk/'
|
||||||
|
}
|
||||||
|
|
||||||
|
html_filters.push 'gnu_cobol/entries', 'gnu_cobol/clean_html'
|
||||||
|
|
||||||
|
options[:attribution] = <<-HTML
|
||||||
|
Copyright © 2000, 2001, 2002, 2007, 2008 Free Software Foundation, Inc.<br>
|
||||||
|
Licensed under the GNU Free Documentation License.
|
||||||
|
HTML
|
||||||
|
|
||||||
|
def get_latest_version(opts)
|
||||||
|
doc = fetch_doc('https://open-cobol.sourceforge.io/HTML/gnucobpg.html', opts)
|
||||||
|
title = doc.at_css('h1').content
|
||||||
|
title.scan(/([0-9.]+)/)[0][0]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
After Width: | Height: | Size: 661 B |
After Width: | Height: | Size: 1.9 KiB |
@ -0,0 +1 @@
|
|||||||
|
https://sourceforge.net/p/open-cobol/icon
|
Loading…
Reference in new issue