react-codemirror-runmode 1.0.4 → 2.0.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/.eslintignore ADDED
@@ -0,0 +1 @@
1
+ dist
package/.eslintrc.yml ADDED
@@ -0,0 +1,19 @@
1
+ root: true
2
+ extends:
3
+ - plugin:@typescript-eslint/eslint-recommended
4
+ - plugin:@typescript-eslint/recommended
5
+ - prettier
6
+ parser: '@typescript-eslint/parser'
7
+ parserOptions:
8
+ ecmaVersion: 2022
9
+ sourceType: 'module'
10
+ rules:
11
+ no-useless-escape: 0
12
+ '@typescript-eslint/no-explicit-any': 0
13
+ '@typescript-eslint/no-unused-vars':
14
+ - 2
15
+ - argsIgnorePattern: ^_
16
+ varsIgnorePattern: ^_
17
+ '@typescript-eslint/ban-ts-comment': 0
18
+ '@typescript-eslint/no-this-alias': 0
19
+ '@typescript-eslint/no-var-requires': 0
@@ -0,0 +1,21 @@
1
+ name: CI
2
+ on:
3
+ push:
4
+ pull_request:
5
+ branches: [main]
6
+ jobs:
7
+ test:
8
+ name: Test
9
+ runs-on: ubuntu-latest
10
+ steps:
11
+ - uses: actions/checkout@v4
12
+ - uses: actions/setup-node@v4
13
+ with:
14
+ node-version: '20'
15
+ - run: npm install
16
+ - run: npm run format:check
17
+ - run: npm run lint
18
+ - run: npm run test
19
+ - run: npm run build
20
+ - name: Check ESM module resolution
21
+ run: npx @arethetypeswrong/cli --ignore-rules cjs-resolves-to-esm --pack
@@ -0,0 +1,137 @@
1
+ # Logs
2
+ logs
3
+ *.log
4
+ npm-debug.log*
5
+ yarn-debug.log*
6
+ yarn-error.log*
7
+ lerna-debug.log*
8
+ .pnpm-debug.log*
9
+
10
+ # Diagnostic reports (https://nodejs.org/api/report.html)
11
+ report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
12
+
13
+ # Runtime data
14
+ pids
15
+ *.pid
16
+ *.seed
17
+ *.pid.lock
18
+
19
+ # Directory for instrumented libs generated by jscoverage/JSCover
20
+ lib-cov
21
+
22
+ # Coverage directory used by tools like istanbul
23
+ coverage
24
+ *.lcov
25
+
26
+ # nyc test coverage
27
+ .nyc_output
28
+
29
+ # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
30
+ .grunt
31
+
32
+ # Bower dependency directory (https://bower.io/)
33
+ bower_components
34
+
35
+ # node-waf configuration
36
+ .lock-wscript
37
+
38
+ # Compiled binary addons (https://nodejs.org/api/addons.html)
39
+ build/Release
40
+
41
+ # Dependency directories
42
+ node_modules/
43
+ jspm_packages/
44
+
45
+ # Snowpack dependency directory (https://snowpack.dev/)
46
+ web_modules/
47
+
48
+ # TypeScript cache
49
+ *.tsbuildinfo
50
+
51
+ # Optional npm cache directory
52
+ .npm
53
+
54
+ # Optional eslint cache
55
+ .eslintcache
56
+
57
+ # Optional stylelint cache
58
+ .stylelintcache
59
+
60
+ # Microbundle cache
61
+ .rpt2_cache/
62
+ .rts2_cache_cjs/
63
+ .rts2_cache_es/
64
+ .rts2_cache_umd/
65
+
66
+ # Optional REPL history
67
+ .node_repl_history
68
+
69
+ # Output of 'npm pack'
70
+ *.tgz
71
+
72
+ # Yarn Integrity file
73
+ .yarn-integrity
74
+
75
+ # dotenv environment variable files
76
+ .env
77
+ .env.development.local
78
+ .env.test.local
79
+ .env.production.local
80
+ .env.local
81
+
82
+ # parcel-bundler cache (https://parceljs.org/)
83
+ .cache
84
+ .parcel-cache
85
+
86
+ # Next.js build output
87
+ .next
88
+ out
89
+
90
+ # Nuxt.js build / generate output
91
+ .nuxt
92
+ dist
93
+
94
+ # Gatsby files
95
+ .cache/
96
+ # Comment in the public line in if your project uses Gatsby and not Next.js
97
+ # https://nextjs.org/blog/next-9-1#public-directory-support
98
+ # public
99
+
100
+ # vuepress build output
101
+ .vuepress/dist
102
+
103
+ # vuepress v2.x temp and cache directory
104
+ .temp
105
+ .cache
106
+
107
+ # Docusaurus cache and generated files
108
+ .docusaurus
109
+
110
+ # Serverless directories
111
+ .serverless/
112
+
113
+ # FuseBox cache
114
+ .fusebox/
115
+
116
+ # DynamoDB Local files
117
+ .dynamodb/
118
+
119
+ # TernJS port file
120
+ .tern-port
121
+
122
+ # Stores VSCode versions used for testing VSCode extensions
123
+ .vscode-test
124
+
125
+ # yarn v2
126
+ .yarn/cache
127
+ .yarn/unplugged
128
+ .yarn/build-state.yml
129
+ .yarn/install-state.gz
130
+ .pnp.*
131
+
132
+ # IDE
133
+ .idea/
134
+ .vscode/
135
+
136
+ # Lock files
137
+ pnpm-lock.yaml
@@ -0,0 +1,10 @@
1
+ {
2
+ "arrowParens": "avoid",
3
+ "singleQuote": true,
4
+ "bracketSpacing": true,
5
+ "endOfLine": "lf",
6
+ "semi": false,
7
+ "tabWidth": 2,
8
+ "trailingComma": "none",
9
+ "plugins": []
10
+ }
package/.travis.yml CHANGED
@@ -1,3 +1,6 @@
1
1
  language: node_js
