@duskmoon-dev/el-markdown 0.1.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 +236 -0
- package/dist/cjs/index.js +27795 -0
- package/dist/cjs/index.js.map +272 -0
- package/dist/esm/index.js +27783 -0
- package/dist/esm/index.js.map +272 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types/el-dm-markdown.d.ts +176 -0
- package/dist/types/el-dm-markdown.d.ts.map +1 -0
- package/dist/types/index.d.ts +20 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/themes/atom-one-dark.d.ts +6 -0
- package/dist/types/themes/atom-one-dark.d.ts.map +1 -0
- package/dist/types/themes/atom-one-light.d.ts +6 -0
- package/dist/types/themes/atom-one-light.d.ts.map +1 -0
- package/dist/types/themes/github.d.ts +6 -0
- package/dist/types/themes/github.d.ts.map +1 -0
- package/dist/types/themes/index.d.ts +7 -0
- package/dist/types/themes/index.d.ts.map +1 -0
- package/package.json +60 -0
package/README.md
ADDED
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
# @duskmoon-dev/el-markdown
|
|
2
|
+
|
|
3
|
+
A markdown renderer component using remark/rehype with syntax highlighting, mermaid diagram support, and streaming mode for LLM output.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
bun add @duskmoon-dev/el-markdown
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
For mermaid diagram support (optional):
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
bun add mermaid
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
### Inline Content
|
|
20
|
+
|
|
21
|
+
````html
|
|
22
|
+
<script type="module">
|
|
23
|
+
import { register } from '@duskmoon-dev/el-markdown';
|
|
24
|
+
register();
|
|
25
|
+
</script>
|
|
26
|
+
|
|
27
|
+
<el-dm-markdown>
|
|
28
|
+
# Hello World This is **markdown** content with: - Lists - Code blocks - And more! ```javascript
|
|
29
|
+
console.log('Syntax highlighting!');</el-dm-markdown
|
|
30
|
+
>
|
|
31
|
+
````
|
|
32
|
+
|
|
33
|
+
</el-dm-markdown>
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### From URL
|
|
37
|
+
|
|
38
|
+
```html
|
|
39
|
+
<el-dm-markdown src="/docs/readme.md"></el-dm-markdown>
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### With Mermaid Diagrams
|
|
43
|
+
|
|
44
|
+
````html
|
|
45
|
+
<el-dm-markdown>
|
|
46
|
+
# Flowchart Example ```mermaid graph TD A[Start] --> B{Is it?} B -->|Yes| C[OK] B -->|No|
|
|
47
|
+
D[End]</el-dm-markdown
|
|
48
|
+
>
|
|
49
|
+
````
|
|
50
|
+
|
|
51
|
+
</el-dm-markdown>
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Features
|
|
55
|
+
|
|
56
|
+
- **GitHub Flavored Markdown**: Tables, task lists, strikethrough, autolinks
|
|
57
|
+
- **Syntax Highlighting**: Powered by highlight.js via rehype-highlight
|
|
58
|
+
- **Mermaid Diagrams**: Optional support for flowcharts, sequence diagrams, etc.
|
|
59
|
+
- **Multiple Themes**: GitHub, Atom One Dark, Atom One Light
|
|
60
|
+
- **Auto Theme**: Respects `prefers-color-scheme` media query
|
|
61
|
+
- **Indentation Removal**: Automatically removes common indentation from inline content
|
|
62
|
+
- **Streaming Mode**: Real-time rendering for LLM output with automatic syntax error recovery
|
|
63
|
+
|
|
64
|
+
## Themes
|
|
65
|
+
|
|
66
|
+
| Theme | Description |
|
|
67
|
+
| ---------------- | ----------------------------------- |
|
|
68
|
+
| `auto` | Follows system preference (default) |
|
|
69
|
+
| `github` | GitHub-style light theme |
|
|
70
|
+
| `atom-one-dark` | Atom One Dark theme |
|
|
71
|
+
| `atom-one-light` | Atom One Light theme |
|
|
72
|
+
|
|
73
|
+
````html
|
|
74
|
+
<el-dm-markdown theme="atom-one-dark"> ```js const dark = true;</el-dm-markdown>
|
|
75
|
+
````
|
|
76
|
+
|
|
77
|
+
</el-dm-markdown>
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Attributes
|
|
81
|
+
|
|
82
|
+
| Attribute | Type | Default | Description |
|
|
83
|
+
| ------------ | ------- | ------- | ----------------------------------- |
|
|
84
|
+
| `src` | string | | URL to fetch markdown from |
|
|
85
|
+
| `theme` | string | `auto` | Code syntax highlighting theme |
|
|
86
|
+
| `debug` | boolean | `false` | Enable debug logging |
|
|
87
|
+
| `no-mermaid` | boolean | `false` | Disable mermaid rendering |
|
|
88
|
+
| `streaming` | boolean | `false` | Read-only, reflects streaming state |
|
|
89
|
+
|
|
90
|
+
## Properties
|
|
91
|
+
|
|
92
|
+
| Property | Type | Description |
|
|
93
|
+
| --------- | ------ | --------------------------------- |
|
|
94
|
+
| `content` | string | Get/set markdown content directly |
|
|
95
|
+
|
|
96
|
+
## Methods
|
|
97
|
+
|
|
98
|
+
| Method | Description |
|
|
99
|
+
| ---------------------- | ----------------------------------------------- |
|
|
100
|
+
| `startStreaming()` | Begin streaming mode, clear buffer, show cursor |
|
|
101
|
+
| `appendContent(chunk)` | Append a chunk of content during streaming |
|
|
102
|
+
| `setContent(content)` | Replace content (works in streaming & normal) |
|
|
103
|
+
| `endStreaming()` | End streaming, perform final clean render |
|
|
104
|
+
|
|
105
|
+
## CSS Parts
|
|
106
|
+
|
|
107
|
+
| Part | Description |
|
|
108
|
+
| ----------- | ----------------------------- |
|
|
109
|
+
| `container` | The outer container |
|
|
110
|
+
| `content` | The rendered markdown content |
|
|
111
|
+
|
|
112
|
+
## Events
|
|
113
|
+
|
|
114
|
+
| Event | Detail | Description |
|
|
115
|
+
| ----------------- | ------------------------------------ | -------------------------------- |
|
|
116
|
+
| `dm-rendered` | `{ html: string }` | Fired after markdown is rendered |
|
|
117
|
+
| `dm-error` | `{ error: string }` | Fired when an error occurs |
|
|
118
|
+
| `dm-stream-chunk` | `{ content: string, chunk: string }` | Fired when a chunk is appended |
|
|
119
|
+
| `dm-stream-end` | `{ content: string }` | Fired when streaming ends |
|
|
120
|
+
|
|
121
|
+
## CSS Custom Properties
|
|
122
|
+
|
|
123
|
+
| Property | Description |
|
|
124
|
+
| -------------------------------- | ----------------------- |
|
|
125
|
+
| `--dm-markdown-font-family` | Font family for content |
|
|
126
|
+
| `--dm-markdown-code-font-family` | Font family for code |
|
|
127
|
+
| `--dm-markdown-line-height` | Line height |
|
|
128
|
+
|
|
129
|
+
## Supported Markdown Features
|
|
130
|
+
|
|
131
|
+
- Headings (h1-h6)
|
|
132
|
+
- Paragraphs
|
|
133
|
+
- Bold, italic, strikethrough
|
|
134
|
+
- Links and images
|
|
135
|
+
- Ordered and unordered lists
|
|
136
|
+
- Task lists (GFM)
|
|
137
|
+
- Blockquotes
|
|
138
|
+
- Code (inline and blocks)
|
|
139
|
+
- Syntax highlighting
|
|
140
|
+
- Tables (GFM)
|
|
141
|
+
- Horizontal rules
|
|
142
|
+
- Mermaid diagrams (optional)
|
|
143
|
+
|
|
144
|
+
## Examples
|
|
145
|
+
|
|
146
|
+
### Task List
|
|
147
|
+
|
|
148
|
+
```html
|
|
149
|
+
<el-dm-markdown> ## Todo - [x] Complete task - [ ] Pending task - [ ] Another task </el-dm-markdown>
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
### Table
|
|
153
|
+
|
|
154
|
+
```html
|
|
155
|
+
<el-dm-markdown>
|
|
156
|
+
| Feature | Status | |---------|--------| | Tables | Supported | | Strikethrough | ~~Yes~~ |
|
|
157
|
+
</el-dm-markdown>
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
### Loading Remote Content
|
|
161
|
+
|
|
162
|
+
```html
|
|
163
|
+
<el-dm-markdown src="https://raw.githubusercontent.com/user/repo/main/README.md"></el-dm-markdown>
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
## Streaming Mode
|
|
167
|
+
|
|
168
|
+
Streaming mode is designed for rendering LLM output in real-time. It automatically handles incomplete markdown syntax during streaming and shows a blinking cursor.
|
|
169
|
+
|
|
170
|
+
### Basic Streaming
|
|
171
|
+
|
|
172
|
+
```typescript
|
|
173
|
+
const md = document.querySelector('el-dm-markdown');
|
|
174
|
+
|
|
175
|
+
// Start streaming mode
|
|
176
|
+
md.startStreaming();
|
|
177
|
+
|
|
178
|
+
// Append chunks as they arrive from LLM
|
|
179
|
+
for await (const chunk of llmStream) {
|
|
180
|
+
md.appendContent(chunk);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// End streaming (performs final clean render)
|
|
184
|
+
md.endStreaming();
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
### Using Content Property
|
|
188
|
+
|
|
189
|
+
```typescript
|
|
190
|
+
const md = document.querySelector('el-dm-markdown');
|
|
191
|
+
|
|
192
|
+
md.streaming = true; // Or call startStreaming()
|
|
193
|
+
let content = '';
|
|
194
|
+
|
|
195
|
+
for await (const chunk of llmStream) {
|
|
196
|
+
content += chunk;
|
|
197
|
+
md.content = content;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
md.streaming = false; // Or call endStreaming()
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
### Listening to Stream Events
|
|
204
|
+
|
|
205
|
+
```typescript
|
|
206
|
+
const md = document.querySelector('el-dm-markdown');
|
|
207
|
+
|
|
208
|
+
md.addEventListener('dm-stream-chunk', (e) => {
|
|
209
|
+
console.log('Received chunk:', e.detail.chunk);
|
|
210
|
+
console.log('Total content:', e.detail.content);
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
md.addEventListener('dm-stream-end', (e) => {
|
|
214
|
+
console.log('Streaming complete:', e.detail.content);
|
|
215
|
+
});
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
### Syntax Auto-Recovery
|
|
219
|
+
|
|
220
|
+
During streaming, incomplete markdown syntax is automatically fixed:
|
|
221
|
+
|
|
222
|
+
| Incomplete Pattern | Auto-Fix Action |
|
|
223
|
+
| ------------------ | -------------------- |
|
|
224
|
+
| ` ``` ` unclosed | Closes code block |
|
|
225
|
+
| `` ` `` unclosed | Closes inline code |
|
|
226
|
+
| `**text` unclosed | Closes bold |
|
|
227
|
+
| `*text` unclosed | Closes italic |
|
|
228
|
+
| `~~text` unclosed | Closes strikethrough |
|
|
229
|
+
| `[text](url` | Closes link |
|
|
230
|
+
| `![alt](url` | Closes image |
|
|
231
|
+
|
|
232
|
+
This ensures the markdown renders correctly even with partial content.
|
|
233
|
+
|
|
234
|
+
## License
|
|
235
|
+
|
|
236
|
+
MIT
|