@origints/markdown 0.1.0 → 0.1.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.
Files changed (2) hide show
  1. package/README.md +214 -0
  2. package/package.json +14 -14
package/README.md ADDED
@@ -0,0 +1,214 @@
1
+ # @origints/markdown
2
+
3
+ > Markdown parsing and manipulation for Origins with full lineage tracking.
4
+
5
+ ---
6
+
7
+ ## Why
8
+
9
+ Parsing Markdown is easy. Knowing exactly where each heading, link, or code block came from in the source is harder. When you're extracting structured data from Markdown documents, you need that connection.
10
+
11
+ This package parses Markdown into a navigable tree while maintaining source positions for every node. Extract frontmatter, query by node type, and convert to HTML - all with full provenance.
12
+
13
+ ---
14
+
15
+ ## Features
16
+
17
+ - Parse Markdown with GFM (GitHub Flavored Markdown) support
18
+ - YAML frontmatter extraction
19
+ - Source position tracking for all nodes
20
+ - Type-safe navigation and extraction
21
+ - Convert to HTML
22
+ - Support for tables, task lists, and footnotes
23
+ - Integrates with Origins transform registry
24
+
25
+ ---
26
+
27
+ ## Quick Start
28
+
29
+ ```bash
30
+ npm install @origints/markdown @origints/core
31
+ ```
32
+
33
+ ```ts
34
+ import { parseMarkdown } from "@origints/markdown";
35
+
36
+ const md = `
37
+ # Hello World
38
+
39
+ This is a paragraph.
40
+ `;
41
+
42
+ const result = parseMarkdown(md);
43
+
44
+ if (result.ok) {
45
+ const heading = result.value.find("heading");
46
+ console.log(heading?.text());
47
+ }
48
+ ```
49
+
50
+ Expected output:
51
+
52
+ ```
53
+ Hello World
54
+ ```
55
+
56
+ ---
57
+
58
+ ## Installation
59
+
60
+ - Supported platforms:
61
+ - macOS / Linux / Windows
62
+ - Runtime requirements:
63
+ - Node.js >= 18
64
+ - Package managers:
65
+ - npm, pnpm, yarn
66
+ - Peer dependencies:
67
+ - @origints/core ^0.1.0
68
+
69
+ ```bash
70
+ npm install @origints/markdown @origints/core
71
+ # or
72
+ pnpm add @origints/markdown @origints/core
73
+ ```
74
+
75
+ ---
76
+
77
+ ## Usage
78
+
79
+ ### Basic parsing
80
+
81
+ ```ts
82
+ import { parseMarkdown } from "@origints/markdown";
83
+
84
+ const result = parseMarkdown(`
85
+ # Title
86
+
87
+ A paragraph with **bold** and *italic*.
88
+
89
+ - Item 1
90
+ - Item 2
91
+ `);
92
+
93
+ if (result.ok) {
94
+ const doc = result.value;
95
+
96
+ // Find all headings
97
+ const headings = doc.findAll("heading");
98
+
99
+ // Find all links
100
+ const links = doc.findAll("link");
101
+
102
+ // Get text content
103
+ const text = doc.text();
104
+ }
105
+ ```
106
+
107
+ ### Frontmatter extraction
108
+
109
+ ```ts
110
+ import { parseMarkdown, extractFrontmatter } from "@origints/markdown";
111
+
112
+ const result = parseMarkdown(`
113
+ ---
114
+ title: My Post
115
+ date: 2024-01-15
116
+ tags:
117
+ - typescript
118
+ - origins
119
+ ---
120
+
121
+ # Content here
122
+ `);
123
+
124
+ if (result.ok) {
125
+ const frontmatter = extractFrontmatter(result.value);
126
+ console.log(frontmatter?.title);
127
+ }
128
+ ```
129
+
130
+ ### Converting to HTML
131
+
132
+ ```ts
133
+ import { parseMarkdown, toHtml } from "@origints/markdown";
134
+
135
+ const result = parseMarkdown("# Hello\n\nWorld");
136
+
137
+ if (result.ok) {
138
+ const html = toHtml(result.value);
139
+ // <h1>Hello</h1>\n<p>World</p>
140
+ }
141
+ ```
142
+
143
+ ### Using with Origins plans
144
+
145
+ ```ts
146
+ import { Planner, loadFile, globalRegistry } from "@origints/core";
147
+ import { parseMarkdown, registerMarkdownTransforms } from "@origints/markdown";
148
+
149
+ registerMarkdownTransforms(globalRegistry);
150
+
151
+ const plan = Planner.in(loadFile("README.md"))
152
+ .mapIn(parseMarkdown())
153
+ .emit((out, $) => {
154
+ const title = $.find("heading")?.text() ?? "Untitled";
155
+ out.add("title", title);
156
+ })
157
+ .compile();
158
+ ```
159
+
160
+ ### Typed node extraction
161
+
162
+ ```ts
163
+ import { parseMarkdown } from "@origints/markdown";
164
+ import type { HeadingData, LinkData } from "@origints/markdown";
165
+
166
+ const result = parseMarkdown(content);
167
+
168
+ if (result.ok) {
169
+ // Get heading with typed data
170
+ const heading = result.value.find("heading");
171
+ const data: HeadingData | undefined = heading?.data();
172
+ console.log(data?.depth); // 1, 2, 3, etc.
173
+
174
+ // Get link with typed data
175
+ const link = result.value.find("link");
176
+ const linkData: LinkData | undefined = link?.data();
177
+ console.log(linkData?.url);
178
+ }
179
+ ```
180
+
181
+ ---
182
+
183
+ ## Project Status
184
+
185
+ - **Experimental** - APIs may change
186
+
187
+ ---
188
+
189
+ ## Non-Goals
190
+
191
+ - Not a Markdown renderer/serializer
192
+ - Not a Markdown editor
193
+ - Not a full MDX parser
194
+
195
+ ---
196
+
197
+ ## Documentation
198
+
199
+ - See `@origints/core` for Origins concepts
200
+ - See [remark](https://github.com/remarkjs/remark) for underlying parser
201
+
202
+ ---
203
+
204
+ ## Contributing
205
+
206
+ - Open an issue before large changes
207
+ - Keep PRs focused
208
+ - Tests required for new features
209
+
210
+ ---
211
+
212
+ ## License
213
+
214
+ MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@origints/markdown",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Markdown parsing and manipulation for Origins with full lineage tracking",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -13,6 +13,13 @@
13
13
  "require": "./dist/index.cjs"
14
14
  }
