######################################################################### # # # # # 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. # # # # You should have received a copy of the GNU General Public License # # along with this program; if not, write to the Free Software # # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA # # 02111-1307 USA # # # # # ######################################################################### import sys, os, tempfile from libprs500.ebooks.rtf2xml import copy class Paragraphs: """ ================= Purpose ================= Write paragraph tags for a tokenized file. (This module won't be any use to use to you unless you use it as part of the other modules.) ------------- Method ------------- RTF does not tell you when a paragraph begins. It only tells you when the paragraph ends. In order to make paragraphs out of this limited info, the parser starts in the body of the documents and assumes it is not in a paragraph. It looks for clues to begin a paragraph. Text starts a paragraph; so does an inline field or list-text. If an end of paragraph marker (\par) is found, then this indicates a blank paragraph. Once a paragraph is found, the state changes to 'paragraph.' In this state, clues are looked to for the end of a paragraph. The end of a paragraph marker (\par) marks the end of a paragraph. So does the end of a footnote or heading; a paragraph definintion; the end of a field-block; and the beginning of a section. (How about the end of a section or the end of a field-block?) """ def __init__(self, in_file, bug_handler, copy = None, write_empty_para = 1, run_level = 1, ): """ Required: 'file'--file to parse 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.__write_empty_para = write_empty_para self.__run_level = run_level self.__write_to = tempfile.mktemp() def __initiate_values(self): """ Initiate all values. """ self.__state = 'before_body' self.__start_marker = 'mi