Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update guides generation to use Nokogiri's HTML5 parser #48521

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 11 additions & 3 deletions guides/rails_guides/markdown.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def generate_description
def generate_structure
@headings_for_index = []
if @body.present?
document = Nokogiri::HTML.fragment(@body).tap do |doc|
document = html_fragment(@body).tap do |doc|
hierarchy = []

doc.children.each do |node|
Expand Down Expand Up @@ -136,7 +136,7 @@ def generate_index
end
end

@index = Nokogiri::HTML.fragment(engine.render(raw_index)).tap do |doc|
@index = html_fragment(engine.render(raw_index)).tap do |doc|
doc.at("ol")[:class] = "chapters"
end.to_html

Expand All @@ -150,7 +150,7 @@ def generate_index
end

def generate_title
if heading = Nokogiri::HTML.fragment(@header).at(:h1)
if heading = html_fragment(@header).at(:h1)
@title = "#{heading.text} — Ruby on Rails Guides"
else
@title = "Ruby on Rails Guides"
Expand Down Expand Up @@ -180,5 +180,13 @@ def render_page
@view.content_for(:index_section) { @index }
@view.render(layout: @layout, html: @body.html_safe)
end

def html_fragment(html)
if defined?(Nokogiri::HTML5)
Nokogiri::HTML5.fragment(html)
else
Nokogiri::HTML4.fragment(html)
end
end
end
end