pandoc 1.9.1.1 不支援subchapter,需要subchapter則需要修改toc.ncx檔案
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import os | |
import sys | |
Help = """ A simple converter for gjots. convert '.gjots' file to '.epub' format. | |
Note: | |
All notes will be located in 'root' node, no folder supported! | |
Pandoc don't support subchapter in toc.ncx. | |
If you want subchapter make your own toc.ncx! | |
Usage: gjots2epub.py [input_file] | |
The ouput filename will be '[input_file].epub' | |
""" | |
try: | |
output = '' | |
input_file = os.path.basename(sys.argv[1]) | |
output_file = '{0}.epub'.format(input_file) | |
tmp_file = '{0}.tmp'.format(input_file) | |
with file(sys.argv[1]) as f: | |
for line in f.readlines(): | |
if '\\NewEntry' in line: | |
line = '\n\n# ' | |
elif '\\NewFolder' in line: | |
line = '\n\n# ' | |
elif '\\EndFolder' in line: | |
line = '\n' | |
output += line | |
with file(tmp_file, 'w') as f: | |
f.write(output) | |
os.system("pandoc '{0}' -o '{1}'".format(tmp_file, output_file)) | |
os.remove(tmp_file) | |
except IndexError: | |
print Help | |
sys.exit(1) | |
except IOError: | |
print 'No such file exists: {0}'.format(sys.argv[1]) | |
sys.exit(1) |
沒有留言:
張貼留言