@lexbuild/core 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +102 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
# @lexbuild/core
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@lexbuild/core)
|
|
4
|
+
[](https://github.com/chris-c-thomas/lexbuild/blob/main/LICENSE)
|
|
5
|
+
|
|
6
|
+
This package is part of the [LexBuild](https://github.com/chris-c-thomas/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.
|
|
7
|
+
|
|
8
|
+
It provides the foundational building blocks for XML parsing infrastructure, AST definitions, and Markdown rendering for use by [`@lexbuild/usc`](https://www.npmjs.com/package/@lexbuild/usc) and [`@lexbuild/cli`](https://www.npmjs.com/package/@lexbuild/cli).
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm install @lexbuild/core
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## What's Included
|
|
17
|
+
|
|
18
|
+
### XML Parser
|
|
19
|
+
|
|
20
|
+
Streaming SAX parser with namespace normalization for USLM documents.
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
import { XMLParser } from "@lexbuild/core";
|
|
24
|
+
|
|
25
|
+
const parser = new XMLParser();
|
|
26
|
+
parser.on("openElement", (name, attrs) => { /* ... */ });
|
|
27
|
+
parser.on("closeElement", (name) => { /* ... */ });
|
|
28
|
+
parser.on("text", (text) => { /* ... */ });
|
|
29
|
+
|
|
30
|
+
await parser.parseStream(readableStream);
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### AST Builder
|
|
34
|
+
|
|
35
|
+
Stack-based XML-to-AST construction with a section-emit pattern for bounded memory usage.
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
import { ASTBuilder } from "@lexbuild/core";
|
|
39
|
+
|
|
40
|
+
const builder = new ASTBuilder({
|
|
41
|
+
emitAt: "section",
|
|
42
|
+
onEmit: (node, context) => {
|
|
43
|
+
// Called with each completed section subtree
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Markdown Renderer
|
|
49
|
+
|
|
50
|
+
Stateless AST-to-Markdown conversion with YAML frontmatter, cross-reference link resolution, and notes filtering.
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
import { renderDocument, generateFrontmatter, createLinkResolver } from "@lexbuild/core";
|
|
54
|
+
|
|
55
|
+
const markdown = renderDocument(sectionNode, frontmatterData, {
|
|
56
|
+
linkStyle: "relative",
|
|
57
|
+
resolveLink: resolver.resolve,
|
|
58
|
+
});
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### AST Node Types
|
|
62
|
+
|
|
63
|
+
Full type definitions for the legislative document AST: `LevelNode`, `ContentNode`, `InlineNode`, `NoteNode`, `TableNode`, and more.
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
import type { ASTNode, LevelNode, FrontmatterData, RenderOptions } from "@lexbuild/core";
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Namespace Constants
|
|
70
|
+
|
|
71
|
+
USLM, XHTML, Dublin Core namespace URIs and element classification sets.
|
|
72
|
+
|
|
73
|
+
```ts
|
|
74
|
+
import { USLM_NS, XHTML_NS, LEVEL_ELEMENTS, CONTENT_ELEMENTS } from "@lexbuild/core";
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## API Reference
|
|
78
|
+
|
|
79
|
+
| Export | Description |
|
|
80
|
+
|--------|-------------|
|
|
81
|
+
| `XMLParser` | Streaming SAX parser with namespace normalization |
|
|
82
|
+
| `ASTBuilder` | XML events to AST with section-emit pattern |
|
|
83
|
+
| `renderDocument()` | Render a section node with frontmatter to Markdown |
|
|
84
|
+
| `renderSection()` | Render a section-level node to Markdown |
|
|
85
|
+
| `renderNode()` | Render any AST node to Markdown |
|
|
86
|
+
| `generateFrontmatter()` | Generate YAML frontmatter block |
|
|
87
|
+
| `createLinkResolver()` | Create a cross-reference link resolver |
|
|
88
|
+
| `parseIdentifier()` | Parse a USLM identifier into components |
|
|
89
|
+
| `FORMAT_VERSION` | Output format version (`"1.0.0"`) |
|
|
90
|
+
| `GENERATOR` | Generator string for frontmatter |
|
|
91
|
+
|
|
92
|
+
## Documentation
|
|
93
|
+
|
|
94
|
+
- [Monorepo README](https://github.com/chris-c-thomas/lexbuild#readme)
|
|
95
|
+
- [Architecture](https://github.com/chris-c-thomas/lexbuild/blob/main/docs/architecture.md)
|
|
96
|
+
- [Output Format](https://github.com/chris-c-thomas/lexbuild/blob/main/docs/output-format.md)
|
|
97
|
+
- [XML Element Reference](https://github.com/chris-c-thomas/lexbuild/blob/main/docs/xml-element-reference.md)
|
|
98
|
+
- [Extending](https://github.com/chris-c-thomas/lexbuild/blob/main/docs/extending.md)
|
|
99
|
+
|
|
100
|
+
## License
|
|
101
|
+
|
|
102
|
+
[MIT](https://github.com/chris-c-thomas/lexbuild/blob/main/LICENSE)
|
package/package.json
CHANGED