create-markdown 0.1.1 → 0.2.2

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 CHANGED
@@ -3,10 +3,21 @@
3
3
  [![npm version](https://img.shields.io/npm/v/create-markdown.svg)](https://www.npmjs.com/package/create-markdown)
4
4
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
5
 
6
- Markdown package to enable creating markdown interfaces seamlessly because it is complicated and annoying asf.
6
+ A complete block-based markdown notes package with zero dependencies. Parse, create, and serialize markdown with full TypeScript support.
7
7
 
8
8
  ðŸ“Ķ **[View on npm](https://www.npmjs.com/package/create-markdown)**
9
9
 
10
+ ## Features
11
+
12
+ - ðŸ§ą **Block-based architecture** - Work with structured blocks instead of raw strings
13
+ - 🔄 **Bidirectional conversion** - Parse markdown to blocks, serialize blocks to markdown
14
+ - 📝 **Rich inline styles** - Bold, italic, code, links, strikethrough, highlights
15
+ - ⚛ïļ **React components** - Optional React bindings for rendering and editing
16
+ - âœĻ **Live WYSIWYG editing** - Interactive playground with real-time markdown rendering
17
+ - ðŸŠķ **Zero dependencies** - Core package has no runtime dependencies
18
+ - 🔒 **Full TypeScript** - Complete type definitions with generics
19
+ - 🚀 **Framework ready** - Works with Next.js, Vite, Remix, Astro, and more
20
+
10
21
  ## Installation
11
22
 
12
23
  ```bash
@@ -23,74 +34,222 @@ yarn add create-markdown
23
34
  pnpm add create-markdown
24
35
  ```
25
36
 
26
- ## Usage
37
+ ## Quick Start
27
38
 
28
- ### ESM (recommended)
39
+ ### Parse Markdown to Blocks
29
40
 
30
41
  ```typescript
31
- import { createMarkdown } from 'create-markdown';
42
+ import { parse } from 'create-markdown';
43
+
44
+ const blocks = parse(`# Hello World
45
+
46
+ This is **bold** and *italic* text.
32
47
 
33
- const doc = createMarkdown('# Hello World');
34
- console.log(doc.content);
48
+ - Item one
49
+ - Item two
50
+ `);
51
+
52
+ console.log(blocks);
53
+ // [
54
+ // { type: 'heading', props: { level: 1 }, content: [...] },
55
+ // { type: 'paragraph', content: [...] },
56
+ // { type: 'bulletList', children: [...] }
57
+ // ]
35
58
  ```
36
59
 
37
- ### Default Export
60
+ ### Create Blocks Programmatically
38
61
 
39
62
  ```typescript
40
- import createMarkdown from 'create-markdown';
63
+ import { h1, paragraph, bulletList, bold, italic, spans } from 'create-markdown';
64
+
65
+ const blocks = [
66
+ h1('My Document'),
67
+ paragraph(spans(
68
+ bold('Important: '),
69
+ { text: 'This is ', styles: {} },
70
+ italic('really'),
71
+ { text: ' cool!', styles: {} }
72
+ )),
73
+ bulletList(['First item', 'Second item', 'Third item']),
74
+ ];
75
+ ```
41
76
 
42
- const doc = createMarkdown('# Hello World');
43
- console.log(doc.content);
77
+ ### Serialize Blocks to Markdown
78
+
79
+ ```typescript
80
+ import { stringify, h1, paragraph, codeBlock } from 'create-markdown';
81
+
82
+ const markdown = stringify([
83
+ h1('Hello'),
84
+ paragraph('World'),
85
+ codeBlock('console.log("Hi!");', 'javascript'),
86
+ ]);
87
+
88
+ console.log(markdown);
89
+ // # Hello
90
+ //
91
+ // World
92
+ //
93
+ // ```javascript
94
+ // console.log("Hi!");
95
+ // ```
44
96
  ```
45
97
 
46
- ### CommonJS
98
+ ### Document Management
47
99
 
48
- ```javascript
49
- const { createMarkdown } = require('create-markdown');
100
+ ```typescript
101
+ import {
102
+ createDocument,
103
+ appendBlock,
104
+ removeBlock,
105
+ findBlock,
106
+ paragraph
107
+ } from 'create-markdown';
108
+
109
+ // Create a document
110
+ let doc = createDocument([paragraph('First paragraph')]);
111
+
112
+ // Add a block
113
+ doc = appendBlock(doc, paragraph('Second paragraph'));
114
+
115
+ // Find a block
116
+ const block = findBlock(doc, 'some-id');
50
117
 
51
- const doc = createMarkdown('# Hello World');
52
- console.log(doc.content);
118
+ // Remove a block
119
+ doc = removeBlock(doc, 'some-id');
53
120
  ```
54
121
 
55
- ### With Options
122
+ ## React Components
123
+
124
+ Optional React bindings are available via a separate import:
125
+
126
+ ```tsx
127
+ import { BlockRenderer, useDocument, useMarkdown } from 'create-markdown/react';
128
+ import { paragraph, h1 } from 'create-markdown/react';
129
+
130
+ function Editor() {
131
+ const { blocks, appendBlock, toMarkdown } = useDocument();
132
+
133
+ return (
134
+ <div>
135
+ <BlockRenderer blocks={blocks} />
136
+ <button onClick={() => appendBlock(paragraph('New paragraph'))}>
137
+ Add Paragraph
138
+ </button>
139
+ <button onClick={() => console.log(toMarkdown())}>
140
+ Export Markdown
141
+ </button>
142
+ </div>
143
+ );
144
+ }
145
+
146
+ function MarkdownEditor() {
147
+ const { markdown, blocks, setMarkdown } = useMarkdown('# Hello');
148
+
149
+ return (
150
+ <div>
151
+ <textarea
152
+ value={markdown}
153
+ onChange={(e) => setMarkdown(e.target.value)}
154
+ />
155
+ <BlockRenderer blocks={blocks} />
156
+ </div>
157
+ );
158
+ }
159
+ ```
56
160
 
57
- ```typescript
58
- import { createMarkdown, type MarkdownOptions } from 'create-markdown';
161
+ ## Block Types
162
+
163
+ | Type | Factory Function | Description |
164
+ |------|-----------------|-------------|
165
+ | `paragraph` | `paragraph(content)` | Text paragraph |
166
+ | `heading` | `heading(level, content)` or `h1`-`h6` | Heading levels 1-6 |
167
+ | `bulletList` | `bulletList(items)` | Unordered list |
168
+ | `numberedList` | `numberedList(items)` | Ordered list |
169
+ | `checkList` | `checkList(items)` | Task list with checkboxes |
170
+ | `codeBlock` | `codeBlock(code, language?)` | Fenced code block |
171
+ | `blockquote` | `blockquote(content)` | Block quote |
172
+ | `image` | `image(url, alt?)` | Image |
173
+ | `divider` | `divider()` | Horizontal rule |
174
+ | `table` | `table(headers, rows)` | Table with headers |
175
+ | `callout` | `callout(type, content)` | Callout/admonition |
59
176
 
60
- const options: MarkdownOptions = {
61
- strict: true,
62
- lineEnding: '\n',
63
- };
177
+ ## Inline Styles
64
178
 
65
- const doc = createMarkdown('# My Document', options);
179
+ ```typescript
180
+ import { bold, italic, code, link, strikethrough, highlight } from 'create-markdown';
181
+
182
+ // Create styled text spans
183
+ const content = [
184
+ bold('Bold text'),
185
+ italic('Italic text'),
186
+ code('inline code'),
187
+ link('Click here', 'https://example.com'),
188
+ strikethrough('deleted'),
189
+ highlight('highlighted'),
190
+ ];
66
191
  ```
67
192
 
68
- ## API
193
+ ## API Reference
69
194
 
70
- ### `createMarkdown(content?, options?)`
195
+ ### Parsing
71
196
 
72
- Creates a new markdown document.
197
+ - `parse(markdown)` - Parse markdown string to blocks
198
+ - `markdownToBlocks(markdown, options?)` - Full parser with options
199
+ - `markdownToDocument(markdown)` - Parse to a Document object
73
200
 
74
- **Parameters:**
75
- - `content` (string, optional): Initial markdown content
76
- - `options` (MarkdownOptions, optional): Configuration options
77
- - `strict` (boolean): Enable strict parsing mode
78
- - `lineEnding` (string): Custom line ending (default: `'\n'`)
201
+ ### Serialization
79
202
 
80
- **Returns:** `MarkdownDocument`
81
- - `content` (string): Raw markdown content
82
- - `meta` (Record<string, unknown>): Document metadata
203
+ - `stringify(blocks)` - Serialize blocks to markdown
204
+ - `blocksToMarkdown(blocks, options?)` - Full serializer with options
205
+ - `documentToMarkdown(doc)` - Serialize a Document
83
206
 
84
- ### `VERSION`
207
+ ### Document Operations
85
208
 
86
- Package version string.
209
+ - `createDocument(blocks?, options?)` - Create a new document
210
+ - `insertBlock(doc, block, index?)` - Insert block at position
211
+ - `appendBlock(doc, block)` - Add block at end
212
+ - `removeBlock(doc, blockId)` - Remove block by ID
213
+ - `updateBlock(doc, blockId, updates)` - Update block properties
214
+ - `moveBlock(doc, blockId, newIndex)` - Reorder blocks
215
+ - `findBlock(doc, blockId)` - Find block by ID
87
216
 
88
- ```typescript
89
- import { VERSION } from 'create-markdown';
217
+ ### React Hooks
218
+
219
+ - `useDocument(initialBlocks?)` - Full document state management
220
+ - `useMarkdown(initialMarkdown?)` - Bidirectional markdown/blocks
221
+ - `useBlockEditor(doc)` - Selection and editing operations
222
+
223
+ ## Integration
224
+
225
+ For detailed framework-specific setup guides, see the **[Integration Guide](./INTEGRATION.md)**.
226
+
227
+ Quick links:
228
+ - [Next.js (App Router)](./INTEGRATION.md#nextjs-app-router)
229
+ - [Next.js (Pages Router)](./INTEGRATION.md#nextjs-pages-router)
230
+ - [Vite + React](./INTEGRATION.md#vite--react)
231
+ - [Remix](./INTEGRATION.md#remix)
232
+ - [Astro](./INTEGRATION.md#astro)
233
+ - [Node.js / Server-side](./INTEGRATION.md#nodejs--server-side)
234
+
235
+ ## Playground
90
236
 
91
- console.log(VERSION); // '0.1.1'
237
+ The package includes a full WYSIWYG playground editor demonstrating all features:
238
+
239
+ ```bash
240
+ # Run the interactive playground
241
+ bun run playground
92
242
  ```
93
243
 
244
+ **Playground Features:**
245
+ - Click-to-edit blocks with live markdown rendering
246
+ - Markdown shortcuts (`#` headings, `-` lists, `>` quotes, ``` code, `---` dividers)
247
+ - Inline formatting (`**bold**`, `*italic*`, `` `code` ``, `~~strike~~`, `==highlight==`, `[link](url)`)
248
+ - Keyboard shortcuts (Cmd/Ctrl+B, Cmd/Ctrl+I, Cmd/Ctrl+U)
249
+ - List item management with Enter/Backspace/Tab
250
+ - Dark/light theme toggle
251
+ - Export to markdown
252
+
94
253
  ## Development
95
254
 
96
255
  ```bash
@@ -100,11 +259,8 @@ bun install
100
259
  # Build the package
101
260
  bun run build
102
261
 
103
- # Watch mode during development
104
- bun run dev
105
-
106
- # Clean build artifacts
107
- bun run clean
262
+ # Type check
263
+ bun run typecheck
108
264
 
109
265
  # Run the playground
110
266
  bun run playground
@@ -114,6 +270,16 @@ bun run playground
114
270
 
115
271
  - Node.js 20+
116
272
  - Bun 1.0+ (for development)
273
+ - React 18+ (optional, for React components)
274
+
275
+ ## Documentation
276
+
277
+ | Document | Description |
278
+ |----------|-------------|
279
+ | [README.md](./README.md) | Quick start and API overview |
280
+ | [INTEGRATION.md](./INTEGRATION.md) | Framework-specific setup guides |
281
+ | [CONTRIBUTING.md](./CONTRIBUTING.md) | Contribution guidelines |
282
+ | [CHANGELOG.md](./CHANGELOG.md) | Version history |
117
283
 
118
284
  ## Contributing
119
285
 
@@ -0,0 +1,136 @@
1
+ /**
2
+ * create-markdown - Block Factory Functions
3
+ * Create and manipulate block structures
4
+ */
5
+ import type { Block, BlockType, TextSpan, InlineStyle, HeadingBlock, ParagraphBlock, BulletListBlock, NumberedListBlock, CheckListBlock, CodeBlockBlock, BlockquoteBlock, ImageBlock, DividerBlock, CalloutBlock, CalloutType, TableBlock } from '../types';
6
+ /**
7
+ * Creates: block with the specified type and properties
8
+ */
9
+ export declare function createBlock<T extends BlockType>(type: T, content?: TextSpan[], props?: Block<T>['props'], children?: Block[]): Block<T>;
10
+ /**
11
+ * Creates: plain text span with no styles
12
+ */
13
+ export declare function text(content: string): TextSpan;
14
+ /**
15
+ * Creates: bold text span
16
+ */
17
+ export declare function bold(content: string): TextSpan;
18
+ /**
19
+ * Creates: italic text span
20
+ */
21
+ export declare function italic(content: string): TextSpan;
22
+ /**
23
+ * Creates: inline code text span
24
+ */
25
+ export declare function code(content: string): TextSpan;
26
+ /**
27
+ * Creates: strikethrough text span
28
+ */
29
+ export declare function strikethrough(content: string): TextSpan;
30
+ /**
31
+ * Creates: underlined text span
32
+ */
33
+ export declare function underline(content: string): TextSpan;
34
+ /**
35
+ * Creates: highlighted text span
36
+ */
37
+ export declare function highlight(content: string): TextSpan;
38
+ /**
39
+ * Creates: link text span
40
+ */
41
+ export declare function link(content: string, url: string, title?: string): TextSpan;
42
+ /**
43
+ * Creates: text span with custom styles
44
+ */
45
+ export declare function styled(content: string, styles: InlineStyle): TextSpan;
46
+ /**
47
+ * Combines multiple text spans into a content array
48
+ */
49
+ export declare function spans(...textSpans: TextSpan[]): TextSpan[];
50
+ /**
51
+ * Creates: paragraph block
52
+ */
53
+ export declare function paragraph(content: string | TextSpan[]): ParagraphBlock;
54
+ /**
55
+ * Creates: heading block
56
+ */
57
+ export declare function heading(level: 1 | 2 | 3 | 4 | 5 | 6, content: string | TextSpan[]): HeadingBlock;
58
+ export declare const h1: (content: string | TextSpan[]) => HeadingBlock;
59
+ export declare const h2: (content: string | TextSpan[]) => HeadingBlock;
60
+ export declare const h3: (content: string | TextSpan[]) => HeadingBlock;
61
+ export declare const h4: (content: string | TextSpan[]) => HeadingBlock;
62
+ export declare const h5: (content: string | TextSpan[]) => HeadingBlock;
63
+ export declare const h6: (content: string | TextSpan[]) => HeadingBlock;
64
+ /**
65
+ * Creates: bullet list block with items
66
+ */
67
+ export declare function bulletList(items: (string | TextSpan[] | Block)[]): BulletListBlock;
68
+ /**
69
+ * Creates: numbered list block with items
70
+ */
71
+ export declare function numberedList(items: (string | TextSpan[] | Block)[]): NumberedListBlock;
72
+ /**
73
+ * Creates: checklist item
74
+ */
75
+ export declare function checkListItem(content: string | TextSpan[], checked?: boolean): CheckListBlock;
76
+ /**
77
+ * Creates: checklist with multiple items
78
+ */
79
+ export declare function checkList(items: {
80
+ content: string | TextSpan[];
81
+ checked?: boolean;
82
+ }[]): Block[];
83
+ /**
84
+ * Creates: code block
85
+ */
86
+ export declare function codeBlock(code: string, language?: string): CodeBlockBlock;
87
+ /**
88
+ * Creates: blockquote
89
+ */
90
+ export declare function blockquote(content: string | TextSpan[]): BlockquoteBlock;
91
+ /**
92
+ * Creates: horizontal divider
93
+ */
94
+ export declare function divider(): DividerBlock;
95
+ /**
96
+ * Creates: image block
97
+ */
98
+ export declare function image(url: string, alt?: string, options?: {
99
+ title?: string;
100
+ width?: number;
101
+ height?: number;
102
+ }): ImageBlock;
103
+ /**
104
+ * Creates: callout block
105
+ */
106
+ export declare function callout(type: CalloutType, content: string | TextSpan[]): CalloutBlock;
107
+ export declare const infoCallout: (content: string | TextSpan[]) => CalloutBlock;
108
+ export declare const warningCallout: (content: string | TextSpan[]) => CalloutBlock;
109
+ export declare const tipCallout: (content: string | TextSpan[]) => CalloutBlock;
110
+ export declare const dangerCallout: (content: string | TextSpan[]) => CalloutBlock;
111
+ export declare const noteCallout: (content: string | TextSpan[]) => CalloutBlock;
112
+ /**
113
+ * Creates: table block
114
+ */
115
+ export declare function table(headers: string[], rows: string[][], alignments?: ('left' | 'center' | 'right' | null)[]): TableBlock;
116
+ /**
117
+ * Adds: content to an existing block
118
+ */
119
+ export declare function appendContent<T extends BlockType>(block: Block<T>, ...newSpans: TextSpan[]): Block<T>;
120
+ /**
121
+ * Prepends: content to an existing block
122
+ */
123
+ export declare function prependContent<T extends BlockType>(block: Block<T>, ...newSpans: TextSpan[]): Block<T>;
124
+ /**
125
+ * Replaces: the content of a block
126
+ */
127
+ export declare function setContent<T extends BlockType>(block: Block<T>, content: TextSpan[]): Block<T>;
128
+ /**
129
+ * Adds: children to a block
130
+ */
131
+ export declare function addChildren<T extends BlockType>(block: Block<T>, ...newChildren: Block[]): Block<T>;
132
+ /**
133
+ * Updates: block properties
134
+ */
135
+ export declare function updateProps<T extends BlockType>(block: Block<T>, props: Partial<Block<T>['props']>): Block<T>;
136
+ //# sourceMappingURL=blocks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"blocks.d.ts","sourceRoot":"","sources":["../../src/core/blocks.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EACV,KAAK,EACL,SAAS,EACT,QAAQ,EACR,WAAW,EACX,YAAY,EACZ,cAAc,EACd,eAAe,EACf,iBAAiB,EACjB,cAAc,EACd,cAAc,EACd,eAAe,EACf,UAAU,EACV,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,UAAU,EACX,MAAM,UAAU,CAAC;AAOlB;;GAEG;AACH,wBAAgB,WAAW,CAAC,CAAC,SAAS,SAAS,EAC7C,IAAI,EAAE,CAAC,EACP,OAAO,GAAE,QAAQ,EAAO,EACxB,KAAK,GAAE,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAA2B,EAClD,QAAQ,GAAE,KAAK,EAAO,GACrB,KAAK,CAAC,CAAC,CAAC,CAQV;AAMD;;GAEG;AACH,wBAAgB,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,QAAQ,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,EACf,OAAO,EAAE,QAAQ,EAAE,GAClB,KAAK,CAAC,CAAC,CAAC,CAKV;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,CAAC,SAAS,SAAS,EAC7C,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,EACf,GAAG,WAAW,EAAE,KAAK,EAAE,GACtB,KAAK,CAAC,CAAC,CAAC,CAKV;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,CAAC,SAAS,SAAS,EAC7C,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,EACf,KAAK,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,GAChC,KAAK,CAAC,CAAC,CAAC,CAKV"}
@@ -0,0 +1,135 @@
1
+ /**
2
+ * create-markdown - Document Management
3
+ * Create and manipulate document structures
4
+ */
5
+ import type { Block, BlockType, Document, DocumentMeta, DocumentOptions, TextSpan } from '../types';
6
+ /**
7
+ * Current document schema version
8
+ */
9
+ export declare const DOCUMENT_VERSION = 1;
10
+ /**
11
+ * Creates: new document with optional initial blocks and metadata
12
+ */
13
+ export declare function createDocument(blocks?: Block[], options?: DocumentOptions): Document;
14
+ /**
15
+ * Creates: empty document
16
+ */
17
+ export declare function emptyDocument(options?: DocumentOptions): Document;
18
+ /**
19
+ * Clones: document with new IDs for all blocks
20
+ */
21
+ export declare function cloneDocument(doc: Document): Document;
22
+ /**
23
+ * Inserts: block at the specified index
24
+ * If index is not provided, appends to the end
25
+ */
26
+ export declare function insertBlock(doc: Document, block: Block, index?: number): Document;
27
+ /**
28
+ * Appends: block to the end of the document
29
+ */
30
+ export declare function appendBlock(doc: Document, block: Block): Document;
31
+ /**
32
+ * Prepends: block to the beginning of the document
33
+ */
34
+ export declare function prependBlock(doc: Document, block: Block): Document;
35
+ /**
36
+ * Inserts: multiple blocks at the specified index
37
+ */
38
+ export declare function insertBlocks(doc: Document, blocks: Block[], index?: number): Document;
39
+ /**
40
+ * Removes: block by its ID
41
+ */
42
+ export declare function removeBlock(doc: Document, blockId: string): Document;
43
+ /**
44
+ * Removes: multiple blocks by their IDs
45
+ */
46
+ export declare function removeBlocks(doc: Document, blockIds: string[]): Document;
47
+ /**
48
+ * Updates: block by its ID with partial updates
49
+ */
50
+ export declare function updateBlock<T extends BlockType>(doc: Document, blockId: string, updates: Partial<Omit<Block<T>, 'id' | 'type'>>): Document;
51
+ /**
52
+ * Replaces: block entirely by its ID
53
+ */
54
+ export declare function replaceBlock(doc: Document, blockId: string, newBlock: Block): Document;
55
+ /**
56
+ * Moves: block to a new position
57
+ */
58
+ export declare function moveBlock(doc: Document, blockId: string, newIndex: number): Document;
59
+ /**
60
+ * Swaps: two blocks by their IDs
61
+ */
62
+ export declare function swapBlocks(doc: Document, blockId1: string, blockId2: string): Document;
63
+ /**
64
+ * Finds: block by its ID
65
+ */
66
+ export declare function findBlock(doc: Document, blockId: string): Block | undefined;
67
+ /**
68
+ * Finds: index of a block by its ID
69
+ */
70
+ export declare function getBlockIndex(doc: Document, blockId: string): number;
71
+ /**
72
+ * Gets: block at the specified index
73
+ */
74
+ export declare function getBlockAt(doc: Document, index: number): Block | undefined;
75
+ /**
76
+ * Gets: first block in the document
77
+ */
78
+ export declare function getFirstBlock(doc: Document): Block | undefined;
79
+ /**
80
+ * Gets: last block in the document
81
+ */
82
+ export declare function getLastBlock(doc: Document): Block | undefined;
83
+ /**
84
+ * Finds: all blocks of a specific type
85
+ */
86
+ export declare function findBlocksByType<T extends BlockType>(doc: Document, type: T): Block<T>[];
87
+ /**
88
+ * Checks: if the document contains a block with the given ID
89
+ */
90
+ export declare function hasBlock(doc: Document, blockId: string): boolean;
91
+ /**
92
+ * Gets: total number of blocks in the document
93
+ */
94
+ export declare function getBlockCount(doc: Document): number;
95
+ /**
96
+ * Checks: if the document is empty
97
+ */
98
+ export declare function isEmpty(doc: Document): boolean;
99
+ /**
100
+ * Updates: content of a specific block
101
+ */
102
+ export declare function setBlockContent(doc: Document, blockId: string, content: TextSpan[]): Document;
103
+ /**
104
+ * Appends: content to a specific block
105
+ */
106
+ export declare function appendBlockContent(doc: Document, blockId: string, content: TextSpan[]): Document;
107
+ /**
108
+ * Updates: document metadata
109
+ */
110
+ export declare function updateMeta(doc: Document, meta: Partial<DocumentMeta>): Document;
111
+ /**
112
+ * Sets: specific metadata field
113
+ */
114
+ export declare function setMetaField(doc: Document, key: string, value: unknown): Document;
115
+ /**
116
+ * Gets: specific metadata field
117
+ */
118
+ export declare function getMetaField<T = unknown>(doc: Document, key: string): T | undefined;
119
+ /**
120
+ * Clears: all blocks from the document
121
+ */
122
+ export declare function clearBlocks(doc: Document): Document;
123
+ /**
124
+ * Replaces: all blocks in the document
125
+ */
126
+ export declare function setBlocks(doc: Document, blocks: Block[]): Document;
127
+ /**
128
+ * Filters: blocks based on a predicate
129
+ */
130
+ export declare function filterBlocks(doc: Document, predicate: (block: Block, index: number) => boolean): Document;
131
+ /**
132
+ * Maps: over all blocks and transforms them
133
+ */
134
+ export declare function mapBlocks(doc: Document, transform: (block: Block, index: number) => Block): Document;
135
+ //# sourceMappingURL=document.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"document.d.ts","sourceRoot":"","sources":["../../src/core/document.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EACV,KAAK,EACL,SAAS,EACT,QAAQ,EACR,YAAY,EACZ,eAAe,EACf,QAAQ,EACT,MAAM,UAAU,CAAC;AAOlB;;GAEG;AACH,eAAO,MAAM,gBAAgB,IAAI,CAAC;AAMlC;;GAEG;AACH,wBAAgB,cAAc,CAC1B,MAAM,GAAE,KAAK,EAAO,EACpB,OAAO,GAAE,eAAoB,GAC9B,QAAQ,CAYV;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,OAAO,GAAE,eAAoB,GAAG,QAAQ,CAErE;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,QAAQ,GAAG,QAAQ,CAUrD;AAMD;;;GAGG;AACH,wBAAg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,QAAQ,EACb,IAAI,EAAE,OAAO,CAAC,YAAY,CAAC,GAC5B,QAAQ,CASV;AAED;;GAEG;AACH,wBAAgB,YAAY,CACxB,GAAG,EAAE,QAAQ,EACb,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,OAAO,GACf,QAAQ,CAEV;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,CAAC,GAAG,OAAO,EACpC,GAAG,EAAE,QAAQ,EACb,GAAG,EAAE,MAAM,GACZ,CAAC,GAAG,SAAS,CAEf;AAMD;;GAEG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,QAAQ,GAAG,QAAQ,CASnD;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,QAAQ,CASlE;AAED;;GAEG;AACH,wBAAgB,YAAY,CACxB,GAAG,EAAE,QAAQ,EACb,SAAS,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,GACpD,QAAQ,CAeV;AAED;;GAEG;AACH,wBAAgB,SAAS,CACrB,GAAG,EAAE,QAAQ,EACb,SAAS,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,KAAK,KAAK,GAClD,QAAQ,CASV"}
@@ -0,0 +1,80 @@
1
+ /**
2
+ * create-markdown - Utility Functions
3
+ * Core utilities for block manipulation and markdown handling
4
+ */
5
+ import type { Block, BlockType, TextSpan } from '../types';
6
+ /**
7
+ * Generates a unique ID for blocks
8
+ * Nano ID-style implementation without dependencies
9
+ */
10
+ export declare function generateId(length?: number): string;
11
+ /**
12
+ * Deep clones a block and all its children
13
+ * Generates new IDs for cloned blocks to ensure uniqueness
14
+ */
15
+ export declare function deepClone<T extends BlockType>(block: Block<T>, regenerateIds?: boolean): Block<T>;
16
+ /**
17
+ * Deep clones an array of blocks
18
+ */
19
+ export declare function deepCloneBlocks(blocks: Block[], regenerateIds?: boolean): Block[];
20
+ /**
21
+ * Normalizes line endings to LF (\n)
22
+ */
23
+ export declare function normalizeLineEndings(text: string): string;
24
+ /**
25
+ * Converts line endings to the specified format
26
+ */
27
+ export declare function convertLineEndings(text: string, lineEnding: '\n' | '\r\n'): string;
28
+ /**
29
+ * Escapes special markdown characters in text
30
+ */
31
+ export declare function escapeMarkdown(text: string): string;
32
+ /**
33
+ * Unescapes markdown escape sequences
34
+ */
35
+ export declare function unescapeMarkdown(text: string): string;
36
+ /**
37
+ * Escapes text for use inside code blocks (minimal escaping)
38
+ */
39
+ export declare function escapeCodeBlock(text: string): string;
40
+ /**
41
+ * Trims trailing whitespace from each line
42
+ */
43
+ export declare function trimTrailingWhitespace(text: string): string;
44
+ /**
45
+ * Removes leading/trailing blank lines
46
+ */
47
+ export declare function trimBlankLines(text: string): string;
48
+ /**
49
+ * Indents each line of text by the specified number of spaces
50
+ */
51
+ export declare function indent(text: string, spaces: number): string;
52
+ /**
53
+ * Extracts plain text from an array of text spans
54
+ */
55
+ export declare function spansToPlainText(spans: TextSpan[]): string;
56
+ /**
57
+ * Creates a simple text span with no styles
58
+ */
59
+ export declare function plainSpan(text: string): TextSpan;
60
+ /**
61
+ * Creates an array with a single plain text span
62
+ */
63
+ export declare function plainContent(text: string): TextSpan[];
64
+ /**
65
+ * Checks if a block has any content
66
+ */
67
+ export declare function hasContent(block: Block): boolean;
68
+ /**
69
+ * Checks if a block has children
70
+ */
71
+ export declare function hasChildren(block: Block): boolean;
72
+ /**
73
+ * Validates a heading level
74
+ */
75
+ export declare function isValidHeadingLevel(level: number): level is 1 | 2 | 3 | 4 | 5 | 6;
76
+ /**
77
+ * Validates a block type
78
+ */
79
+ export declare function isValidBlockType(type: string): type is BlockType;
80
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/core/utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,KAAK,EAA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