create-markdown 0.1.1 → 0.2.0

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,19 @@
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
+ - ðŸŠķ **Zero dependencies** - Core package has no runtime dependencies
17
+ - 🔒 **Full TypeScript** - Complete type definitions with generics
18
+
10
19
  ## Installation
11
20
 
12
21
  ```bash
@@ -23,73 +32,191 @@ yarn add create-markdown
23
32
  pnpm add create-markdown
24
33
  ```
25
34
 
26
- ## Usage
35
+ ## Quick Start
27
36
 
28
- ### ESM (recommended)
37
+ ### Parse Markdown to Blocks
29
38
 
30
39
  ```typescript
31
- import { createMarkdown } from 'create-markdown';
40
+ import { parse } from 'create-markdown';
41
+
42
+ const blocks = parse(`# Hello World
43
+
44
+ This is **bold** and *italic* text.
45
+
46
+ - Item one
47
+ - Item two
48
+ `);
32
49
 
33
- const doc = createMarkdown('# Hello World');
34
- console.log(doc.content);
50
+ console.log(blocks);
51
+ // [
52
+ // { type: 'heading', props: { level: 1 }, content: [...] },
53
+ // { type: 'paragraph', content: [...] },
54
+ // { type: 'bulletList', children: [...] }
55
+ // ]
35
56
  ```
36
57
 
37
- ### Default Export
58
+ ### Create Blocks Programmatically
38
59
 
39
60
  ```typescript
40
- import createMarkdown from 'create-markdown';
61
+ import { h1, paragraph, bulletList, bold, italic, spans } from 'create-markdown';
62
+
63
+ const blocks = [
64
+ h1('My Document'),
65
+ paragraph(spans(
66
+ bold('Important: '),
67
+ { text: 'This is ', styles: {} },
68
+ italic('really'),
69
+ { text: ' cool!', styles: {} }
70
+ )),
71
+ bulletList(['First item', 'Second item', 'Third item']),
72
+ ];
73
+ ```
74
+
75
+ ### Serialize Blocks to Markdown
41
76
 
42
- const doc = createMarkdown('# Hello World');
43
- console.log(doc.content);
77
+ ```typescript
78
+ import { stringify, h1, paragraph, codeBlock } from 'create-markdown';
79
+
80
+ const markdown = stringify([
81
+ h1('Hello'),
82
+ paragraph('World'),
83
+ codeBlock('console.log("Hi!");', 'javascript'),
84
+ ]);
85
+
86
+ console.log(markdown);
87
+ // # Hello
88
+ //
89
+ // World
90
+ //
91
+ // ```javascript
92
+ // console.log("Hi!");
93
+ // ```
44
94
  ```
45
95
 
46
- ### CommonJS
96
+ ### Document Management
97
+
98
+ ```typescript
99
+ import {
100
+ createDocument,
101
+ appendBlock,
102
+ removeBlock,
103
+ findBlock,
104
+ paragraph
105
+ } from 'create-markdown';
47
106
 
48
- ```javascript
49
- const { createMarkdown } = require('create-markdown');
107
+ // Create a document
108
+ let doc = createDocument([paragraph('First paragraph')]);
50
109
 
51
- const doc = createMarkdown('# Hello World');
52
- console.log(doc.content);
110
+ // Add a block
111
+ doc = appendBlock(doc, paragraph('Second paragraph'));
112
+
113
+ // Find a block
114
+ const block = findBlock(doc, 'some-id');
115
+
116
+ // Remove a block
117
+ doc = removeBlock(doc, 'some-id');
53
118
  ```
54
119
 
55
- ### With Options
120
+ ## React Components
121
+
122
+ Optional React bindings are available via a separate import:
123
+
124
+ ```tsx
125
+ import { BlockRenderer, useDocument, useMarkdown } from 'create-markdown/react';
126
+ import { paragraph, h1 } from 'create-markdown/react';
127
+
128
+ function Editor() {
129
+ const { blocks, appendBlock, toMarkdown } = useDocument();
130
+
131
+ return (
132
+ <div>
133
+ <BlockRenderer blocks={blocks} />
134
+ <button onClick={() => appendBlock(paragraph('New paragraph'))}>
135
+ Add Paragraph
136
+ </button>
137
+ <button onClick={() => console.log(toMarkdown())}>
138
+ Export Markdown
139
+ </button>
140
+ </div>
141
+ );
142
+ }
143
+
144
+ function MarkdownEditor() {
145
+ const { markdown, blocks, setMarkdown } = useMarkdown('# Hello');
146
+
147
+ return (
148
+ <div>
149
+ <textarea
150
+ value={markdown}
151
+ onChange={(e) => setMarkdown(e.target.value)}
152
+ />
153
+ <BlockRenderer blocks={blocks} />
154
+ </div>
155
+ );
156
+ }
157
+ ```
56
158
 
