Package Exports
- @lexbuild/core
Readme
@lexbuild/core
This package is part of the LexBuild monorepo, a tool that converts U.S. legislative XML into structured Markdown optimized for AI, RAG pipelines, and semantic search. See the monorepo for full documentation, architecture details, and contribution guidelines.
It provides the foundational building blocks for XML parsing infrastructure, AST definitions, and Markdown rendering for use by @lexbuild/usc and @lexbuild/cli.
Install
npm install @lexbuild/coreWhat's Included
XML Parser
Streaming SAX parser with namespace normalization for USLM documents.
import { XMLParser } from "@lexbuild/core";
const parser = new XMLParser();
parser.on("openElement", (name, attrs) => { /* ... */ });
parser.on("closeElement", (name) => { /* ... */ });
parser.on("text", (text) => { /* ... */ });
await parser.parseStream(readableStream);AST Builder
Stack-based XML-to-AST construction with a section-emit pattern for bounded memory usage.
import { ASTBuilder } from "@lexbuild/core";
const builder = new ASTBuilder({
emitAt: "section",
onEmit: (node, context) => {
// Called with each completed section subtree
},
});Markdown Renderer
Stateless AST-to-Markdown conversion with YAML frontmatter, cross-reference link resolution, and notes filtering.
import { renderDocument, generateFrontmatter, createLinkResolver } from "@lexbuild/core";
const markdown = renderDocument(sectionNode, frontmatterData, {
linkStyle: "relative",
resolveLink: resolver.resolve,
});AST Node Types
Full type definitions for the legislative document AST: LevelNode, ContentNode, InlineNode, NoteNode, TableNode, and more.
import type { ASTNode, LevelNode, FrontmatterData, RenderOptions } from "@lexbuild/core";Namespace Constants
USLM, XHTML, Dublin Core namespace URIs and element classification sets.
import { USLM_NS, XHTML_NS, LEVEL_ELEMENTS, CONTENT_ELEMENTS } from "@lexbuild/core";API Reference
| Export | Description |
|---|---|
XMLParser |
Streaming SAX parser with namespace normalization |
ASTBuilder |
XML events to AST with section-emit pattern |
renderDocument() |
Render a section node with frontmatter to Markdown |
renderSection() |
Render a section-level node to Markdown |
renderNode() |
Render any AST node to Markdown |
generateFrontmatter() |
Generate YAML frontmatter block |
createLinkResolver() |
Create a cross-reference link resolver |
parseIdentifier() |
Parse a USLM identifier into components |
FORMAT_VERSION |
Output format version ("1.0.0") |
GENERATOR |
Generator string for frontmatter |