mirror of
https://github.com/VectifyAI/PageIndex.git
synced 2026-07-21 21:31:08 +02:00
fix(markdown): skip empty bold headings
This commit is contained in:
parent
6fd237986e
commit
01dbcbf47f
2 changed files with 26 additions and 2 deletions
|
|
@ -62,7 +62,8 @@ def extract_nodes_from_markdown(markdown_content):
|
|||
bold_match = re.match(bold_heading_pattern, stripped_line)
|
||||
if bold_match:
|
||||
title = bold_match.group(1).strip()
|
||||
node_list.append({'node_title': title, 'line_num': line_num, 'level': 1})
|
||||
if title:
|
||||
node_list.append({'node_title': title, 'line_num': line_num, 'level': 1})
|
||||
|
||||
return node_list, lines
|
||||
|
||||
|
|
@ -340,4 +341,4 @@ if __name__ == "__main__":
|
|||
with open(output_path, 'w', encoding='utf-8') as f:
|
||||
json.dump(tree_structure, f, indent=2, ensure_ascii=False)
|
||||
|
||||
print(f"\nTree structure saved to: {output_path}")
|
||||
print(f"\nTree structure saved to: {output_path}")
|
||||
|
|
|
|||
23
tests/test_page_index_md.py
Normal file
23
tests/test_page_index_md.py
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
import unittest
|
||||
|
||||
from pageindex.page_index_md import extract_nodes_from_markdown
|
||||
|
||||
|
||||
class ExtractNodesFromMarkdownTest(unittest.TestCase):
|
||||
def test_skips_bold_heading_with_only_whitespace(self):
|
||||
nodes, _ = extract_nodes_from_markdown("** **\n**Valid heading**")
|
||||
|
||||
self.assertEqual(
|
||||
nodes,
|
||||
[
|
||||
{
|
||||
"node_title": "Valid heading",
|
||||
"line_num": 2,
|
||||
"level": 1,
|
||||
}
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Loading…
Add table
Add a link
Reference in a new issue