Remove empty tags in info

This commit is contained in:
Sengian 2011-01-15 21:51:37 +01:00
parent 77ce7b9c76
commit 8cf62f9feb

View File

@ -15,7 +15,7 @@
# # # #
# # # #
######################################################################### #########################################################################
import sys, os, tempfile import sys, os, tempfile, re
from calibre.ebooks.rtf2xml import copy from calibre.ebooks.rtf2xml import copy
@ -51,6 +51,7 @@ class Info:
""" """
self.__text_string = '' self.__text_string = ''
self.__state = 'before_info_table' self.__state = 'before_info_table'
self.rmspace = re.compile(r'\s+')
self.__state_dict = { self.__state_dict = {
'before_info_table': self.__before_info_table_func, 'before_info_table': self.__before_info_table_func,
'after_info_table': self.__after_info_table_func, 'after_info_table': self.__after_info_table_func,
@ -167,11 +168,13 @@ class Info:
""" """
if self.__token_info == 'mi<mk<docinf-end': if self.__token_info == 'mi<mk<docinf-end':
self.__state = 'in_info_table' self.__state = 'in_info_table'
self.__write_obj.write( #Don't print empty tags
'mi<tg<open______<%s\n' if len(self.rmspace.sub('',self.__text_string)):
'tx<nu<__________<%s\n' self.__write_obj.write(
'mi<tg<close_____<%s\n' % (self.__tag, self.__text_string, self.__tag) 'mi<tg<open______<%s\n'
) 'tx<nu<__________<%s\n'
'mi<tg<close_____<%s\n' % (self.__tag, self.__text_string, self.__tag)
)
self.__text_string = '' self.__text_string = ''
elif line[0:2] == 'tx': elif line[0:2] == 'tx':
self.__text_string += line[17:-1] self.__text_string += line[17:-1]