57
- ```typescript
58
- import { createMarkdown, type MarkdownOptions } from 'create-markdown';
159
+ ## Block Types
160
+
161
+ | Type | Factory Function | Description |
162
+ |------|-----------------|-------------|
163
+ | `paragraph` | `paragraph(content)` | Text paragraph |
164
+ | `heading` | `heading(level, content)` or `h1`-`h6` | Heading levels 1-6 |
165
+ | `bulletList` | `bulletList(items)` | Unordered list |
166
+ | `numberedList` | `numberedList(items)` | Ordered list |
167
+ | `checkList` | `checkList(items)` | Task list with checkboxes |
168
+ | `codeBlock` | `codeBlock(code, language?)` | Fenced code block |
169
+ | `blockquote` | `blockquote(content)` | Block quote |
170
+ | `image` | `image(url, alt?)` | Image |
171
+ | `divider` | `divider()` | Horizontal rule |
172
+ | `table` | `table(headers, rows)` | Table with headers |
173
+ | `callout` | `callout(type, content)` | Callout/admonition |
59
174
 
60
- const options: MarkdownOptions = {
61
- strict: true,
62
- lineEnding: '\n',
63
- };
175
+ ## Inline Styles
64
176
 
65
- const doc = createMarkdown('# My Document', options);
177
+ ```typescript
178
+ import { bold, italic, code, link, strikethrough, highlight } from 'create-markdown';
179
+
180
+ // Create styled text spans
181
+ const content = [
182
+ bold('Bold text'),
183
+ italic('Italic text'),
184
+ code('inline code'),
185
+ link('Click here', 'https://example.com'),
186
+ strikethrough('deleted'),
187
+ highlight('highlighted'),
188
+ ];
66
189
  ```
67
190
 
68
- ## API
191
+ ## API Reference
69
192
 
70
- ### `createMarkdown(content?, options?)`
193
+ ### Parsing
71
194
 
72
- Creates a new markdown document.
195
+ - `parse(markdown)` - Parse markdown string to blocks
196
+ - `markdownToBlocks(markdown, options?)` - Full parser with options
197
+ - `markdownToDocument(markdown)` - Parse to a Document object
73
198
 
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'`)
199
+ ### Serialization
79
200
 
80
- **Returns:** `MarkdownDocument`
81
- - `content` (string): Raw markdown content
82
- - `meta` (Record<string, unknown>): Document metadata
201
+ - `stringify(blocks)` - Serialize blocks to markdown
202
+ - `blocksToMarkdown(blocks, options?)` - Full serializer with options
203
+ - `documentToMarkdown(doc)` - Serialize a Document
83
204
 
84
- ### `VERSION`
205
+ ### Document Operations
85
206
 
86
- Package version string.
207
+ - `createDocument(blocks?, options?)` - Create a new document
208
+ - `insertBlock(doc, block, index?)` - Insert block at position
209
+ - `appendBlock(doc, block)` - Add block at end
210
+ - `removeBlock(doc, blockId)` - Remove block by ID
211
+ - `updateBlock(doc, blockId, updates)` - Update block properties
212
+ - `moveBlock(doc, blockId, newIndex)` - Reorder blocks
213
+ - `findBlock(doc, blockId)` - Find block by ID
87
214
 
88
- ```typescript
89
- import { VERSION } from 'create-markdown';
215
+ ### React Hooks
90
216
 
91
- console.log(VERSION); // '0.1.1'
92
- ```
217
+ - `useDocument(initialBlocks?)` - Full document state management
218
+ - `useMarkdown(initialMarkdown?)` - Bidirectional markdown/blocks
219
+ - `useBlockEditor(doc)` - Selection and editing operations
93
220
 
94
221
  ## Development
95
222
 
@@ -100,11 +227,8 @@ bun install
100
227
  # Build the package
101
228
  bun run build
102
229
 
103
- # Watch mode during development
104
- bun run dev
105
-
106
- # Clean build artifacts
107
- bun run clean
230
+ # Type check
231
+ bun run typecheck
108
232
 
109
233
  # Run the playground
110
234
  bun run playground
@@ -114,6 +238,7 @@ bun run playground
114
238
 
115
239
  - Node.js 20+
116
240
  - Bun 1.0+ (for development)
241
+ - React 18+ (optional, for React components)
117
242
 
118
243
  ## Contributing
119
244
 
@@ -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,CA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GAAG,QAAQ,EAAE,QAAQ,EAAE,GACtB,KAAK,CAAC,CAAC,CAAC,CAKV;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,CAAC,SAAS,SAAS,EAC5C,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,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;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,wBAAgB,kBAAkB,CAC9B,GAAG,EAAE,QAAQ,EACb,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,QAAQ,EAAE,GACpB,QAAQ,CAOV;AAMD;;GAEG;AACH,wBAAgB,UAAU,CACtB,GAAG,EAAE,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;
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