refactor extract_section_content to improve section handling logic
This commit is contained in:
+7
-7
@@ -284,18 +284,18 @@ def extract_section_content(content: str, section_type: str) -> str:
|
|||||||
return ""
|
return ""
|
||||||
|
|
||||||
for line in lines:
|
for line in lines:
|
||||||
if pattern.match(line):
|
|
||||||
in_section = True
|
|
||||||
section_level = len(line) - len(line.lstrip('#'))
|
|
||||||
continue
|
|
||||||
|
|
||||||
if in_section:
|
if in_section:
|
||||||
if line.startswith('#'):
|
if line.startswith('#'):
|
||||||
current_level = len(line) - len(line.lstrip('#'))
|
current_level = len(line) - len(line.lstrip('#'))
|
||||||
if current_level <= section_level:
|
if current_level <= section_level:
|
||||||
in_section = False
|
in_section = False
|
||||||
continue
|
else:
|
||||||
section_content.append(line)
|
section_content.append(line)
|
||||||
|
else:
|
||||||
|
section_content.append(line)
|
||||||
|
elif pattern.match(line):
|
||||||
|
in_section = True
|
||||||
|
section_level = len(line) - len(line.lstrip('#'))
|
||||||
|
|
||||||
return '\n'.join(section_content)
|
return '\n'.join(section_content)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user