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
2332pnpm 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
101228bun 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
110234bun 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
0 commit comments