@@ -19,15 +19,13 @@ and elegant virtual syntax highlighting using [Prism][github-prism].
1919* [ Install] ( #install )
2020* [ Use] ( #use )
2121* [ 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 )
2726* [ Examples] ( #examples )
2827 * [ Example: serializing hast as html] ( #example-serializing-hast-as-html )
2928 * [ Example: turning hast into react nodes] ( #example-turning-hast-into-react-nodes )
30- * [ Types] ( #types )
3129* [ Data] ( #data )
3230* [ CSS] ( #css )
3331* [ Compatibility] ( #compatibility )
@@ -149,10 +147,17 @@ Yields:
149147
150148## API
151149
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 ] .
153156There is no default export.
154157
155- ### ` refractor.highlight(value, language) `
158+ ### ` refractor `
159+
160+ #### ` refractor.highlight(value, language) `
156161
157162Highlight ` value ` (code) as ` language ` (programming language).
158163
@@ -172,8 +177,8 @@ Node representing highlighted code ([`Root`][github-hast-root]).
172177###### Example
173178
174179``` js
175- import {refractor } from ' refractor/lib/core.js'
176180import css from ' refractor/lang/css.js'
181+ import {refractor } from ' refractor/lib/core.js'
177182
178183refractor .register (css)
179184console .log (refractor .highlight (' em { color: red }' , ' css' ))
@@ -194,7 +199,7 @@ Yields:
194199}
195200```
196201
197- ### ` refractor.register(syntax) `
202+ #### ` refractor.register(syntax) `
198203
199204Register a syntax.
200205
@@ -208,8 +213,8 @@ Register a syntax.
208213###### Example
209214
210215``` js
211- import {refractor } from ' refractor/lib/core.js'
212216import markdown from ' refractor/lang/markdown.js'
217+ import {refractor } from ' refractor/lib/core.js'
213218
214219refractor .register (markdown)
215220
@@ -227,7 +232,7 @@ Yields:
227232}
228233```
229234
230- ### ` refractor.alias(name[, alias]) `
235+ #### ` refractor.alias(name[, alias]) `
231236
232237Register aliases for already registered languages.
233238
@@ -250,8 +255,8 @@ Register aliases for already registered languages.
250255###### Example
251256
252257``` js
253- import {refractor } from ' refractor/lib/core.js'
254258import markdown from ' refractor/lang/markdown.js'
259+ import {refractor } from ' refractor/lib/core.js'
255260
256261refractor .register (markdown)
257262
@@ -263,7 +268,7 @@ refractor.highlight('*Emphasis*', 'mdown')
263268// ^ Works!
264269```
265270
266- ### ` refractor.registered(aliasOrlanguage) `
271+ #### ` refractor.registered(aliasOrlanguage) `
267272
268273Check whether an ` alias ` or ` language ` is registered.
269274
@@ -275,8 +280,8 @@ Check whether an `alias` or `language` is registered.
275280###### Example
276281
277282``` js
278- import {refractor } from ' refractor/lib/core.js'
279283import markdown from ' refractor/lang/markdown.js'
284+ import {refractor } from ' refractor/lib/core.js'
280285
281286console .log (refractor .registered (' markdown' )) // => false
282287
@@ -285,7 +290,7 @@ refractor.register(markdown)
285290console .log (refractor .registered (' markdown' )) // => true
286291```
287292
288- ### ` refractor.listLanguages() `
293+ #### ` refractor.listLanguages() `
289294
290295List all registered languages (names and aliases).
291296
@@ -296,8 +301,8 @@ List all registered languages (names and aliases).
296301###### Example
297302
298303``` js
299- import {refractor } from ' refractor/lib/core.js'
300304import markdown from ' refractor/lang/markdown.js'
305+ import {refractor } from ' refractor/lib/core.js'
301306
302307console .log (refractor .listLanguages ()) // => []
303308
@@ -318,6 +323,39 @@ Yields:
318323]
319324```
320325
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+
321359## Examples
322360
323361### Example: serializing hast as html
@@ -326,8 +364,8 @@ hast trees as returned by refractor can be serialized with
326364[ ` hast -util -to -html ` ][github-hast-util-to-html]:
327365
328366` ` ` js
329- import {refractor } from ' refractor'
330367import {toHtml } from ' hast-util-to-html'
368+ import {refractor } from ' refractor'
331369
332370const tree = refractor .highlight (' "use strict";' , ' js' )
333371
@@ -370,14 +408,6 @@ Yields:
370408}
371409```
372410
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-
381411<!-- Old name of the following section:-->
382412
383413<a name =" syntaxes " ></a >
@@ -765,6 +795,14 @@ See [How to Contribute to Open Source][opensource-guide].
765795
766796<!-- Definitions -->
767797
798+ [ api-grammar ] : #grammar
799+
800+ [ api-refractor ] : #refractor
801+
802+ [ api-root ] : #root
803+
804+ [ api-syntax ] : #syntax
805+
768806[ badge-build-image ] : https://github.com/wooorm/refractor/workflows/main/badge.svg
769807
770808[ badge-build-url ] : https://github.com/wooorm/refractor/actions
0 commit comments