mirror of https://github.com/freeCodeCamp/devdocs
parent
175308b914
commit
58c57e02b6
@ -0,0 +1,69 @@
|
|||||||
|
module Docs
|
||||||
|
class Bootstrap
|
||||||
|
class CleanHtmlV4Filter < Filter
|
||||||
|
def call
|
||||||
|
@doc = at_css('.bd-content')
|
||||||
|
|
||||||
|
at_css('h1').content = 'Bootstrap 4' if root_page?
|
||||||
|
|
||||||
|
css('hr', '.bd-clipboard', '.modal', '.bd-example .bd-example').remove
|
||||||
|
|
||||||
|
css('#markdown-toc-contents').each do |node|
|
||||||
|
node.parent.remove
|
||||||
|
end
|
||||||
|
|
||||||
|
css('.bd-example-row', '.table-responsive').each do |node|
|
||||||
|
node.before(node.children).remove
|
||||||
|
end
|
||||||
|
|
||||||
|
css('.bd-example', '.responsive-utilities-test').each do |node|
|
||||||
|
if node.previous_element['class'].try(:include?, 'bd-example')
|
||||||
|
node.remove
|
||||||
|
else
|
||||||
|
node.content = ''
|
||||||
|
node.name = 'p'
|
||||||
|
node['class'] = 'bd-example'
|
||||||
|
node.remove_attribute('data-example-id')
|
||||||
|
prev = node.previous_element
|
||||||
|
prev = prev.previous_element until prev['id']
|
||||||
|
node.inner_html = %(<a href="#{current_url}/##{prev['id']}">Open example on getbootstrap.com</a>)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
css('.bd-example + .highlight').each do |node|
|
||||||
|
node.previous_element.name = 'div'
|
||||||
|
end
|
||||||
|
|
||||||
|
css('div[class*="col-"]').each do |node|
|
||||||
|
node['class'] = 'col'
|
||||||
|
end
|
||||||
|
|
||||||
|
css('.__cf_email__').each do |node|
|
||||||
|
node.replace(decode_cloudflare_email(node['data-cfemail']))
|
||||||
|
end
|
||||||
|
|
||||||
|
css('.highlight').each do |node|
|
||||||
|
code = node.at_css('code')
|
||||||
|
node['data-language'] = code['data-lang']
|
||||||
|
node.content = code.content
|
||||||
|
node.name = 'pre'
|
||||||
|
end
|
||||||
|
|
||||||
|
css('bd-callout h3').each do |node|
|
||||||
|
node.name = 'h4'
|
||||||
|
end
|
||||||
|
|
||||||
|
css('table, tr, td, th, pre, code').each do |node|
|
||||||
|
node.remove_attribute('class')
|
||||||
|
node.remove_attribute('style')
|
||||||
|
end
|
||||||
|
|
||||||
|
css('[class*="bd-"]').each do |node|
|
||||||
|
node['class'] = node['class'].gsub('bd-', 'bs-')
|
||||||
|
end
|
||||||
|
|
||||||
|
doc
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,62 @@
|
|||||||
|
module Docs
|
||||||
|
class Bootstrap
|
||||||
|
class EntriesV4Filter < Docs::EntriesFilter
|
||||||
|
def get_name
|
||||||
|
name = at_css('.bd-content h1').content.strip
|
||||||
|
name.remove! ' system'
|
||||||
|
return type if name == 'Overview'
|
||||||
|
name
|
||||||
|
end
|
||||||
|
|
||||||
|
def get_type
|
||||||
|
if subpath.start_with?('components')
|
||||||
|
at_css('.bd-content h1').content.strip.prepend 'Components: '
|
||||||
|
else
|
||||||
|
at_css('.bd-pageheader h1').content
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def additional_entries
|
||||||
|
return [] if root_page? || subpath.start_with?('getting-started')
|
||||||
|
entries = []
|
||||||
|
|
||||||
|
css('#markdown-toc > li > a', '#markdown-toc > li li #markdown-toc-events').each do |node|
|
||||||
|
name = node.content
|
||||||
|
next if name =~ /example/i || IGNORE_ENTRIES.include?(name)
|
||||||
|
name.downcase!
|
||||||
|
name.prepend "#{self.name}: "
|
||||||
|
id = node['href'].remove('#')
|
||||||
|
entries << [name, id]
|
||||||
|
end
|
||||||
|
|
||||||
|
css("#options + p + div tbody td:first-child").each do |node|
|
||||||
|
name = node.content.strip
|
||||||
|
id = node.parent['id'] = "#{name.parameterize}-option"
|
||||||
|
name.prepend "#{self.name}: "
|
||||||
|
name << ' (option)'
|
||||||
|
entries << [name, id]
|
||||||
|
end
|
||||||
|
|
||||||
|
css("#methods + table tbody td:first-child, #methods ~ h4 code").each do |node|
|
||||||
|
next unless name = node.content[/\('(\w+)'\)/, 1]
|
||||||
|
id = node.parent['id'] = "#{name.parameterize}-method"
|
||||||
|
name.prepend "#{self.name}: "
|
||||||
|
name << ' (method)'
|
||||||
|
entries << [name, id]
|
||||||
|
end
|
||||||
|
|
||||||
|
entries
|
||||||
|
end
|
||||||
|
|
||||||
|
IGNORE_ENTRIES = %w(
|
||||||
|
Contents
|
||||||
|
How\ it\ works
|
||||||
|
Approach
|
||||||
|
JavaScript\ behavior
|
||||||
|
Usage
|
||||||
|
Basics
|
||||||
|
Overview
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in new issue