feat: markdown dialect option, faster search (0.1.1)

- split_markdown/load_markdown: dialect="commonmark"|"python-markdown" so list
  blocks match the HTML structure of the renderer (list after paragraph needs a
  blank line; nesting needs 4 spaces in Python-Markdown)
- SearchEngine caches the searched text per block on load
- regex timeout only for /regex/ terms (words and phrases are linear);
  typical queries over 26k blocks: ~30-140 ms instead of 250-700 ms

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
dschlueter 2026-10-12 19:37:40 +02:00
commit d9f81ac918

View file

@ -63,6 +63,29 @@ def test_split_list():
assert "not a heading" in blocks[6].text
def test_dialect_list_interrupting_paragraph():
doc = "**1. Trend**\n* stories: a\n* why: b\n\n- real item\n"
common = split_markdown(doc, split="list")
assert [b.meta["kind"] for b in common] == ["paragraph", "item", "item", "item"]
pymd = split_markdown(doc, split="list", dialect="python-markdown")
assert [b.meta["kind"] for b in pymd] == ["paragraph", "item"]
assert "stories: a" in pymd[0].text
def test_dialect_nesting_indent():
doc = "1. **Trend A**\n - why: x\n - how: y\n\n2. **Trend B**\n - nested: z\n"
common = split_markdown(doc, split="list")
assert [b.line for b in common] == [1, 5]
pymd = split_markdown(doc, split="list", dialect="python-markdown")
assert [b.line for b in pymd] == [1, 2, 3, 5] # 3 spaces: no nesting in Python-Markdown
assert "nested: z" in pymd[-1].text
def test_invalid_dialect():
with pytest.raises(ValueError):
split_markdown("x", split="list", dialect="gfm")
def test_split_heading():
blocks = split_markdown(DOC, split="heading")
assert [(b.title, b.anchor) for b in blocks] == [