@create-markdown/core
v0.1.0
Published
Block-based markdown parsing and serialization with zero dependencies
Maintainers
Readme
@create-markdown/core
Block-based markdown parsing and serialization with zero dependencies.
Installation
# Using bun
bun add @create-markdown/core
# Using npm
npm install @create-markdown/core
# Using yarn
yarn add @create-markdown/core
# Using pnpm
pnpm add @create-markdown/coreQuick Start
Parse Markdown to Blocks
import { parse } from '@create-markdown/core';
const blocks = parse(`# Hello World
This is **bold** and *italic* text.
- Item one
- Item two
`);Create Blocks Programmatically
import { h1, paragraph, bulletList, bold, italic, spans } from '@create-markdown/core';
const blocks = [
h1('My Document'),
paragraph(spans(
bold('Important: '),
{ text: 'This is ', styles: {} },
italic('really'),
{ text: ' cool!', styles: {} }
)),
bulletList(['First item', 'Second item', 'Third item']),
];Serialize Blocks to Markdown
import { stringify, h1, paragraph, codeBlock } from '@create-markdown/core';
const markdown = stringify([
h1('Hello'),
paragraph('World'),
codeBlock('console.log("Hi!");', 'javascript'),
]);Block Types
| Type | Factory Function | Description |
|------|-----------------|-------------|
| paragraph | paragraph(content) | Text paragraph |
| heading | heading(level, content) or h1-h6 | Heading levels 1-6 |
| bulletList | bulletList(items) | Unordered list |
| numberedList | numberedList(items) | Ordered list |
| checkList | checkList(items) | Task list with checkboxes |
| codeBlock | codeBlock(code, language?) | Fenced code block |
| blockquote | blockquote(content) | Block quote |
| image | image(url, alt?) | Image |
| divider | divider() | Horizontal rule |
| table | table(headers, rows) | Table with headers |
| callout | callout(type, content) | Callout/admonition |
API Reference
Parsing
parse(markdown)- Parse markdown string to blocksmarkdownToBlocks(markdown, options?)- Full parser with optionsmarkdownToDocument(markdown)- Parse to a Document object
Serialization
stringify(blocks)- Serialize blocks to markdownblocksToMarkdown(blocks, options?)- Full serializer with optionsdocumentToMarkdown(doc)- Serialize a Document
Document Operations
createDocument(blocks?, options?)- Create a new documentinsertBlock(doc, block, index?)- Insert block at positionappendBlock(doc, block)- Add block at endremoveBlock(doc, blockId)- Remove block by IDupdateBlock(doc, blockId, updates)- Update block propertiesmoveBlock(doc, blockId, newIndex)- Reorder blocksfindBlock(doc, blockId)- Find block by ID
License
MIT
