Skip to content

Instantly share code, notes, and snippets.

@JenniferMack JenniferMack/fix-epub.rb
Last active Aug 29, 2015

Embed
What would you like to do?
ePub playOrder fix for Ulysses export
#!/usr/bin/env ruby
cnt = 1
cmd = ARGV[0]
file = ARGV[1]
begin
if cmd == "unzip"
system "unzip", "-q", file
ARGV.replace ["OPS/toc.ncx"]
elsif cmd == "zip"
system "zip", "-f", file
exit
end
ARGF.each_line do |line|
if /playOrder/.match(line)
line.sub!(/playOrder="1"/, "playOrder=\"#{cnt}\"")
cnt += 1
end
puts line
end
rescue
puts "Oops. Something went wrong."
end
@JenniferMack

This comment has been minimized.

Copy link
Owner Author

JenniferMack commented Feb 26, 2015

Updated to search for full 'playOrder="1"' string instead of each digit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.