Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions project_processor/gh_processor/file_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,18 +133,20 @@ def extract_headings_with_paragraphs_from_markdown(file_path: str) -> dict:

with open(file_path, "r") as file:
content = file.read()
heading_pattern = r"#+\s(.+)"
heading_pattern = re.compile(r"^#+\s+(.+)$", re.MULTILINE)
matches = re.findall(heading_pattern, content)

for match in matches:
heading = match
next_line_index = content.index(match) + len(match) + 1
next_line = content[next_line_index:].strip()

if next_line.startswith("#"):
paragraph = ""
paragraph_start_index = content.index(match) + len(match) + 1
rest_content = content[paragraph_start_index:].strip()
next_heading = re.search(heading_pattern, rest_content)
if next_heading is None:
paragraph_end_index = len(content)
else:
paragraph = next_line
paragraph_end_index = next_heading.start()

paragraph = content[paragraph_start_index:paragraph_start_index + paragraph_end_index - 1].strip()

heading_paragraphs[heading] = paragraph

Expand Down