@semos-labs/glyph-markdown 0.2.6
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 +209 -0
- package/package.json +55 -0
package/README.md
ADDED
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
<h1 align="center">@semos-labs/glyph-markdown</h1>
|
|
2
|
+
|
|
3
|
+
<p align="center">
|
|
4
|
+
<strong>Markdown renderer for <a href="https://github.com/semos-labs/glyph">Glyph</a> terminal UIs</strong>
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
<p align="center">
|
|
8
|
+
<a href="https://www.npmjs.com/package/@semos-labs/glyph-markdown"><img src="https://img.shields.io/npm/v/@semos-labs/glyph-markdown?color=crimson&logo=npm" alt="npm version"></a>
|
|
9
|
+
<img src="https://img.shields.io/badge/React-18%2B-61dafb?logo=react&logoColor=white" alt="React 18+">
|
|
10
|
+
<img src="https://img.shields.io/badge/TypeScript-First-3178c6?logo=typescript&logoColor=white" alt="TypeScript">
|
|
11
|
+
<img src="https://img.shields.io/badge/License-MIT-blue" alt="MIT License">
|
|
12
|
+
</p>
|
|
13
|
+
|
|
14
|
+
<p align="center">
|
|
15
|
+
<a href="#features">Features</a> •
|
|
16
|
+
<a href="#quick-start">Quick Start</a> •
|
|
17
|
+
<a href="#api">API</a> •
|
|
18
|
+
<a href="#syntax-highlighting">Syntax Highlighting</a> •
|
|
19
|
+
<a href="#examples">Examples</a>
|
|
20
|
+
</p>
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
Render markdown as native Glyph components. Headings, lists, tables, code blocks with syntax highlighting, images, links, and inline formatting — all rendered with proper flexbox layout, focus navigation, and terminal colors.
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## Features
|
|
29
|
+
|
|
30
|
+
- **Full GFM support** — Headings, paragraphs, bold, italic, strikethrough, inline code, links, images, blockquotes, ordered/unordered/task lists, tables, thematic breaks.
|
|
31
|
+
- **Syntax highlighting** — Powered by [Shiki](https://shiki.style) with TextMate grammars. Loaded lazily — only initializes when code blocks are present.
|
|
32
|
+
- **Terminal-native colors** — Custom Shiki theme that outputs ANSI named colors, automatically inheriting your terminal's color scheme.
|
|
33
|
+
- **Images** — Rendered via Glyph's `<Image>` component with Kitty/iTerm2 protocol support.
|
|
34
|
+
- **Focusable links** — Links are rendered as Glyph `<Link>` components with keyboard navigation and browser opening.
|
|
35
|
+
- **Zero config** — Just pass a markdown string. Highlighting, image loading, and link handling work out of the box.
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## Quick Start
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
bun add @semos-labs/glyph-markdown
|
|
43
|
+
# or: npm install / pnpm add
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Requires `@semos-labs/glyph` and `react` as peer dependencies.
|
|
47
|
+
|
|
48
|
+
```tsx
|
|
49
|
+
import React from "react";
|
|
50
|
+
import { render, Box } from "@semos-labs/glyph";
|
|
51
|
+
import { Markdown } from "@semos-labs/glyph-markdown";
|
|
52
|
+
|
|
53
|
+
const source = `
|
|
54
|
+
# Hello World
|
|
55
|
+
|
|
56
|
+
A **bold** statement with \`inline code\` and a [link](https://github.com).
|
|
57
|
+
|
|
58
|
+
\`\`\`typescript
|
|
59
|
+
const greeting = "Hello from Glyph!";
|
|
60
|
+
console.log(greeting);
|
|
61
|
+
\`\`\`
|
|
62
|
+
`;
|
|
63
|
+
|
|
64
|
+
function App() {
|
|
65
|
+
return (
|
|
66
|
+
<Box style={{ padding: 1 }}>
|
|
67
|
+
<Markdown>{source}</Markdown>
|
|
68
|
+
</Box>
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
render(<App />);
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
## API
|
|
78
|
+
|
|
79
|
+
### `<Markdown>`
|
|
80
|
+
|
|
81
|
+
| Prop | Type | Default | Description |
|
|
82
|
+
|------|------|---------|-------------|
|
|
83
|
+
| `children` | `string` | — | Markdown source string |
|
|
84
|
+
| `style` | `Style` | — | Style applied to the outer container |
|
|
85
|
+
| `highlight` | `Highlighter \| false \| CreateHighlighterOptions` | `undefined` | Control syntax highlighting behavior |
|
|
86
|
+
|
|
87
|
+
#### `highlight` prop
|
|
88
|
+
|
|
89
|
+
| Value | Behavior |
|
|
90
|
+
|-------|----------|
|
|
91
|
+
| `undefined` | Auto-loads Shiki lazily when code blocks are present |
|
|
92
|
+
| `false` | Disable syntax highlighting entirely |
|
|
93
|
+
| `{ langs: [...], theme: "..." }` | Auto-load with custom Shiki options |
|
|
94
|
+
| `Highlighter` instance | Use a pre-created highlighter |
|
|
95
|
+
|
|
96
|
+
### `createHighlighter(options?)`
|
|
97
|
+
|
|
98
|
+
Create a Shiki highlighter instance manually. Useful when you need to share a single instance across multiple `<Markdown>` components.
|
|
99
|
+
|
|
100
|
+
```tsx
|
|
101
|
+
import { createHighlighter } from "@semos-labs/glyph-markdown";
|
|
102
|
+
|
|
103
|
+
const hl = await createHighlighter({ langs: ["tsx", "python", "bash"] });
|
|
104
|
+
|
|
105
|
+
<Markdown highlight={hl}>{source1}</Markdown>
|
|
106
|
+
<Markdown highlight={hl}>{source2}</Markdown>
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### `parseMarkdown(source)`
|
|
110
|
+
|
|
111
|
+
Parse a markdown string into an mdast AST. Useful for custom rendering or analysis.
|
|
112
|
+
|
|
113
|
+
```tsx
|
|
114
|
+
import { parseMarkdown } from "@semos-labs/glyph-markdown";
|
|
115
|
+
|
|
116
|
+
const ast = parseMarkdown("# Hello **world**");
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
---
|
|
120
|
+
|
|
121
|
+
## Syntax Highlighting
|
|
122
|
+
|
|
123
|
+
Highlighting is powered by Shiki and loaded lazily — the WASM grammar engine only initializes when your document contains code blocks. Code blocks render immediately as plain text, then re-render with highlighting once Shiki is ready.
|
|
124
|
+
|
|
125
|
+
The default theme uses terminal-native ANSI colors, so highlighting adapts to your terminal's color scheme. You can also use any built-in Shiki theme:
|
|
126
|
+
|
|
127
|
+
```tsx
|
|
128
|
+
<Markdown highlight={{ theme: "github-dark" }}>{source}</Markdown>
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### Supported languages
|
|
132
|
+
|
|
133
|
+
The default configuration loads a common set of languages: TypeScript, JavaScript, TSX, JSX, Python, Rust, Go, Bash, JSON, YAML, HTML, CSS, SQL, Markdown, and more. Pass a custom `langs` array to control exactly which grammars are loaded.
|
|
134
|
+
|
|
135
|
+
---
|
|
136
|
+
|
|
137
|
+
## Examples
|
|
138
|
+
|
|
139
|
+
### Minimal
|
|
140
|
+
|
|
141
|
+
```tsx
|
|
142
|
+
<Markdown>{`# Title\n\nSome **bold** text.`}</Markdown>
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### With ScrollView
|
|
146
|
+
|
|
147
|
+
```tsx
|
|
148
|
+
import { ScrollView, useInput } from "@semos-labs/glyph";
|
|
149
|
+
|
|
150
|
+
function App() {
|
|
151
|
+
const [offset, setOffset] = useState(0);
|
|
152
|
+
|
|
153
|
+
useInput((key) => {
|
|
154
|
+
if (key.name === "down") setOffset((o) => o + 1);
|
|
155
|
+
if (key.name === "up") setOffset((o) => Math.max(0, o - 1));
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
return (
|
|
159
|
+
<ScrollView scrollOffset={offset} onScroll={setOffset} style={{ flexGrow: 1 }}>
|
|
160
|
+
<Markdown>{longDocument}</Markdown>
|
|
161
|
+
</ScrollView>
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
### No highlighting
|
|
167
|
+
|
|
168
|
+
```tsx
|
|
169
|
+
<Markdown highlight={false}>{source}</Markdown>
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### Custom languages only
|
|
173
|
+
|
|
174
|
+
```tsx
|
|
175
|
+
<Markdown highlight={{ langs: ["typescript", "python"] }}>{source}</Markdown>
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
---
|
|
179
|
+
|
|
180
|
+
## Supported Markdown Features
|
|
181
|
+
|
|
182
|
+
| Feature | Syntax | Rendering |
|
|
183
|
+
|---------|--------|-----------|
|
|
184
|
+
| Headings | `# H1` through `###### H6` | Colored with number icons (❶ ❷ ❸ ...) |
|
|
185
|
+
| Bold | `**text**` | Bold terminal attribute |
|
|
186
|
+
| Italic | `*text*` | Italic terminal attribute |
|
|
187
|
+
| Strikethrough | `~~text~~` | ANSI strikethrough + dim |
|
|
188
|
+
| Inline code | `` `code` `` | Yellow highlighted |
|
|
189
|
+
| Code blocks | ```` ```lang ```` | Shiki syntax highlighting in bordered box |
|
|
190
|
+
| Links | `[text](url)` | Focusable, opens in browser on Enter/Space |
|
|
191
|
+
| Images | `` | Glyph Image component (Kitty/iTerm2) |
|
|
192
|
+
| Blockquotes | `> text` | Indented with `│` prefix |
|
|
193
|
+
| Unordered lists | `- item` | Bullet points (`•`) |
|
|
194
|
+
| Ordered lists | `1. item` | Numbered |
|
|
195
|
+
| Task lists | `- [x] done` | Checkbox icons (☑ ☐) |
|
|
196
|
+
| Tables | GFM tables | Glyph Table component with borders |
|
|
197
|
+
| Thematic breaks | `---` | Horizontal rule |
|
|
198
|
+
|
|
199
|
+
---
|
|
200
|
+
|
|
201
|
+
## License
|
|
202
|
+
|
|
203
|
+
MIT
|
|
204
|
+
|
|
205
|
+
---
|
|
206
|
+
|
|
207
|
+
<p align="center">
|
|
208
|
+
<sub>Part of the <a href="https://github.com/semos-labs/glyph">Glyph</a> ecosystem • React for the terminal</sub>
|
|
209
|
+
</p>
|
package/package.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@semos-labs/glyph-markdown",
|
|
3
|
+
"version": "0.2.6",
|
|
4
|
+
"description": "Markdown renderer for Glyph terminal UI framework with syntax highlighting",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "tsup",
|
|
20
|
+
"dev": "tsup --watch",
|
|
21
|
+
"typecheck": "tsc --noEmit"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"remark-gfm": "^4.0.1",
|
|
25
|
+
"remark-parse": "^11.0.0",
|
|
26
|
+
"shiki": "^3.0.0",
|
|
27
|
+
"unified": "^11.0.5"
|
|
28
|
+
},
|
|
29
|
+
"peerDependencies": {
|
|
30
|
+
"@semos-labs/glyph": ">=0.2.0",
|
|
31
|
+
"react": "^18.0.0 || ^19.0.0"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@semos-labs/glyph": "workspace:*",
|
|
35
|
+
"@types/mdast": "^4",
|
|
36
|
+
"@types/react": "^19",
|
|
37
|
+
"react": "^19.0.0",
|
|
38
|
+
"tsup": "^8",
|
|
39
|
+
"typescript": "^5.5"
|
|
40
|
+
},
|
|
41
|
+
"keywords": [
|
|
42
|
+
"glyph",
|
|
43
|
+
"terminal",
|
|
44
|
+
"markdown",
|
|
45
|
+
"tui",
|
|
46
|
+
"syntax-highlighting",
|
|
47
|
+
"react"
|
|
48
|
+
],
|
|
49
|
+
"license": "MIT",
|
|
50
|
+
"repository": {
|
|
51
|
+
"type": "git",
|
|
52
|
+
"url": "git+https://github.com/semos-labs/glyph.git",
|
|
53
|
+
"directory": "packages/glyph-markdown"
|
|
54
|
+
}
|
|
55
|
+
}
|