From 26ba75f76cc1db12439fb6f3a7c6bc9fbd049507 Mon Sep 17 00:00:00 2001 From: ldolse Date: Wed, 17 Nov 2010 10:25:51 +0800 Subject: [PATCH] added a search for emphasized lines during chapter markup --- src/calibre/ebooks/conversion/utils.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/calibre/ebooks/conversion/utils.py b/src/calibre/ebooks/conversion/utils.py index 51139d3a18..bec15924d6 100644 --- a/src/calibre/ebooks/conversion/utils.py +++ b/src/calibre/ebooks/conversion/utils.py @@ -177,9 +177,10 @@ class PreProcessor(object): numeric_chapters = r".?(\d+\.?|(CHAPTER\s*([\dA-Z\-\'\"\?\.!#,]+\s*){1,10}))\s*" uppercase_chapters = r"\s*.?([A-Z#]+(\s|-){0,3}){1,5}\s*" numeric_titles = r".?(\d+\.?\s+([\d\w-]+\:?\'?-?\s?){0,5})\s*" + emphasized_lines = r"]*>\s*(]*>)?\s*(\s*(?=[\w#\-*\s]+<)([\w#-*]+\s*){1,5}\s*)()?\s*" full_chapter_line = chapter_line_open+chapter_header_open+typical_chapters+chapter_header_close+chapter_line_close - n_lookahead = re.sub("(out|inn|cha)", "l", full_chapter_line) + n_lookahead = re.sub("(ou|in|cha)", "lookahead_", full_chapter_line) print "n_lookahead is " + n_lookahead print "Chapter line is " + full_chapter_line + "\n\n" chapter_marker = lookahead+full_chapter_line+blank_lines+n_lookahead_open+n_lookahead+n_lookahead_close+opt_title_open+title_line_open+title_header_open+default_title+title_header_close+title_line_close+opt_title_close @@ -195,7 +196,7 @@ class PreProcessor(object): if self.html_preprocess_sections < 10: self.log("not enough chapters, only " + unicode(self.html_preprocess_sections) + ", trying numeric chapters") full_chapter_line = chapter_line_open+chapter_header_open+numeric_chapters+chapter_header_close+chapter_line_close - n_lookahead = re.sub("(out|inn|cha)", "l", full_chapter_line) + n_lookahead = re.sub("(ou|in|cha)", "lookahead_", full_chapter_line) print "n_lookahead is " + n_lookahead print "Chapter line is " + full_chapter_line + "\n\n" chapter_marker = lookahead+full_chapter_line+blank_lines+n_lookahead_open+n_lookahead+n_lookahead_close+opt_title_open+title_line_open+title_header_open+default_title+title_header_close+title_line_close+opt_title_close @@ -203,10 +204,21 @@ class PreProcessor(object): chapdetect2 = re.compile(r'%s' % chapter_marker, re.IGNORECASE) html = chapdetect2.sub(self.chapter_head, html) + if self.html_preprocess_sections < 10: + self.log("not enough chapters, only " + unicode(self.html_preprocess_sections) + ", trying emphazised lines") + full_chapter_line = chapter_line_open+chapter_header_open+emphasized_lines+chapter_header_close+chapter_line_close + n_lookahead = re.sub("(ou|in|cha)", "lookahead_", full_chapter_line) + print "n_lookahead is " + n_lookahead + print "Chapter line is " + full_chapter_line + "\n\n" + chapter_marker = lookahead+full_chapter_line+blank_lines+n_lookahead_open+n_lookahead+n_lookahead_close+opt_title_open+title_line_open+title_header_open+default_title+title_header_close+title_line_close+opt_title_close + print chapter_marker + chapdetect2 = re.compile(r'%s' % chapter_marker, re.IGNORECASE) + html = chapdetect2.sub(self.chapter_head, html) + if self.html_preprocess_sections < 10: self.log("not enough chapters, only " + unicode(self.html_preprocess_sections) + ", trying with uppercase words") full_chapter_line = chapter_line_open+chapter_header_open+uppercase_chapters+chapter_header_close+chapter_line_close - n_lookahead = re.sub("(out|inn|cha)", "l", full_chapter_line) + n_lookahead = re.sub("(ou|in|cha)", "lookahead_", full_chapter_line) print "n_lookahead is " + n_lookahead print "Chapter line is " + full_chapter_line + "\n\n" chapter_marker = lookahead+full_chapter_line+blank_lines+n_lookahead_open+n_lookahead+n_lookahead_close+opt_title_open+title_line_open+title_header_open+default_title+title_header_close+title_line_close+opt_title_close @@ -217,7 +229,7 @@ class PreProcessor(object): if self.html_preprocess_sections < 10: self.log("not enough chapters, only " + unicode(self.html_preprocess_sections) + ", trying numeric chapters with titles") full_chapter_line = chapter_line_open+chapter_header_open+numeric_titles+chapter_header_close+chapter_line_close - n_lookahead = re.sub("(out|inn|cha)", "l", full_chapter_line) + n_lookahead = re.sub("(ou|in|cha)", "lookahead_", full_chapter_line) print "n_lookahead is " + n_lookahead print "Chapter line is " + full_chapter_line + "\n\n" chapter_marker = lookahead+full_chapter_line+blank_lines+n_lookahead_open+n_lookahead+n_lookahead_close+opt_title_open+title_line_open+title_header_open+default_title+title_header_close+title_line_close+opt_title_close