From c845f316765b9bff67ce9b5f0522a46c0e263bcc Mon Sep 17 00:00:00 2001 From: Wei Feng Date: Thu, 2 Aug 2018 23:10:01 +1000 Subject: [PATCH] Fix the missing table of content --- generate.rb | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) 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