def find_numeration_in_body(docbody): marker_patterns = get_reference_line_numeration_marker_patterns() ref_details = None found_title = False for line in docbody: # Move past blank lines if line.isspace(): continue # Is this line numerated like a reference line? mark_match = regex_match_list(line, marker_patterns) if mark_match: mark = mark_match.group('mark') mk_ptn = mark_match.re.pattern ref_details = { 'marker': mark, 'marker_pattern': mk_ptn, 'title_marker_same_line': False, } # Check if it's the first reference # Something like [1] or (1), etc. m_num = re_num.search(mark) if m_num and m_num.group(0) == '1': # 1st ref truly found break else: # No numeration ref_details = { 'title_marker_same_line': False, 'marker': None, 'marker_pattern': None, } return ref_details, found_title
def find_numeration_in_body(docbody): marker_patterns = get_reference_line_numeration_marker_patterns() ref_details = None found_title = False for line in docbody: # Move past blank lines if line.isspace(): continue # Is this line numerated like a reference line? mark_match = regex_match_list(line, marker_patterns) if mark_match: mark = mark_match.group("mark") mk_ptn = mark_match.re.pattern ref_details = {"marker": mark, "marker_pattern": mk_ptn, "title_marker_same_line": False} # Check if it's the first reference # Something like [1] or (1), etc. m_num = re_num.search(mark) if m_num and m_num.group(0) == "1": # 1st ref truly found break else: # No numeration ref_details = {"title_marker_same_line": False, "marker": None, "marker_pattern": None} return ref_details, found_title
def find_numeration_in_title(docbody, title): ref_details = None found_title = False try: first_line = docbody[0] except IndexError: return ref_details, found_title # Need to escape to avoid problems like 'References[' title = re.escape(title) mk_with_title_ptns = get_reference_line_numeration_marker_patterns(title) mk_with_title_match = regex_match_list(first_line, mk_with_title_ptns) if mk_with_title_match: mk = mk_with_title_match.group("mark") mk_ptn = mk_with_title_match.re.pattern m_num = re_num.search(mk) if m_num and m_num.group(0) == "1": # Mark found found_title = True ref_details = {"marker": mk, "marker_pattern": mk_ptn, "title_marker_same_line": True} else: ref_details = {"marker": mk, "marker_pattern": mk_ptn, "title_marker_same_line": True} return ref_details, found_title
def find_numeration_in_title(docbody, title): ref_details = None found_title = False try: first_line = docbody[0] except IndexError: return ref_details, found_title # Need to escape to avoid problems like 'References[' title = re.escape(title) mk_with_title_ptns = \ get_reference_line_numeration_marker_patterns(title) mk_with_title_match = \ regex_match_list(first_line, mk_with_title_ptns) if mk_with_title_match: mk = mk_with_title_match.group('mark') mk_ptn = mk_with_title_match.re.pattern m_num = re_num.search(mk) if m_num and m_num.group(0) == '1': # Mark found found_title = True ref_details = { 'marker': mk, 'marker_pattern': mk_ptn, 'title_marker_same_line': True } else: ref_details = { 'marker': mk, 'marker_pattern': mk_ptn, 'title_marker_same_line': True } return ref_details, found_title
def format_marker(line_marker): if line_marker: num_match = re_num.search(line_marker) if num_match: line_marker = num_match.group(0) return line_marker