@ngrok/mantle-server-syntax-highlighter 1.0.1 → 1.0.2
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 +108 -0
- package/package.json +2 -2
package/README.md
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
# @ngrok/mantle-server-syntax-highlighter
|
|
2
|
+
|
|
3
|
+
Server-side syntax highlighting for [`@ngrok/mantle`](https://github.com/ngrok-oss/mantle), powered by [Shiki](https://shiki.style).
|
|
4
|
+
|
|
5
|
+
Use this package to highlight code in API routes, server actions, or any Node.js context where you need Mantle-compatible highlighted HTML without a browser or Vite.
|
|
6
|
+
|
|
7
|
+
## Requirements
|
|
8
|
+
|
|
9
|
+
- Node.js 24+
|
|
10
|
+
- `@ngrok/mantle` installed in the same project
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```sh
|
|
15
|
+
pnpm add -E @ngrok/mantle-server-syntax-highlighter
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Usage
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
import { createMantleServerSyntaxHighlighter } from "@ngrok/mantle-server-syntax-highlighter";
|
|
22
|
+
|
|
23
|
+
const highlighter = createMantleServerSyntaxHighlighter();
|
|
24
|
+
|
|
25
|
+
const result = await highlighter.highlight({
|
|
26
|
+
code: 'console.log("hello world")',
|
|
27
|
+
language: "typescript",
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
// result.html — highlighted HTML (inner content, no <code> wrapper)
|
|
31
|
+
// result.code — normalized source code
|
|
32
|
+
// result.language — resolved language
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## API
|
|
36
|
+
|
|
37
|
+
### `createMantleServerSyntaxHighlighter()`
|
|
38
|
+
|
|
39
|
+
Creates a reusable server highlighter instance. This is the recommended entry point — it internally caches the Shiki highlighter and recently highlighted results for performance.
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
const highlighter = createMantleServerSyntaxHighlighter();
|
|
43
|
+
const result = await highlighter.highlight(input);
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### `highlightWithMantleShiki(input)`
|
|
47
|
+
|
|
48
|
+
Lower-level function that highlights code with Mantle's shared Shiki engine and normalization defaults. Use this if you need direct access without the facade object.
|
|
49
|
+
|
|
50
|
+
```ts
|
|
51
|
+
import { highlightWithMantleShiki } from "@ngrok/mantle-server-syntax-highlighter";
|
|
52
|
+
|
|
53
|
+
const result = await highlightWithMantleShiki({
|
|
54
|
+
code: "const x = 1;",
|
|
55
|
+
language: "typescript",
|
|
56
|
+
showLineNumbers: true,
|
|
57
|
+
highlightLines: [1],
|
|
58
|
+
});
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### `getMantleShikiHighlighter()`
|
|
62
|
+
|
|
63
|
+
Returns Mantle's shared Shiki highlighter instance (created and cached on first call). Useful if you need the raw Shiki highlighter for advanced use cases.
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
import { getMantleShikiHighlighter } from "@ngrok/mantle-server-syntax-highlighter";
|
|
67
|
+
|
|
68
|
+
const shiki = await getMantleShikiHighlighter();
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Input Options
|
|
72
|
+
|
|
73
|
+
| Option | Type | Default | Description |
|
|
74
|
+
| ----------------- | -------------------------------- | ---------- | ------------------------------------------------------------ |
|
|
75
|
+
| `code` | `string` | (required) | Raw code string to highlight. |
|
|
76
|
+
| `language` | `string` | (required) | Language hint (e.g. `"typescript"`, `"go"`, `"python"`). |
|
|
77
|
+
| `indentation` | `"tabs" \| "spaces"` | auto | Indentation preference. Defaults to language-inferred value. |
|
|
78
|
+
| `showLineNumbers` | `boolean` | `false` | Whether to render line numbers into the returned HTML. |
|
|
79
|
+
| `highlightLines` | `(number \| [number, number])[]` | `[]` | Line numbers or ranges to highlight. |
|
|
80
|
+
| `lineNumberStart` | `number` | `1` | Start line number for rendered line numbers. |
|
|
81
|
+
|
|
82
|
+
### Result
|
|
83
|
+
|
|
84
|
+
| Field | Type | Description |
|
|
85
|
+
| ----------------- | -------------------------------- | ----------------------------------------------------- |
|
|
86
|
+
| `html` | `string` | Highlighted HTML (inner content of `<code>` element). |
|
|
87
|
+
| `code` | `string` | Normalized source code used as the highlight input. |
|
|
88
|
+
| `language` | `string` | Resolved language used for highlighting. |
|
|
89
|
+
| `showLineNumbers` | `boolean` | Whether the HTML includes line numbers. |
|
|
90
|
+
| `highlightLines` | `(number \| [number, number])[]` | Highlighted line ranges applied to the HTML. |
|
|
91
|
+
| `lineNumberStart` | `number` | Start line number used in the HTML. |
|
|
92
|
+
|
|
93
|
+
### Supported Languages
|
|
94
|
+
|
|
95
|
+
The following Shiki grammar IDs are preloaded:
|
|
96
|
+
|
|
97
|
+
`bash`, `csharp`, `css`, `go`, `html`, `java`, `javascript`, `json`, `jsx`, `python`, `ruby`, `rust`, `shell`, `tsx`, `typescript`, `xml`, `yaml`
|
|
98
|
+
|
|
99
|
+
These are exported as `mantleShikiLanguageGrammarIds` for programmatic access.
|
|
100
|
+
|
|
101
|
+
## TypeScript
|
|
102
|
+
|
|
103
|
+
Type declarations are included. No `@types/*` package is needed.
|
|
104
|
+
|
|
105
|
+
## Related Packages
|
|
106
|
+
|
|
107
|
+
- [`@ngrok/mantle`](https://github.com/ngrok-oss/mantle/tree/main/packages/mantle) — UI component library ([npm](https://www.npmjs.com/package/@ngrok/mantle))
|
|
108
|
+
- [`@ngrok/mantle-vite-plugins`](https://github.com/ngrok-oss/mantle/tree/main/packages/mantle-vite-plugins) — Vite + rehype plugins ([npm](https://www.npmjs.com/package/@ngrok/mantle-vite-plugins))
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ngrok/mantle-server-syntax-highlighter",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Server-side syntax highlighting for @ngrok/mantle, powered by Shiki.",
|
|
5
5
|
"homepage": "https://mantle.ngrok.com",
|
|
6
6
|
"license": "MIT",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"tsdown": "0.21.7",
|
|
32
32
|
"typescript": "6.0.2",
|
|
33
33
|
"@cfg/tsconfig": "1.0.0",
|
|
34
|
-
"@ngrok/mantle": "0.68.
|
|
34
|
+
"@ngrok/mantle": "0.68.1"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
37
|
"@ngrok/mantle": "*"
|