Skip to content
This repository has been archived by the owner on Feb 11, 2020. It is now read-only.

Commit

Permalink
fixed issue #1
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandru committed Nov 3, 2011
1 parent 45d6e8b commit 92769ef
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 20 deletions.
33 changes: 13 additions & 20 deletions builder/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,15 @@ task :build_html => :html_files_unzip do
doc.css('blockquote pre').each do |elem|
parent = elem.ancestors('blockquote').first
parent.name = 'pre'
html = elem.inner_html
html = elem.text
html = html.split(/\r?\n/).map{|x| x = " " + x}.join("\n")

unless fpath =~ /Preface/ or fpath =~ /Frontmatter/
html = Pygments.highlight(html, :options => {:noclasses => true}, :lexer => 'cpp')

parent.inner_html = html
parent.inner_html = parent.css('pre').inner_html

# only keeping font styling, not colors
parent.css('span[style]').each do |span|
style = span.attr('style')
Expand Down Expand Up @@ -138,7 +141,7 @@ task :generate_toc => :build_html do
html_files = FileList['build/*.html'].select{|x| x =~ /Chapter|Appendix/}.sort{|a,b| a =~ /Appendix/ && b =~ /Chapter/ ? 1 : (a =~ /Chapter/ && b =~ /Appendix/ ? -1 : a <=> b)}
html_files.insert 0, 'build/Preface.html'

contents_html = "<ul id='toc'>\n"
contents_html = ""

html_files.each do |fpath|
html = File.read(fpath)
Expand All @@ -148,30 +151,20 @@ task :generate_toc => :build_html do
fname = File.basename(fpath)
h1_elem = doc.css('h1')
h1_name = h1_elem.css('a').attr('name').value
h1_text = h1_elem.css('a').inner_html.strip

contents_html += " <li><a href='#{fname}##{h1_name}'>#{h1_text}</a></li>\n"
started = false
h1_text = h1_elem.text.gsub(/[\n\r\s]+/, ' ').strip
h1_text = 'Preface' if h1_text.empty?

contents_html += "<p><a href='#{fname}##{h1_name}'>#{h1_text}</a></p>"
contents_html += "<p>"

doc.css('h2').each do |h2_elem|
h2_name = h2_elem.css('a').attr('name').value
h2_text = h2_elem.css('a').inner_html.strip.gsub(/\r?\n/, ' ').gsub(/\s+/, ' ')
if not started
contents_html += " <li>\n"
contents_html += " <ul>\n"
started = true
end
contents_html += " <li><a href='#{fname}##{h2_name}'>#{h2_text}</a></li>\n"
end

if started
contents_html += " </ul>\n"
contents_html += " </li>\n"
h2_text = h2_elem.text.strip.gsub(/\r?\n/, ' ').gsub(/\s+/, ' ').capitalize
contents_html += " &nbsp;&nbsp;&nbsp;<a href='#{fname}##{h2_name}'>#{h2_text}</a><br />\n"
end
contents_html += "</p>\n"
end

contents_html += "</ul>\n"

File.open('build/toc.html', 'w') do |fh|
html_template = ''
File.open('assets/toc-template.html'){|fh| html_template = fh.read}
Expand Down
Binary file modified thinking-in-cpp-vol1.mobi
Binary file not shown.

0 comments on commit 92769ef

Please sign in to comment.