from llama_index.core import Document, VectorStoreIndex
from llama_index.core.embeddings import MockEmbedding
from llama_index.core.node_parser import HTMLNodeParser
html = """
Support portal runbook
Billing tickets route to the finance queue.
Escalation rule
Escalate refund requests over $500 to Maya.
Attach the customer invoice.
Record the approval code in the ticket.
"""
document = Document(text=html, metadata={"source": "support-portal.html"})
parser = HTMLNodeParser(tags=["h1", "h2", "p", "li"])
nodes = parser.get_nodes_from_documents([document])
print(f"parsed nodes: {len(nodes)}")
assert len(nodes) == 5
assert all("Skip navigation text" not in node.get_content() for node in nodes)
for number, node in enumerate(nodes, start=1):
tag = node.metadata.get("tag", "unknown")
text = node.get_content().replace("\n", " ")
print(f"{number}. tag={tag} text={text}")
index = VectorStoreIndex(nodes, embed_model=MockEmbedding(embed_dim=8))
assert len(index.index_struct.nodes_dict) == len(nodes)
print(f"indexed nodes: {len(index.index_struct.nodes_dict)}")