Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
- Remove inline alignment from tables.
- Render `<figure>` for images with title.
- Render abbreviations with (e.g. `*[CSS]: Cascading Style Sheets`).
- Ensure correct numerical sorting of TOC when there are more than 10 chapters

## v3.1.0

Expand Down
7 changes: 4 additions & 3 deletions lib/kitabu/exporter/epub.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ class Epub < Base

def sections
@sections ||=
html.css(SECTION_SELECTOR).each_with_index.map do |chapter, index|
html.css(SECTION_SELECTOR).each.with_index(1).map do |chapter, index|
html = Nokogiri::HTML5.fragment(chapter.inner_html)
section_number = index.to_s.rjust(2, '0')

OpenStruct.new(
index:,
filename: "section_#{index}.html",
filepath: tmp_dir.join("section_#{index}.html").to_s,
filename: "section_#{section_number}.html",
filepath: tmp_dir.join("section_#{section_number}.html").to_s,
html:
)
end
Expand Down
13 changes: 12 additions & 1 deletion spec/kitabu/exporter/epub_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,21 @@
describe Kitabu::Exporter::Epub do
let(:root) { SPECDIR.join("support/mybook") }

it "generates e-pub" do
before do
Kitabu::Exporter::HTML.export(root)
Kitabu::Exporter::Epub.export(root)
end

it "generates e-pub" do
expect(root.join("output/mybook.epub")).to be_file
end

it "adds leading zero to 1 digit number" do
sections = root.join("output/epub").glob("section*.{xhtml,html}")
sections = sections.map do |path|
path.to_s.split("/").last
end
expected = 1.upto(12).map {|i| "section_#{i.to_s.rjust(2, '0')}.html" }
expect(sections).to eq(expected)
end
end
3 changes: 3 additions & 0 deletions spec/support/mybook/text/05_Chapter 5.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## Chapter 5

This is Chapter 5
3 changes: 3 additions & 0 deletions spec/support/mybook/text/06_Chapter 6.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## Chapter 6

This is Chapter 6
3 changes: 3 additions & 0 deletions spec/support/mybook/text/07_Chapter 7.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## Chapter 7

This is Chapter 7
3 changes: 3 additions & 0 deletions spec/support/mybook/text/08_Chapter 8.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## Chapter 8

This is Chapter 8
3 changes: 3 additions & 0 deletions spec/support/mybook/text/09_Chapter 9.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## Chapter 9

This is Chapter 9
3 changes: 3 additions & 0 deletions spec/support/mybook/text/10_Chapter 10.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## Chapter 10

This is Chapter 10
3 changes: 3 additions & 0 deletions spec/support/mybook/text/11_Chapter 11.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## Chapter 11

This is Chapter 11
Loading