2
2
  node_js:
3
- - 7
3
+ - 15
4
+ script:
5
+ - npm run build
6
+ - npm test
package/README.md CHANGED
@@ -1,61 +1,61 @@
1
- react-codemirror-runmode
2
- ========================
1
+ # react-codemirror-runmode
3
2
 
4
- [![build status](https://secure.travis-ci.org/craftzdog/react-codemirror-runmode.svg)](http://travis-ci.org/craftzdog/react-codemirror-runmode)
5
-
6
- Syntax highlighter for React, utilizing CodeMirror's parser
3
+ Syntax highlighter for React, using CodeMirror 6.
4
+ It automatically loads [the language metadata](https://github.com/codemirror/language-data) and dynamically loads language parser modules based on the specified language.
7
5
 
8
6
  ## Installation
9
7
 
10
8
  ```sh
11
- npm install --save react-codemirror-runmode codemirror
9
+ npm install --save react-codemirror-runmode
12
10
  ```
13
11
 
14
- You'll also need to provide the CodeMirror language definitions you want to use. We don't bundle these in order to not bloat the component with unused definitions.
15
-
16
12
  ## Usage
17
13
 
18
14
  ```javascript
19
- import CodeMirror from 'codemirror'
20
- import 'codemirror/addon/runmode/runmode'
21
- import 'codemirror/mode/meta'
22
- import 'codemirror/mode/javascript/javascript'
23
- import Highlighter from 'react-codemirror-runmode'
15
+ import { oneDarkHighlightStyle } from '@codemirror/theme-one-dark'
16
+ import { Highlighter } from 'react-codemirror-runmode'
24
17
  import React from 'react'
25
- import ReactDOM from 'react-dom'
26
-
27
- ReactDOM.render(
28
- <Highlighter
29
- codeMirror={CodeMirror}
30
- theme='solarized'
31
- value='/* Code to highlight */'
32
- language='javascript'
33
- />,
34
- document.getElementById('root')
18
+ import ReactDOM from 'react-dom/client'
19
+
20
+ const code = 'const x = 123'
21
+
22
+ ReactDOM.createRoot(document.getElementById('app')!).render(
23
+ <Highlighter lang="js" highlightStyle={oneDarkHighlightStyle}>
24
+ {code}
25
+ </Highlighter>
35
26
  )
36
27
  ```
37
28
 
38
- ## Styling
29
+ ## Theming
39
30
 
40
- Stylesheets are not automatically handled for you - but there is [a bunch of premade styles](https://codemirror.net/demo/theme.html) for CodeMirror which you can simply drop in and they'll "just work". You can either grab these from the source, of pull them in using a CSS loader - whatever works best for you. They're also available on [cdnjs](https://cdnjs.com/libraries/codemirror):
31
+ You can apply custom themes using CodeMirror's theme system. This component uses [`HighlightStyle`](https://codemirror.net/docs/ref#language.HighlightStyle) objects to apply styles, which you can customize or replace.
41
32
 
42
- ```html
43
- <link
44
- rel="stylesheet"
45
- href="//cdnjs.cloudflare.com/ajax/libs/codemirror/5.30.0/theme/solarized.min.css"
46
- />
47
- ```
33
+ ## Reference
34
+
35
+ ### `Highlighter`
36
+
37
+ Props:
38
+
39
+ - `lang`: `string` - The name of the language
40
+ - `highlightStyle`: [`HighlightStyle`](https://codemirror.net/docs/ref#language.HighlightStyle) - The highlight style
41
+ - `children`: `string` - The code to highlight
42
+
43
+ ### `highlightCode<Output>(languageName, input, highlightStyle, callback): Promise<Output[]>`
44
+
45
+ Parameters:
46
+
47
+ - `languageName`: `string` - The name of the language
48
+ - `input`: `string` - The code to highlight
49
+ - `highlightStyle`: [`HighlightStyle`](https://codemirror.net/docs/ref#language.HighlightStyle) - The highlight style
50
+ - `callback`: `(text: string, style: string | null, from: number, to: number) => Output)` - A callback function that converts the parsed tokens
51
+
52
+ ### `getCodeParser(languageName, defaultLanguage?): Promise<Parser | null>`
48
53
 
49
- ## Props
54
+ Parameters:
50
55
 
51
- | Name | Description |
52
- |------|-------------|
53
- | `className` | Class name for the outermost `pre` tag. Default: `''` |
54
- | `language` | Language to use for syntax highlighting this value. Must be registered prior to usage. |
55
- | `value` | The code snippet to syntax highlight |
56
- | `prefix` | Class name prefix for individual node. Default: `cm-` |
57
- | `inline` | Whether code should be displayed inline (no `<pre>` tag, sets `display: inline`) |
56
+ - `languageName: string` - The name of the language
57
+ - `defaultLanguage?: Language` - A fallback language (Optional)
58
58
 
59
59
  ## License
60
60
 
61
- MIT License. Developed by Takuya Matsuyama <hi@craftz.dog>
61
+ MIT License. Developed by Takuya Matsuyama <hi@craftz.dog>
package/Session.vim ADDED
@@ -0,0 +1,260 @@
1
+ let SessionLoad = 1
2
+ let s:so_save = &g:so | let s:siso_save = &g:siso | setg so=0 siso=0 | setl so=-1 siso=-1
3
+ let v:this_session=expand("<sfile>:p")
4
+ silent only
5
+ silent tabonly
6
+ cd ~/.ghq/github.com/craftzdog/react-codemirror-runmode
7
+ if expand('%') == '' && !&modified && line('$') <= 1 && getline(1) == ''
8
+ let s:wipebuf = bufnr('%')
9
+ endif
10
+ let s:shortmess_save = &shortmess
11
+ if &shortmess =~ 'A'
12
+ set shortmess=aoOA
13
+ else
14
+ set shortmess=aoO
15
+ endif
16
+ badd +12 package.json
17
+ badd +1 ~/.ghq/github.com/craftzdog/react-codemirror-runmode/src/highlight.ts
18
+ badd +32 ~/.ghq/github.com/craftzdog/react-codemirror-runmode/src/react-highlighter.tsx
19
+ badd +2 src/index.ts
20
+ badd +7 tsconfig.json
21
+ badd +1 tsconfig.build.json
22
+ badd +10 vite.config.ts
23
+ badd +37 README.md
24
+ badd +68 ~/.ghq/github.com/craftzdog/react-codemirror-runmode/test/index.spec.tsx
25
+ badd +144 ~/.ghq/github.com/craftzdog/react-codemirror-runmode/node_modules/@lezer/common/dist/index.d.ts
26
+ argglobal
27
+ %argdel
28
+ $argadd package.json
29
+ tabnew +setlocal\ bufhidden=wipe
30
+ tabrewind
31
+ edit package.json
32
+ let s:save_splitbelow = &splitbelow
33
+ let s:save_splitright = &splitright
34
+ set splitbelow splitright
35
+ wincmd _ | wincmd |
36
+ vsplit
37
+ wincmd _ | wincmd |
38
+ vsplit
39
+ wincmd _ | wincmd |
40
+ vsplit
41
+ wincmd _ | wincmd |
42
+ vsplit
43
+ 4wincmd h
44
+ wincmd w
45
+ wincmd w
46
+ wincmd _ | wincmd |
47
+ split
48
+ 1wincmd k
49
+ wincmd w
50
+ wincmd w
51
+ wincmd w
52
+ let &splitbelow = s:save_splitbelow
53
+ let &splitright = s:save_splitright
54
+ wincmd t
55
+ let s:save_winminheight = &winminheight
56
+ let s:save_winminwidth = &winminwidth
57
+ set winminheight=0
58
+ set winheight=1
59
+ set winminwidth=0
60
+ set winwidth=1
61
+ wincmd =
62
+ argglobal
63
+ setlocal fdm=indent
64
+ setlocal fde=0
65
+ setlocal fmr={{{,}}}
66
+ setlocal fdi=#
67
+ setlocal fdl=99
68
+ setlocal fml=1
69
+ setlocal fdn=20
70
+ setlocal fen
71
+ let s:l = 19 - ((18 * winheight(0) + 36) / 72)
72
+ if s:l < 1 | let s:l = 1 | endif
73
+ keepjumps exe s:l
74
+ normal! zt
75
+ keepjumps 19
76
+ normal! 013|
77
+ wincmd w
78
+ argglobal
79
+ if bufexists(fnamemodify("~/.ghq/github.com/craftzdog/react-codemirror-runmode/test/index.spec.tsx", ":p")) | buffer ~/.ghq/github.com/craftzdog/react-codemirror-runmode/test/index.spec.tsx | else | edit ~/.ghq/github.com/craftzdog/react-codemirror-runmode/test/index.spec.tsx | endif
80
+ if &buftype ==# 'terminal'
81
+ silent file ~/.ghq/github.com/craftzdog/react-codemirror-runmode/test/index.spec.tsx
82
+ endif
83
+ setlocal fdm=indent
84
+ setlocal fde=0
85
+ setlocal fmr={{{,}}}
86
+ setlocal fdi=#
87
+ setlocal fdl=99
88
+ setlocal fml=1
89
+ setlocal fdn=20
90
+ setlocal fen
91
+ 65
92
+ normal! zo
93
+ 66
94
+ normal! zo
95
+ 68
96
+ normal! zo
97
+ let s:l = 68 - ((64 * winheight(0) + 36) / 72)
98
+ if s:l < 1 | let s:l = 1 | endif
99
+ keepjumps exe s:l
100
+ normal! zt
101
+ keepjumps 68
102
+ normal! 08|
103
+ wincmd w
104
+ argglobal
105
+ if bufexists(fnamemodify("~/.ghq/github.com/craftzdog/react-codemirror-runmode/src/react-highlighter.tsx", ":p")) | buffer ~/.ghq/github.com/craftzdog/react-codemirror-runmode/src/react-highlighter.tsx | else | edit ~/.ghq/github.com/craftzdog/react-codemirror-runmode/src/react-highlighter.tsx | endif
106
+ if &buftype ==# 'terminal'
107
+ silent file ~/.ghq/github.com/craftzdog/react-codemirror-runmode/src/react-highlighter.tsx
108
+ endif
109
+ setlocal fdm=indent
110
+ setlocal fde=0
111
+ setlocal fmr={{{,}}}
112
+ setlocal fdi=#
113
+ setlocal fdl=99
114
+ setlocal fml=1
115
+ setlocal fdn=20
116
+ setlocal fen
117
+ 12
118
+ normal! zo
119
+ 18
120
+ normal! zo
121
+ 19
122
+ normal! zo
123
+ let s:l = 32 - ((31 * winheight(0) + 17) / 35)
124
+ if s:l < 1 | let s:l = 1 | endif
125
+ keepjumps exe s:l
126
+ normal! zt
127
+ keepjumps 32
128
+ normal! 035|
129
+ wincmd w
130
+ argglobal
131
+ if bufexists(fnamemodify("tsconfig.json", ":p")) | buffer tsconfig.json | else | edit tsconfig.json | endif
132
+ if &buftype ==# 'terminal'
133
+ silent file tsconfig.json
134
+ endif
135
+ balt ~/.ghq/github.com/craftzdog/react-codemirror-runmode/src/react-highlighter.tsx
136
+ setlocal fdm=indent
137
+ setlocal fde=0
138
+ setlocal fmr={{{,}}}
139
+ setlocal fdi=#
140
+ setlocal fdl=99
141
+ setlocal fml=1
142
+ setlocal fdn=20
143
+ setlocal fen
144
+ 2
145
+ normal! zo
146
+ let s:l = 7 - ((6 * winheight(0) + 18) / 36)
147
+ if s:l < 1 | let s:l = 1 | endif
148
+ keepjumps exe s:l
149
+ normal! zt
150
+ keepjumps 7
151
+ normal! 021|
152
+ wincmd w
153
+ argglobal
154
+ if bufexists(fnamemodify("~/.ghq/github.com/craftzdog/react-codemirror-runmode/src/highlight.ts", ":p")) | buffer ~/.ghq/github.com/craftzdog/react-codemirror-runmode/src/highlight.ts | else | edit ~/.ghq/github.com/craftzdog/react-codemirror-runmode/src/highlight.ts | endif
155
+ if &buftype ==# 'terminal'
156
+ silent file ~/.ghq/github.com/craftzdog/react-codemirror-runmode/src/highlight.ts
157
+ endif
158
+ balt package.json
159
+ setlocal fdm=indent
160
+ setlocal fde=0
161
+ setlocal fmr={{{,}}}
162
+ setlocal fdi=#
163
+ setlocal fdl=99
164
+ setlocal fml=1
165
+ setlocal fdn=20
166
+ setlocal fen
167
+ 14
168
+ normal! zo
169
+ 15
170
+ normal! zo
171
+ 39
172
+ normal! zo
173
+ 41
174
+ normal! zo
175
+ 45
176
+ normal! zo
177
+ 51
178
+ normal! zo
179
+ let s:l = 1 - ((0 * winheight(0) + 36) / 72)
180
+ if s:l < 1 | let s:l = 1 | endif
181
+ keepjumps exe s:l
182
+ normal! zt
183
+ keepjumps 1
184
+ normal! 010|
185
+ wincmd w
186
+ argglobal
187
+ if bufexists(fnamemodify("~/.ghq/github.com/craftzdog/react-codemirror-runmode/src/highlight.ts", ":p")) | buffer ~/.ghq/github.com/craftzdog/react-codemirror-runmode/src/highlight.ts | else | edit ~/.ghq/github.com/craftzdog/react-codemirror-runmode/src/highlight.ts | endif
188
+ if &buftype ==# 'terminal'
189
+ silent file ~/.ghq/github.com/craftzdog/react-codemirror-runmode/src/highlight.ts
190
+ endif
191
+ balt package.json
192
+ setlocal fdm=indent
193
+ setlocal fde=0
194
+ setlocal fmr={{{,}}}
195
+ setlocal fdi=#
196
+ setlocal fdl=99
197
+ setlocal fml=1
198
+ setlocal fdn=20
199
+ setlocal fen
200
+ 39
201
+ normal! zo
202
+ 41
203
+ normal! zo
204
+ 51
205
+ normal! zo
206
+ let s:l = 11 - ((10 * winheight(0) + 36) / 72)
207
+ if s:l < 1 | let s:l = 1 | endif
208
+ keepjumps exe s:l
209
+ normal! zt
210
+ keepjumps 11
211
+ normal! 0
212
+ wincmd w
213
+ 2wincmd w
214
+ wincmd =
215
+ tabnext
216
+ edit README.md
217
+ wincmd t
218
+ let s:save_winminheight = &winminheight
219
+ let s:save_winminwidth = &winminwidth
220
+ set winminheight=0
221
+ set winheight=1
222
+ set winminwidth=0
223
+ set winwidth=1
224
+ argglobal
225
+ balt ~/.ghq/github.com/craftzdog/react-codemirror-runmode/src/react-highlighter.tsx
226
+ setlocal fdm=indent
227
+ setlocal fde=0
228
+ setlocal fmr={{{,}}}
229
+ setlocal fdi=#
230
+ setlocal fdl=99
231
+ setlocal fml=1
232
+ setlocal fdn=20
233
+ setlocal fen
234
+ 28
235
+ normal! zo
236
+ let s:l = 28 - ((27 * winheight(0) + 36) / 72)
237
+ if s:l < 1 | let s:l = 1 | endif
238
+ keepjumps exe s:l
239
+ normal! zt
240
+ keepjumps 28
241
+ normal! 04|
242
+ tabnext 1
243
+ if exists('s:wipebuf') && len(win_findbuf(s:wipebuf)) == 0 && getbufvar(s:wipebuf, '&buftype') isnot# 'terminal'
244
+ silent exe 'bwipe ' . s:wipebuf
245
+ endif
246
+ unlet! s:wipebuf
247
+ set winheight=1 winwidth=20
248
+ let &shortmess = s:shortmess_save
249
+ let &winminheight = s:save_winminheight
250
+ let &winminwidth = s:save_winminwidth
251
+ let s:sx = expand("<sfile>:p:r")."x.vim"
252
+ if filereadable(s:sx)
253
+ exe "source " . fnameescape(s:sx)
254
+ endif
255
+ let &g:so = s:so_save | let &g:siso = s:siso_save
256
+ set hlsearch
257
+ nohlsearch
258
+ doautoall SessionLoadPost
259
+ unlet SessionLoad
260
+ " vim: set ft=vim :
@@ -0,0 +1,4 @@
1
+ import { Parser } from '@lezer/common';
2
+ import { HighlightStyle, Language } from '@codemirror/language';
3
+ export declare function getCodeParser(languageName: string, defaultLanguage?: Language): Promise<Parser | null>;
4
+ export declare function highlightCode<Output>(languageName: string, input: string, highlightStyle: HighlightStyle, callback: (text: string, style: string | null, from: number, to: number) => Output): Promise<Output[]>;
@@ -0,0 +1,36 @@
1
+ import { LanguageDescription } from '@codemirror/language';
2
+ import { highlightTree } from '@lezer/highlight';
3
+ import { languages } from '@codemirror/language-data';
4
+ export async function getCodeParser(languageName, defaultLanguage) {
5
+ if (languageName && languages) {
6
+ const found = LanguageDescription.matchLanguageName(languages, languageName, true);
7
+ if (found instanceof LanguageDescription) {
8
+ if (!found.support)
9
+ await found.load();
10
+ return found.support ? found.support.language.parser : null;
11
+ }
12
+ else if (found)
13
+ return found.parser;
14
+ }
15
+ return defaultLanguage ? defaultLanguage.parser : null;
16
+ }
17
+ export async function highlightCode(languageName, input, highlightStyle, callback) {
18
+ const parser = await getCodeParser(languageName);
19
+ if (parser) {
20
+ const tree = parser.parse(input);
21
+ const output = [];
22
+ let pos = 0;
23
+ highlightTree(tree, highlightStyle, (from, to, classes) => {
24
+ if (from > pos)
25
+ output.push(callback(input.slice(pos, from), null, pos, from));
26
+ output.push(callback(input.slice(from, to), classes, from, to));
27
+ pos = to;
28
+ });
29
+ pos != tree.length &&
30
+ output.push(callback(input.slice(pos, tree.length), null, pos, tree.length));
31
+ return output;
32
+ }
33
+ else {
34
+ return [callback(input, null, 0, input.length)];
35
+ }
36
+ }
@@ -0,0 +1,2 @@
1
+ export * from './highlight.js';
2
+ export * from './react-highlighter.js';
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export * from './highlight.js';
2
+ export * from './react-highlighter.js';
@@ -0,0 +1,8 @@
1
+ import React from 'react';
2
+ import type { HighlightStyle } from '@codemirror/language';
3
+ export type HighlighterProps = {
4
+ lang: string;
5
+ children: string;
6
+ highlightStyle: HighlightStyle;
7
+ };
8
+ export declare const Highlighter: React.NamedExoticComponent<HighlighterProps>;
@@ -0,0 +1,13 @@
1
+ import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { memo, useEffect, useState } from 'react';
3
+ import { highlightCode } from './highlight';
4
+ export const Highlighter = memo((props) => {
5
+ const { lang, children: code, highlightStyle } = props;
6
+ const [highlightedCode, setHighlightedCode] = useState(null);
7
+ useEffect(() => {
8
+ highlightCode(lang, code, highlightStyle, (text, style, from) => {
9
+ return (_jsx("span", { className: style || '', children: text }, from));
10
+ }).then(setHighlightedCode);
11
+ }, [lang, code, highlightStyle]);
12
+ return _jsx(_Fragment, { children: highlightedCode || code });
13
+ });