feat(chunks): rilevamento universale has_math/has_table + dollarmath plugin
- parser.py: integra dollarmath_plugin (graceful fallback) — blocchi $$…$$ → token math_block atomico
- segmenter.py: gestisce math_block → Block(kind=math, atomic=True, plain_text=[formula])
- packer.py: has_table rileva anche <table> in blocchi html; has_math rileva $$ e \begin{ nel contenuto
- +11 test (parser×3, segmenter×3, packer×5) — totale 65 test
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -116,3 +116,35 @@ def test_assets_empty(cfg):
|
||||
blocks = [make_block(1, "Testo.")]
|
||||
chunks = pack(blocks, cfg, "test")
|
||||
assert chunks[0].assets == []
|
||||
|
||||
|
||||
def test_flags_has_math_via_kind(cfg):
|
||||
blocks = [make_block(1, "$$\nE=mc^2\n$$", kind="math", atomic=True)]
|
||||
chunks = pack(blocks, cfg, "test")
|
||||
assert chunks[0].flags["has_math"] is True
|
||||
|
||||
|
||||
def test_flags_has_math_via_content_dollars(cfg):
|
||||
# Paragrafo con $$ inline (senza dollarmath plugin attivo)
|
||||
blocks = [make_block(1, "Vedi la formula:\n$$\nx^2\n$$")]
|
||||
chunks = pack(blocks, cfg, "test")
|
||||
assert chunks[0].flags["has_math"] is True
|
||||
|
||||
|
||||
def test_flags_has_math_via_content_begin(cfg):
|
||||
blocks = [make_block(1, r"Equazione: \begin{align} x = 1 \end{align}")]
|
||||
chunks = pack(blocks, cfg, "test")
|
||||
assert chunks[0].flags["has_math"] is True
|
||||
|
||||
|
||||
def test_flags_has_table_via_html(cfg):
|
||||
html_content = "<table><tr><td>A</td></tr></table>"
|
||||
blocks = [make_block(1, html_content, kind="html", atomic=True)]
|
||||
chunks = pack(blocks, cfg, "test")
|
||||
assert chunks[0].flags["has_table"] is True
|
||||
|
||||
|
||||
def test_flags_no_math_plain_text(cfg):
|
||||
blocks = [make_block(1, "Testo normale senza formule.")]
|
||||
chunks = pack(blocks, cfg, "test")
|
||||
assert chunks[0].flags["has_math"] is False
|
||||
|
||||
Reference in New Issue
Block a user