Fix the missing table of content

This commit is contained in:
Wei Feng 2018-08-02 23:10:01 +10:00
parent efcb93606d
commit c845f31676
1 changed files with 18 additions and 1 deletions

View File

@ -11,7 +11,11 @@ html = ''
chapter_links.each do |chapter_link|
chapter_file = File.basename chapter_link
html += "<span class=\"hidden\" name=\"#{chapter_file}\"></span>"
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