Skip to content

Commit 55f1e51

Browse files
committedMar 11, 2025
Refactor docs
1 parent 7f9d266 commit 55f1e51

File tree

2 files changed

+65
-37
lines changed

2 files changed

+65
-37
lines changed
 

‎readme.md

+61-33
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
[![Downloads][badge-downloads-image]][badge-downloads-url]
88
[![Size][badge-size-image]][badge-size-url]
99

10-
Lightweight, robust, elegant virtual syntax highlighting using
11-
[Prism][github-prism].
10+
Lightweight,
11+
robust,
12+
and elegant virtual syntax highlighting using [Prism][github-prism].
1213

1314
## Contents
1415

@@ -40,33 +41,46 @@ Lightweight, robust, elegant virtual syntax highlighting using
4041
This package wraps [Prism][github-prism] to output objects (ASTs) instead of a
4142
string of HTML.
4243

43-
Prism, through refractor, supports 270+ programming languages.
44+
Prism,
45+
through refractor,
46+
supports 290+ programming languages.
4447
Supporting all of them requires a lot of code.
4548
That’s why there are three entry points for refractor:
4649

4750
<!--count start-->
4851

49-
* `lib/core.js` — 0 languages
50-
* `lib/common.js` (default) — 36 languages
5152
* `lib/all.js` — 297 languages
53+
* `lib/common.js` (default) — 36 languages
54+
* `lib/core.js` — 0 languages
5255

5356
<!--count end-->
5457

55-
Bundled, minified, and gzipped, those are roughly 12.7 kB, 40 kB, and 211 kB.
58+
Bundled,
59+
minified,
60+
and gzipped,
61+
those are roughly 12.7 kB,
62+
40 kB,
63+
and 211 kB.
5664

5765
## When should I use this?
5866

5967
This package is useful when you want to perform syntax highlighting in a place
6068
where serialized HTML wouldn’t work or wouldn’t work well.
61-
For example, you can use refractor when you want to show code in a CLI by
62-
rendering to ANSI sequences, when you’re using virtual DOM frameworks (such as
63-
React or Preact) so that diffing can be performant, or when you’re working with
64-
ASTs (rehype).
65-
66-
A different package, [`lowlight`][github-lowlight], does the same as refractor
67-
but uses [`highlight.js`][github-highlightjs] instead.
68-
If you’re looking for a *really good* (but rather heavy) highlighter, try
69-
[`starry-night`][github-starry-night].
69+
For example,
70+
you can use refractor when you want to show code in a CLI by rendering to ANSI
71+
sequences,
72+
when you’re using virtual DOM frameworks
73+
(such as React or Preact)
74+
so that diffing can be performant,
75+
or when you’re working with ASTs
76+
(rehype).
77+
78+
A different package,
79+
[`lowlight`][github-lowlight],
80+
does the same as refractor but uses [`highlight.js`][github-highlightjs]
81+
instead.
82+
If you’re looking for a *really good* but rather heavy highlighter,
83+
try [`starry-night`][github-starry-night].
7084

7185
<!--Old name of the following section:-->
7286

@@ -80,7 +94,8 @@ You can play with refractor on the
8094
## Install
8195

8296
This package is [ESM only][github-gist-esm].
83-
In Node.js (version 14+), install with [npm][npmjs-install]:
97+
In Node.js (version 14+),
98+
install with [npm][npmjs-install]:
8499

