Skip to content

Instantly share code, notes, and snippets.

@JenniferMack
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JenniferMack/3169e131d5cd8c6f40db to your computer and use it in GitHub Desktop.
Save JenniferMack/3169e131d5cd8c6f40db to your computer and use it in GitHub Desktop.
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
Copy link
Author

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