Skip to content

Commit

Permalink
resolves #217 add support for Unicode characters in chapter IDs
Browse files Browse the repository at this point in the history
  • Loading branch information
slonopotamus committed Jan 22, 2020
1 parent 6baf437 commit 840bb26
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ For a detailed view of what has changed, refer to the {uri-repo}/commits/master[
== Unreleased

* drop unused dependencies: thread_safe, concurrent-ruby (#234)
* add support for Unicode characters in chapter IDs (#217)
* fix sample-book to be a valid book (#196)
* fix the (in)famous `undefined method `to_ios'` when given a document that doesn't follow asciidoctor-epub3 rules (#7)

Expand Down
11 changes: 10 additions & 1 deletion lib/asciidoctor-epub3/packager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,16 @@ def package options = {}
::FileUtils.mkdir_p dest unless ::File.directory? dest

epub_file = fmt == :kf8 ? %(#{::Asciidoctor::Helpers.rootname target}-kf8.epub) : target
builder.generate_epub epub_file

prev_zip_unicode = ::Zip.unicode_names
begin
# Let's hope there are no parallel threads running while we're messing with global variable
::Zip.unicode_names = true
builder.generate_epub epub_file
ensure
::Zip.unicode_names = prev_zip_unicode
end

puts %(Wrote #{fmt.upcase} to #{epub_file}) if $VERBOSE
if options[:extract]
extract_dir = epub_file.sub EpubExtensionRx, ''
Expand Down
19 changes: 19 additions & 0 deletions spec/converter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,24 @@
attributes: { 'ebook-format' => 'mobi' }
expect(File).to exist(outfile)
end

it 'converts chapter with unicode title to unicode filename' do
infile = fixture_file 'unicode/spine.adoc'
outfile = temp_file 'unicode.epub'
Asciidoctor.convert_file infile,
to_file: outfile,
backend: 'epub3',
header_footer: true,
mkdirs: true
prev_zip_encoding = Zip.force_entry_names_encoding
begin
Zip.force_entry_names_encoding = 'UTF-8'
Zip::File.open outfile do |zip|
expect(zip.find_entry('OEBPS/test-é.xhtml')).not_to be_nil
end
ensure
Zip.force_entry_names_encoding = prev_zip_encoding
end
end
end
end
1 change: 1 addition & 0 deletions spec/fixtures/unicode/reference.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
= Test é
6 changes: 6 additions & 0 deletions spec/fixtures/unicode/spine.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
= Unicode book
:doctype: book
:idprefix:
:idseparator: -

include::reference.adoc[]

0 comments on commit 840bb26

Please sign in to comment.