85100
```sh
86101
npm install refractor
@@ -146,7 +161,9 @@ Highlight `value` (code) as `language` (programming language).
146161
* `value` (`string`)
147162
— code to highlight
148163
* `language` (`string` or `Grammar`)
149-
— programming language name, alias, or grammar.
164+
— programming language name,
165+
alias,
166+
or grammar
150167

151168
###### Returns
152169

@@ -184,8 +201,9 @@ Register a syntax.
184201
###### Parameters
185202

186203
* `syntax` (`Function`)
187-
— language function custom made for refractor, as in, the files in
188-
`refractor/lang/*.js`
204+
— language function custom made for refractor,
205+
as in,
206+
the files in `refractor/lang/*.js`
189207

190208
###### Example
191209

@@ -355,22 +373,27 @@ Yields:
355373
## Types
356374

357375
This package is fully typed with [TypeScript][].
358-
It exports the additional types `Root`, `Grammar`, and `Syntax`.
376+
It exports the additional types
377+
`Grammar`,
378+
`Root`,
379+
and `Syntax`.
359380

360381
<!--Old name of the following section:-->
361382

362383
<a name="syntaxes"></a>
363384

364385
## Data
365386

366-
If you’re using `refractor/lib/core.js`, no syntaxes are included.
367-
Checked syntaxes are included if you import `refractor` (or explicitly
368-
`refractor/lib/common.js`).
387+
If you’re using `refractor/lib/core.js`,
388+
no syntaxes are included.
389+
Checked syntaxes are included if you import `refractor`
390+
(or explicitly `refractor/lib/common.js`).
369391
Unchecked syntaxes are available through `refractor/lib/all.js`.
370392
You can import `core` or `common` and manually add more languages as you please.
371393

372-
Prism operates as a singleton: once you register a language in one place, it’ll
373-
be available everywhere.
394+
Prism operates as a singleton:
395+
once you register a language in one place,
396+
it’ll be available everywhere.
374397

375398
Only these custom built syntaxes will work with `refractor` because Prism’s own
376399
syntaxes are made to work with global variables and are not importable.
@@ -679,13 +702,16 @@ syntaxes are made to work with global variables and are not importable.
679702

680703
## CSS
681704

682-
`refractor` does not inject CSS for the syntax highlighted code (because well,
683-
refractor doesn’t have to be turned into HTML and might not run in a browser!).
684-
If you are in a browser, you can use any Prism theme.
685-
For example, to get Prism Dark from cdnjs:
705+
`refractor` does not inject CSS for the syntax highlighted code.
706+
It does not make sense: refractor doesn’t have to be turned into HTML and might
707+
not run in a browser!
708+
If you are in a browser,
709+
you can use any Prism theme.
710+
For example,
711+
to get Prism Dark from [`esm.sh`][esmsh]:
686712

687713
```html
688-
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.27.0/themes/prism-dark.min.css">
714+
<link rel="stylesheet" href="https://esm.sh/prismjs@1.30.0/themes/prism-dark.css">
689715
```
690716

691717
<!--Old name of the following section:-->
@@ -695,15 +721,17 @@ For example, to get Prism Dark from cdnjs:
695721
## Compatibility
696722

697723
This package is at least compatible with all maintained versions of Node.js.
698-
As of now, that is Node.js 14.14+ and 16.0+.
724+
As of now,
725+
that is Node.js 14+.
699726
It also works in Deno and modern browsers.
700727

701728
Only the custom built syntaxes in `refractor/lang/*.js` will work with
702729
`refractor` as Prism’s own syntaxes are made to work with global variables and
703730
are not importable.
704731

705-
refractor also does not support Prism plugins, due to the same limitations, and
706-
that they almost exclusively deal with the DOM.
732+
refractor also does not support Prism plugins,
733+
due to the same limitations,
734+
and that they almost exclusively deal with the DOM.
707735

708736
## Security
709737

‎script/count.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ export default function count() {
2020
u('list', {spread: false}, [
2121
u('listItem', [
2222
u('paragraph', [
23-
u('inlineCode', 'lib/core.js'),
24-
u('text', ' — 0 languages')
23+
u('inlineCode', 'lib/all.js'),
24+
u('text', ' — ' + all.length + ' languages')
2525
])
2626
]),
2727
u('listItem', [
@@ -32,8 +32,8 @@ export default function count() {
3232
]),
3333
u('listItem', [
3434
u('paragraph', [
35-
u('inlineCode', 'lib/all.js'),
36-
u('text', ' — ' + all.length + ' languages')
35+
u('inlineCode', 'lib/core.js'),
36+
u('text', ' — 0 languages')
3737
])
3838
])
3939
]),

0 commit comments

Comments
 (0)
Please sign in to comment.