@@ -8,22 +8,27 @@ Lightweight, block-based markdown solution (_zero dependencies_). Parse, create,
88## Packages
99| Package | Version | Description |
1010| ---------| ---------| -------------|
11- | [ @create-markdown/core ] ( ./packages/core ) | 0.1.0 | Zero-dependency parsing and serialization |
12- | [ @create-markdown/react ] ( ./packages/react ) | 0.1.0 | React components and hooks |
13- | [ @create-markdown/preview ] ( ./packages/preview ) | 0.1.0 | HTML rendering with Shiki and Mermaid |
14- | [ create-markdown] ( ./packages/create-markdown ) | 0.1.0 | Convenience bundle |
11+ | [ @create-markdown/core ] ( ./packages/core ) | 0.2.0 | Zero-dependency parsing and serialization |
12+ | [ @create-markdown/react ] ( ./packages/react ) | 0.2.0 | React components and hooks |
13+ | [ @create-markdown/preview ] ( ./packages/preview ) | 1.0.0 | HTML rendering with themes, plugins, and BYO-parser support |
14+ | [ @create-markdown/mdx ] ( ./packages/mdx ) | 0.2.0 | MDX conversion |
15+ | [ create-markdown] ( ./packages/create-markdown ) | 0.4.0 | Convenience bundle |
1516
1617## Key Features
1718- ** Block-based architecture** : Work with structured blocks instead of raw strings
18- - ** Bidirectional conversion** : Parse markdown to blocks, serialize blocks to markdown
19- - ** Rich inline styles** : Bold, italic, code, links, strikethrough, highlights
20- - ** React components** : Optional React bindings for rendering and editing
21- - ** HTML preview** : Framework-agnostic HTML rendering with themes
22- - ** Syntax highlighting** : Shiki plugin for code blocks
23- - ** Diagrams** : Mermaid plugin for flowcharts, sequence diagrams, etc.
24- - ** Web Component** : ` <markdown-preview> ` custom element
25- - ** Zero dependencies** : Core package has no runtime dependencies
26- - ** Full TypeScript** : Complete type definitions with generics
19+ - ** Bidirectional conversion** : Parse markdown to blocks, serialize blocks to markdown
20+ - ** Rich inline styles** : Bold, italic, code, links, strikethrough, highlights
21+ - ** React components** : Optional React bindings for rendering and editing
22+ - ** HTML preview** : Framework-agnostic HTML rendering with themes
23+ - ** BYO parser** : Use ` applyPreviewTheme() ` with ` marked ` , ` markdown-it ` , ` remark ` , or any parser -- no lock-in to ` @create-markdown/core `
24+ - ** CSS custom property theming** : ` system.css ` theme integrates with any design system via ` --cm-* ` variables
25+ - ** Syntax highlighting** : Shiki plugin for code blocks
26+ - ** Diagrams** : Mermaid plugin for flowcharts, sequence diagrams, etc.
27+ - ** Web Component** : ` <markdown-preview> ` custom element with optional light DOM mode
28+ - ** BYO sanitizer** : Plug in DOMPurify or any sanitizer function
29+ - ** Theme CSS as strings** : Import theme CSS as string constants for CSS-in-JS or web components
30+ - ** Zero dependencies** : Core package has no runtime dependencies
31+ - ** Full TypeScript** : Complete type definitions with generics
2732
2833## Installation
2934``` bash
@@ -37,6 +42,7 @@ bun add create-markdown
3742```
3843
3944## Quick Start
45+
4046### Parse and Serialize Markdown
4147``` typescript
4248import { parse , stringify , h1 , paragraph } from ' @create-markdown/core' ;
@@ -54,6 +60,20 @@ const doc = [
5460const markdown = stringify (doc );
5561```
5662
63+ ### Use with Any Markdown Parser
64+
65+ ` @create-markdown/preview ` works with any parser's HTML output -- no need to switch to ` @create-markdown/core ` :
66+
67+ ``` typescript
68+ import { applyPreviewTheme } from ' @create-markdown/preview' ;
69+ import { marked } from ' marked' ;
70+
71+ const raw = marked .parse (' # Hello\n\n Some **bold** text.' );
72+ const themed = applyPreviewTheme (raw ); // wraps elements with cm-* classes
73+ ```
74+
75+ Pair with any theme CSS (` github.css ` , ` github-dark.css ` , ` minimal.css ` , or ` system.css ` ) and the styled output just works.
76+
5777### React Components
5878
5979``` tsx
@@ -97,6 +117,61 @@ const html = await renderAsync(blocks, {
97117});
98118```
99119
120+ ### CSS Custom Property Theming
121+
122+ The ` system.css ` theme uses CSS custom properties so it adapts to any design system:
123+
124+ ``` css
125+ /* Set once -- the theme adapts to light and dark mode automatically */
126+ :root {
127+ --cm-text : #1f2328 ;
128+ --cm-bg : #ffffff ;
129+ --cm-border : #d1d9e0 ;
130+ --cm-code-bg : #f6f8fa ;
131+ --cm-link : #0969da ;
132+ }
133+
134+ @media (prefers-color-scheme: dark) {
135+ :root {
136+ --cm-text : #e6edf3 ;
137+ --cm-bg : #0d1117 ;
138+ --cm-border : #30363d ;
139+ --cm-code-bg : #161b22 ;
140+ --cm-link : #58a6ff ;
141+ }
142+ }
143+ ```
144+
145+ ``` typescript
146+ import ' @create-markdown/preview/themes/system.css' ;
147+ ```
148+
149+ ### BYO Sanitizer
150+
151+ Pass any sanitizer function instead of relying on a built-in implementation:
152+
153+ ``` typescript
154+ import { blocksToHTML } from ' @create-markdown/preview' ;
155+ import DOMPurify from ' dompurify' ;
156+
157+ const html = blocksToHTML (blocks , {
158+ sanitize : (html ) => DOMPurify .sanitize (html , { USE_PROFILES: { html: true } }),
159+ });
160+ ```
161+
162+ ### Theme CSS as Strings
163+
164+ Import theme CSS as string constants for CSS-in-JS, bundlers that struggle with CSS imports, or web components:
165+
166+ ``` typescript
167+ import { themes } from ' @create-markdown/preview/themes' ;
168+
169+ // themes.github, themes.githubDark, themes.minimal, themes.system
170+ const style = document .createElement (' style' );
171+ style .textContent = themes .githubDark ;
172+ document .head .appendChild (style );
173+ ```
174+
100175### Web Component
101176
102177``` html
@@ -112,6 +187,12 @@ This renders automatically!
112187</markdown-preview >
113188```
114189
190+ Use ` shadowMode: 'none' ` to render in the light DOM and inherit page styles:
191+
192+ ``` typescript
193+ registerPreviewElement ({ shadowMode: ' none' });
194+ ```
195+
115196## Documentation
116197
117198| Document | Description |
@@ -147,12 +228,15 @@ bun run playground
147228```
148229create-markdown/
149230├── packages/
150- │ ├── core/ # @create-markdown/core
151- │ ├── react/ # @create-markdown/react
152- │ ├── preview/ # @create-markdown/preview
153- │ └── create-markdown/ # Convenience bundle
154- ├── playground/ # Demo application
155- └── .github/ # CI/CD workflows
231+ │ ├── core/ # @create-markdown/core
232+ │ ├── react/ # @create-markdown/react
233+ │ ├── preview/ # @create-markdown/preview
234+ │ ├── mdx/ # @create-markdown/mdx
235+ │ ├── create-markdown/ # Convenience bundle
236+ │ └── docs/ # Documentation site
237+ ├── playground/ # Demo application
238+ ├── scripts/ # Release and utility scripts
239+ └── .github/ # CI/CD workflows
156240```
157241
158242## Contributing
0 commit comments