Merge pull request #10 from windix/ruby

Fix the missing table of content
This commit is contained in:
Nemo 2018-08-02 20:15:55 +05:30 committed by GitHub
commit 15d2d5a554
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 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,17 @@ 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')
end
# replace h1 title
content.at_css('h1').inner_html = title
html += content.inner_html
end