Currently, the TOC consists of the chapter title and all of the h3 headers in the document. What we need to do is loop through the document, fetch all of the h2 headers as well as the h3 headers in between and print them in there proper order, which is a little bit more complex, but definitely possible with nokogiri.