import json import re def compare_headings(current, new): current_nums = [int(num) for num in current.split('.') if num.isdigit()] new_nums = [int(num) for num in new.split('.') if num.isdigit()] for c, n in zip(current_nums, new_nums): if n > c: return True elif n < c: return False return len(new_nums) > len(current_nums) def should_add_newline(content, keywords, max_length=20): content_str = ''.join(content).strip() return any(keyword in content_str for keyword in keywords) or len(content_str) <= max_length def handle_content_append(current_content, line_content, append_newline, keywords): if append_newline: if should_add_newline(current_content, keywords): current_content.append('\n') append_newline = False current_content.append(line_content) return append_newline # def parse_text_by_heading(text): # keywords = ['包含', '以下'] # data = {} # current_key = None # current_content = [] # append_newline = False # skip_subheadings = False # # lines = text.split('\n') # for i, line in enumerate(lines): # line_stripped = line.strip().replace('.', '.') # # print(line_stripped) # # 匹配二级、三级标题形如 '1.1'、'2.2.3' 并确保其前后没有字母或括号 # match = re.match(r'^(?