diff --git a/generate.rb b/generate.rb index d3a613d..12ff007 100644 --- a/generate.rb +++ b/generate.rb @@ -11,7 +11,11 @@ html = '' chapter_links.each do |chapter_link| chapter_file = File.basename chapter_link html += "" - content = Nokogiri::HTML(open("html/#{chapter_link}")).css('.content') + doc = Nokogiri::HTML(open("html/#{chapter_link}")) + content = doc.css('.content') + + # this title is with additional 'chapter X' in front + title = doc.at_css('h2.chapter-title').content content.css('.cont').each do |e| e.remove @@ -57,6 +61,19 @@ chapter_links.each do |chapter_link| end end + if content.children.css('section > h1').length > 0 + # remove additional parent section tag + content = content.children.at_css('section') + elsif content.children.css('div > h1').length > 0 + # remove additional parent div tag + content = content.children.at_css('div') + else + content + end + + # replace h1 title + content.at_css('h1').inner_html = title + html += content.inner_html end