Skip to content

Commit 4bbdbad

Browse files
committed
v0.2.0
1 parent ef58cc1 commit 4bbdbad

19 files changed

Lines changed: 4848 additions & 165 deletions

CHANGELOG.md

Lines changed: 46 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,45 +8,64 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
## [Unreleased]
99

1010
### Planned
11-
- Additional markdown element builders (headings, lists, tables, etc.)
1211
- Frontmatter parsing support
1312
- Markdown validation utilities
13+
- Nested list support improvements
1414

1515
---
1616

17-
## [0.1.1] - 2026-01-20
17+
## [0.2.0] - 2026-01-20
1818

19-
### Added
20-
- Documentation for `VERSION` export
21-
- Documentation for default export usage
19+
### Added - Complete Block-Based Architecture
2220

23-
### Fixed
24-
- Corrected Node.js version requirement to 20+ (was incorrectly stated as 18+)
25-
- Fixed repository URL inconsistencies across documentation
21+
This release introduces a complete block-based markdown notes system with zero dependencies.
2622

27-
### Changed
28-
- Updated README with improved API documentation
23+
#### Core Types (`src/types/index.ts`)
24+
- `BlockType` union with 11 block types: paragraph, heading, bulletList, numberedList, checkList, codeBlock, blockquote, table, image, divider, callout
25+
- `Block<T>` generic interface with id, type, content, children, and props
26+
- `TextSpan` and `InlineStyle` for rich text formatting
27+
- `Document` interface for complete document representation
2928

30-
---
29+
#### Block Factory Functions (`src/core/blocks.ts`)
30+
- `createBlock()` - Generic block creator
31+
- `paragraph()`, `heading()`, `h1()`-`h6()` - Text blocks
32+
- `bulletList()`, `numberedList()`, `checkList()` - List blocks
33+
- `codeBlock()`, `blockquote()`, `divider()` - Structural blocks
34+
- `image()`, `table()`, `callout()` - Rich content blocks
35+
- Inline helpers: `bold()`, `italic()`, `code()`, `link()`, `strikethrough()`, `highlight()`
36+
37+
#### Document Management (`src/core/document.ts`)
38+
- `createDocument()`, `emptyDocument()`, `cloneDocument()`
39+
- CRUD operations: `insertBlock()`, `appendBlock()`, `removeBlock()`, `updateBlock()`
40+
- Query operations: `findBlock()`, `getBlockIndex()`, `findBlocksByType()`
41+
- Bulk operations: `setBlocks()`, `clearBlocks()`, `filterBlocks()`, `mapBlocks()`
42+
43+
#### Markdown Parser (`src/parsers/`)
44+
- `parse()` / `markdownToBlocks()` - Parse markdown strings to blocks
45+
- `markdownToDocument()` - Parse to full Document object
46+
- Line tokenizer with support for all common markdown constructs
47+
- Inline style parser with nesting support
48+
49+
#### Markdown Serializer (`src/serializers/markdown.ts`)
50+
- `stringify()` / `blocksToMarkdown()` - Serialize blocks to markdown
51+
- `documentToMarkdown()` - Serialize Document objects
52+
- Configurable options: lineEnding, listIndent, headingStyle, codeBlockStyle
3153

32-
## [0.1.0] - 2026-01-20
54+
#### React Components (`src/react/`) - Optional
55+
- `BlockRenderer` - Render blocks as React elements
56+
- `BlockElement` - Render single blocks with custom renderers
57+
- `InlineContent` - Render styled text spans
3358

34-
### Added
35-
- Initial release of `create-markdown`
36-
- `createMarkdown()` function for creating markdown documents
37-
- `MarkdownOptions` interface with `strict` and `lineEnding` options
38-
- `MarkdownDocument` interface with `content` and `meta` properties
39-
- Dual ESM/CommonJS module support
40-
- Full TypeScript type definitions
41-
- Cross-platform line ending normalization
59+
#### React Hooks (`src/react/hooks.ts`) - Optional
60+
- `useDocument()` - Full document state management
61+
- `useMarkdown()` - Bidirectional markdown/blocks state
62+
- `useBlockEditor()` - Selection and editing operations
4263

43-
### Technical
44-
- Built with Bun for fast builds
45-
- Zero runtime dependencies
46-
- Node.js 20+ support
64+
#### Convenience Functions
65+
- `fromMarkdown(markdown)` - Quick parse to Document
66+
- `toMarkdown(blocks)` - Quick serialize to string
4767

4868
---
4969

50-
[Unreleased]: https://github.com/BunsDev/create-markdown/compare/v0.1.1...HEAD
51-
[0.1.1]: https://github.com/BunsDev/create-markdown/compare/v0.1.0...v0.1.1
52-
[0.1.0]: https://github.com/BunsDev/create-markdown/releases/tag/v0.1.0
70+
[Unreleased]: https://github.com/BunsDev/create-markdown/compare/v0.2.0...HEAD
71+
[0.2.0]: https://github.com/BunsDev/create-markdown/releases/tag/v0.2.0

README.md

Lines changed: 170 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,19 @@
33
[![npm version](https://img.shields.io/npm/v/create-markdown.svg)](https://www.npmjs.com/package/create-markdown)
44
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
55

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.
77

88
📦 **[View on npm](https://www.npmjs.com/package/create-markdown)**
99

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+
1019
## Installation
1120

1221
```bash
@@ -23,73 +32,191 @@ yarn add create-markdown
2332
pnpm add create-markdown
2433
```
2534

26-
## Usage
35+
## Quick Start
2736

28-
### ESM (recommended)
37+
### Parse Markdown to Blocks
2938

3039
```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+
`);
3249

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+
// ]
3556
```
3657

37-
### Default Export
58+
### Create Blocks Programmatically
3859

3960
```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
4176

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+
// ```
4494
```
4595

46-
### CommonJS
96+
### Document Management
97+
98+
```typescript
99+
import {
100+
createDocument,
101+
appendBlock,
102+
removeBlock,
103+
findBlock,
104+
paragraph
105+
} from 'create-markdown';
47106

48-
```javascript
49-
const { createMarkdown } = require('create-markdown');
107+
// Create a document
108+
let doc = createDocument([paragraph('First paragraph')]);
50109

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');
53118
```
54119

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+
```
56158

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 |
59174

60-
const options: MarkdownOptions = {
61-
strict: true,
62-
lineEnding: '\n',
63-
};
175+
## Inline Styles
64176

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+
];
66189
```
67190

68-
## API
191+
## API Reference
69192

70-
### `createMarkdown(content?, options?)`
193+
### Parsing
71194

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
73198

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
79200

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
83204

84-
### `VERSION`
205+
### Document Operations
85206

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
87214

88-
```typescript
89-
import { VERSION } from 'create-markdown';
215+
### React Hooks
90216

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
93220

94221
## Development
95222

@@ -100,11 +227,8 @@ bun install
100227
# Build the package
101228
bun run build
102229

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
108232

109233
# Run the playground
110234
bun run playground
@@ -114,6 +238,7 @@ bun run playground
114238

115239
- Node.js 20+
116240
- Bun 1.0+ (for development)
241+
- React 18+ (optional, for React components)
117242

118243
## Contributing
119244

bun.lock

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)