@@ -19,15 +19,13 @@ and elegant virtual syntax highlighting using [Prism][github-prism].
19
19
* [ Install] ( #install )
20
20
* [ Use] ( #use )
21
21
* [ API] ( #api )
22
- * [ ` refractor.highlight(value, language) ` ] ( #refractorhighlightvalue-language )
23
- * [ ` refractor.register(syntax) ` ] ( #refractorregistersyntax )
24
- * [ ` refractor.alias(name[, alias]) ` ] ( #refractoraliasname-alias )
25
- * [ ` refractor.registered(aliasOrlanguage) ` ] ( #refractorregisteredaliasorlanguage )
26
- * [ ` refractor.listLanguages() ` ] ( #refractorlistlanguages )
22
+ * [ ` refractor ` ] ( #refractor-1 )
23
+ * [ ` Grammar ` ] ( #grammar )
24
+ * [ ` Root ` ] ( #root )
25
+ * [ ` Syntax ` ] ( #syntax )
27
26
* [ Examples] ( #examples )
28
27
* [ Example: serializing hast as html] ( #example-serializing-hast-as-html )
29
28
* [ Example: turning hast into react nodes] ( #example-turning-hast-into-react-nodes )
30
- * [ Types] ( #types )
31
29
* [ Data] ( #data )
32
30
* [ CSS] ( #css )
33
31
* [ Compatibility] ( #compatibility )
@@ -149,10 +147,17 @@ Yields:
149
147
150
148
## API
151
149
152
- This package exports the identifier ` refractor ` .
150
+ This package exports the identifier [ ` refractor ` ] [ api-refractor ] .
151
+ It also exports the [ TypeScript] [ ] types
152
+ [ ` Grammar ` ] [ api-grammar ] ,
153
+ [ ` Root ` ] [ api-root ] ,
154
+ and
155
+ [ ` Syntax ` ] [ api-syntax ] .
153
156
There is no default export.
154
157
155
- ### ` refractor.highlight(value, language) `
158
+ ### ` refractor `
159
+
160
+ #### ` refractor.highlight(value, language) `
156
161
157
162
Highlight ` value ` (code) as ` language ` (programming language).
158
163
@@ -172,8 +177,8 @@ Node representing highlighted code ([`Root`][github-hast-root]).
172
177
###### Example
173
178
174
179
``` js
175
- import {refractor } from ' refractor/lib/core.js'
176
180
import css from ' refractor/lang/css.js'
181
+ import {refractor } from ' refractor/lib/core.js'
177
182
178
183
refractor .register (css)
179
184
console .log (refractor .highlight (' em { color: red }' , ' css' ))
@@ -194,7 +199,7 @@ Yields:
194
199
}
195
200
```
196
201
197
- ### ` refractor.register(syntax) `
202
+ #### ` refractor.register(syntax) `
198
203
199
204
Register a syntax.
200
205
@@ -208,8 +213,8 @@ Register a syntax.
208
213
###### Example
209
214
210
215
``` js
211
- import {refractor } from ' refractor/lib/core.js'
212
216
import markdown from ' refractor/lang/markdown.js'
217
+ import {refractor } from ' refractor/lib/core.js'
213
218
214
219
refractor .register (markdown)
215
220
@@ -227,7 +232,7 @@ Yields:
227
232
}
228
233
```
229
234
230
- ### ` refractor.alias(name[, alias]) `
235
+ #### ` refractor.alias(name[, alias]) `
231
236
232
237
Register aliases for already registered languages.
233
238
@@ -250,8 +255,8 @@ Register aliases for already registered languages.
250
255
###### Example
251
256
252
257
``` js
253
- import {refractor } from ' refractor/lib/core.js'
254
258
import markdown from ' refractor/lang/markdown.js'
259
+ import {refractor } from ' refractor/lib/core.js'
255
260
256
261
refractor .register (markdown)
257
262
@@ -263,7 +268,7 @@ refractor.highlight('*Emphasis*', 'mdown')
263
268
// ^ Works!
264
269
```
265
270
266
- ### ` refractor.registered(aliasOrlanguage) `
271
+ #### ` refractor.registered(aliasOrlanguage) `
267
272
268
273
Check whether an ` alias ` or ` language ` is registered.
269
274
@@ -275,8 +280,8 @@ Check whether an `alias` or `language` is registered.
275
280
###### Example
276
281
277
282
``` js
278
- import {refractor } from ' refractor/lib/core.js'
279
283
import markdown from ' refractor/lang/markdown.js'
284
+ import {refractor } from ' refractor/lib/core.js'
280
285
281
286
console .log (refractor .registered (' markdown' )) // => false
282
287
@@ -285,7 +290,7 @@ refractor.register(markdown)
285
290
console .log (refractor .registered (' markdown' )) // => true
286
291
```
287
292
288
- ### ` refractor.listLanguages() `
293
+ #### ` refractor.listLanguages() `
289
294
290
295
List all registered languages (names and aliases).
291
296
@@ -296,8 +301,8 @@ List all registered languages (names and aliases).
296
301
###### Example
297
302
298
303
``` js
299
- import {refractor } from ' refractor/lib/core.js'
300
304
import markdown from ' refractor/lang/markdown.js'
305
+ import {refractor } from ' refractor/lib/core.js'
301
306
302
307
console .log (refractor .listLanguages ()) // => []
303
308
@@ -318,6 +323,39 @@ Yields:
318
323
]
319
324
```
320
325
326
+ ### ` Grammar `
327
+
328
+ Grammar.
329
+
330
+ ###### Type
331
+
332
+ ``` ts
333
+ export type {Grammar } from ' prismjs'
334
+ ```
335
+
336
+ ### ` Root `
337
+
338
+ Tree representing HTML.
339
+
340
+ ###### Type
341
+
342
+ ``` ts
343
+ export type {Root } from ' hast'
344
+ ```
345
+
346
+ ### ` Syntax `
347
+
348
+ Refractor syntax function.
349
+
350
+ ###### Type
351
+
352
+ ``` ts
353
+ export type Syntax = ((prism : Refractor ) => undefined | void ) & {
354
+ aliases? : Array <string > | undefined
355
+ displayName: string
356
+ }
357
+ ` ` `
358
+
321
359
## Examples
322
360
323
361
### Example: serializing hast as html
@@ -326,8 +364,8 @@ hast trees as returned by refractor can be serialized with
326
364
[ ` hast -util -to -html ` ][github-hast-util-to-html]:
327
365
328
366
` ` ` js
329
- import {refractor } from ' refractor'
330
367
import {toHtml } from ' hast-util-to-html'
368
+ import {refractor } from ' refractor'
331
369
332
370
const tree = refractor .highlight (' "use strict";' , ' js' )
333
371
@@ -370,14 +408,6 @@ Yields:
370
408
}
371
409
```
372
410
373
- ## Types
374
-
375
- This package is fully typed with [ TypeScript] [ ] .
376
- It exports the additional types
377
- ` Grammar ` ,
378
- ` Root ` ,
379
- and ` Syntax ` .
380
-
381
411
<!-- Old name of the following section:-->
382
412
383
413
<a name =" syntaxes " ></a >
@@ -765,6 +795,14 @@ See [How to Contribute to Open Source][opensource-guide].
765
795
766
796
<!-- Definitions -->
767
797
798
+ [ api-grammar ] : #grammar
799
+
800
+ [ api-refractor ] : #refractor
801
+
802
+ [ api-root ] : #root
803
+
804
+ [ api-syntax ] : #syntax
805
+
768
806
[ badge-build-image ] : https://github.com/wooorm/refractor/workflows/main/badge.svg
769
807
770
808
[ badge-build-url ] : https://github.com/wooorm/refractor/actions
0 commit comments