Skip to content

Commit

Permalink
Merge pull request rails#48521 from flavorjones/flavorjones-update-ra…
Browse files Browse the repository at this point in the history
…ils-guides-to-html5

Update guides generation to use Nokogiri's HTML5 parser
  • Loading branch information
guilleiguaran authored Jun 20, 2023
2 parents 52ca1b6 + cbc7909 commit e05245d
Showing 1 changed file with 11 additions and 3 deletions.
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

0 comments on commit e05245d

Please sign in to comment.