15
15
  },
16
+ "scripts": {
17
+ "build": "vite build",
18
+ "test": "vitest run",
19
+ "test:watch": "vitest",
20
+ "typecheck": "tsc -p tsconfig.json --noEmit",
21
+ "lint": "eslint src"
22
+ },
16
23
  "dependencies": {
17
24
  "unified": "^11.0.0",
18
25
  "remark-parse": "^11.0.0",
@@ -29,6 +36,8 @@
29
36
  "@origints/core": "^0.1.0"
30
37
  },
31
38
  "devDependencies": {
39
+ "@origints/core": "workspace:*",
40
+ "@origints/yaml": "workspace:*",
32
41
  "@types/mdast": "^4.0.0",
33
42
  "@types/node": "^25.0.0",
34
43
  "@vitest/coverage-v8": "^4.0.0",
@@ -36,9 +45,7 @@
36
45
  "typescript": "^5.9.0",
37
46
  "vite": "^7.0.0",
38
47
  "vite-plugin-dts": "^4.0.0",
39
- "vitest": "^4.0.0",
40
- "@origints/core": "0.1.0",
41
- "@origints/yaml": "0.1.0"
48
+ "vitest": "^4.0.0"
42
49
  },
43
50
  "files": [
44
51
  "dist"
@@ -48,15 +55,8 @@
48
55
  },
49
56
  "repository": {
50
57
  "type": "git",
51
- "url": "https://github.com/anthropics/origins.git",
58
+ "url": "https://github.com/fponticelli/origints.git",
52
59
  "directory": "packages/markdown"
53
60
  },
54
- "license": "MIT",
55
- "scripts": {
56
- "build": "vite build",
57
- "test": "vitest run",
58
- "test:watch": "vitest",
59
- "typecheck": "tsc -p tsconfig.json --noEmit",
60
- "lint": "eslint src"
61
- }
62
- }
61
+ "license": "MIT"
62
+ }