######################################################################### # # # # # copyright 2002 Paul Henry Tremblay # # # # This program is distributed in the hope that it will be useful, # # but WITHOUT ANY WARRANTY; without even the implied warranty of # # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # # General Public License for more details. # # # # # ######################################################################### import sys, os, re from ebook_converter.ebooks.rtf2xml import copy from ebook_converter.ptempfile import better_mktemp from . import open_for_read, open_for_write class GroupStyles: """ Form lists. Use RTF's own formatting to determine if a paragraph definition is part of a list. Use indents to determine items and how lists are nested. """ def __init__(self, in_file, bug_handler, copy=None, run_level=1, wrap=0, ): """ Required: 'file' Optional: 'copy'-- whether to make a copy of result for debugging 'temp_dir' --where to output temporary results (default is directory from which the script is run.) Returns: nothing """ self.__file = in_file self.__bug_handler = bug_handler self.__copy = copy self.__run_level = run_level self.__write_to = better_mktemp() self.__wrap = wrap def __initiate_values(self): """ Required: Nothing Return: Nothing Logic: The self.__end_list is a list of tokens that will force a list to end. Likewise, the self.__end_lines is a list of lines that forces a list to end. """ self.__state = "default" self.__left_indent = 0 self.__list_type = 'not-defined' self.__pard_def = "" self.__all_lists = [] self.__list_chunk = '' self.__state_dict={ 'default' : self.__default_func, 'in_pard' : self.__in_pard_func, 'after_pard' : self.__after_pard_func, } # section end self.__end_list = [ # section end 'mi') self.__found_appt = 0 self.__line_num = 0 def __in_pard_func(self, line): """ Required: line -- the line of current text. Return: Nothing Logic: You are in a list, but in the middle of a paragraph definition. Don't do anything until you find the end of the paragraph definition. """ if self.__token_info == 'mi 2: msg = 'wrong flag' raise self.__bug_handler(msg) elif self.__token_info in self.__end_list: self.__write_obj.write('mi%s\n' % name) self.__write_obj.write('mi