@speed-highlight/core 1.0.1
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/LICENSE +121 -0
- package/README.md +191 -0
- package/dist/common.js +1 -0
- package/dist/detect.d.ts +8 -0
- package/dist/detect.js +1 -0
- package/dist/index.d.ts +114 -0
- package/dist/index.js +1 -0
- package/dist/languages/asm.js +1 -0
- package/dist/languages/bash.js +1 -0
- package/dist/languages/bf.js +1 -0
- package/dist/languages/c.js +1 -0
- package/dist/languages/css.js +1 -0
- package/dist/languages/csv.js +1 -0
- package/dist/languages/diff.js +1 -0
- package/dist/languages/docker.js +1 -0
- package/dist/languages/git.js +1 -0
- package/dist/languages/go.js +1 -0
- package/dist/languages/html.js +1 -0
- package/dist/languages/http.js +1 -0
- package/dist/languages/ini.js +1 -0
- package/dist/languages/java.js +1 -0
- package/dist/languages/js.js +1 -0
- package/dist/languages/js_template_literals.js +1 -0
- package/dist/languages/jsdoc.js +1 -0
- package/dist/languages/json.js +1 -0
- package/dist/languages/leanpub-md.js +1 -0
- package/dist/languages/log.js +1 -0
- package/dist/languages/lua.js +1 -0
- package/dist/languages/make.js +1 -0
- package/dist/languages/md.js +1 -0
- package/dist/languages/pl.js +1 -0
- package/dist/languages/plain.js +1 -0
- package/dist/languages/py.js +1 -0
- package/dist/languages/regex.js +1 -0
- package/dist/languages/rs.js +1 -0
- package/dist/languages/sql.js +1 -0
- package/dist/languages/todo.js +1 -0
- package/dist/languages/toml.js +1 -0
- package/dist/languages/ts.js +1 -0
- package/dist/languages/uri.js +1 -0
- package/dist/languages/xml.js +1 -0
- package/dist/languages/yaml.js +1 -0
- package/dist/node/common.js +1 -0
- package/dist/node/detect.d.ts +8 -0
- package/dist/node/detect.js +1 -0
- package/dist/node/index.d.ts +114 -0
- package/dist/node/index.js +1 -0
- package/dist/node/languages/asm.js +1 -0
- package/dist/node/languages/bash.js +1 -0
- package/dist/node/languages/bf.js +1 -0
- package/dist/node/languages/c.js +1 -0
- package/dist/node/languages/css.js +1 -0
- package/dist/node/languages/csv.js +1 -0
- package/dist/node/languages/diff.js +1 -0
- package/dist/node/languages/docker.js +1 -0
- package/dist/node/languages/git.js +1 -0
- package/dist/node/languages/go.js +1 -0
- package/dist/node/languages/html.js +1 -0
- package/dist/node/languages/http.js +1 -0
- package/dist/node/languages/ini.js +1 -0
- package/dist/node/languages/java.js +1 -0
- package/dist/node/languages/js.js +1 -0
- package/dist/node/languages/js_template_literals.js +1 -0
- package/dist/node/languages/jsdoc.js +1 -0
- package/dist/node/languages/json.js +1 -0
- package/dist/node/languages/leanpub-md.js +1 -0
- package/dist/node/languages/log.js +1 -0
- package/dist/node/languages/lua.js +1 -0
- package/dist/node/languages/make.js +1 -0
- package/dist/node/languages/md.js +1 -0
- package/dist/node/languages/pl.js +1 -0
- package/dist/node/languages/plain.js +1 -0
- package/dist/node/languages/py.js +1 -0
- package/dist/node/languages/regex.js +1 -0
- package/dist/node/languages/rs.js +1 -0
- package/dist/node/languages/sql.js +1 -0
- package/dist/node/languages/todo.js +1 -0
- package/dist/node/languages/toml.js +1 -0
- package/dist/node/languages/ts.js +1 -0
- package/dist/node/languages/uri.js +1 -0
- package/dist/node/languages/xml.js +1 -0
- package/dist/node/languages/yaml.js +1 -0
- package/dist/node/terminal.d.ts +26 -0
- package/dist/node/terminal.js +1 -0
- package/dist/node/themes/atom-dark.js +1 -0
- package/dist/node/themes/default.js +1 -0
- package/dist/node/themes/termcolor.js +1 -0
- package/dist/terminal.d.ts +26 -0
- package/dist/terminal.js +1 -0
- package/dist/themes/atom-dark.js +1 -0
- package/dist/themes/default.js +1 -0
- package/dist/themes/termcolor.js +1 -0
- package/package.json +75 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
Creative Commons Legal Code
|
|
2
|
+
|
|
3
|
+
CC0 1.0 Universal
|
|
4
|
+
|
|
5
|
+
CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
|
|
6
|
+
LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN
|
|
7
|
+
ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
|
|
8
|
+
INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
|
|
9
|
+
REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS
|
|
10
|
+
PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM
|
|
11
|
+
THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED
|
|
12
|
+
HEREUNDER.
|
|
13
|
+
|
|
14
|
+
Statement of Purpose
|
|
15
|
+
|
|
16
|
+
The laws of most jurisdictions throughout the world automatically confer
|
|
17
|
+
exclusive Copyright and Related Rights (defined below) upon the creator
|
|
18
|
+
and subsequent owner(s) (each and all, an "owner") of an original work of
|
|
19
|
+
authorship and/or a database (each, a "Work").
|
|
20
|
+
|
|
21
|
+
Certain owners wish to permanently relinquish those rights to a Work for
|
|
22
|
+
the purpose of contributing to a commons of creative, cultural and
|
|
23
|
+
scientific works ("Commons") that the public can reliably and without fear
|
|
24
|
+
of later claims of infringement build upon, modify, incorporate in other
|
|
25
|
+
works, reuse and redistribute as freely as possible in any form whatsoever
|
|
26
|
+
and for any purposes, including without limitation commercial purposes.
|
|
27
|
+
These owners may contribute to the Commons to promote the ideal of a free
|
|
28
|
+
culture and the further production of creative, cultural and scientific
|
|
29
|
+
works, or to gain reputation or greater distribution for their Work in
|
|
30
|
+
part through the use and efforts of others.
|
|
31
|
+
|
|
32
|
+
For these and/or other purposes and motivations, and without any
|
|
33
|
+
expectation of additional consideration or compensation, the person
|
|
34
|
+
associating CC0 with a Work (the "Affirmer"), to the extent that he or she
|
|
35
|
+
is an owner of Copyright and Related Rights in the Work, voluntarily
|
|
36
|
+
elects to apply CC0 to the Work and publicly distribute the Work under its
|
|
37
|
+
terms, with knowledge of his or her Copyright and Related Rights in the
|
|
38
|
+
Work and the meaning and intended legal effect of CC0 on those rights.
|
|
39
|
+
|
|
40
|
+
1. Copyright and Related Rights. A Work made available under CC0 may be
|
|
41
|
+
protected by copyright and related or neighboring rights ("Copyright and
|
|
42
|
+
Related Rights"). Copyright and Related Rights include, but are not
|
|
43
|
+
limited to, the following:
|
|
44
|
+
|
|
45
|
+
i. the right to reproduce, adapt, distribute, perform, display,
|
|
46
|
+
communicate, and translate a Work;
|
|
47
|
+
ii. moral rights retained by the original author(s) and/or performer(s);
|
|
48
|
+
iii. publicity and privacy rights pertaining to a person's image or
|
|
49
|
+
likeness depicted in a Work;
|
|
50
|
+
iv. rights protecting against unfair competition in regards to a Work,
|
|
51
|
+
subject to the limitations in paragraph 4(a), below;
|
|
52
|
+
v. rights protecting the extraction, dissemination, use and reuse of data
|
|
53
|
+
in a Work;
|
|
54
|
+
vi. database rights (such as those arising under Directive 96/9/EC of the
|
|
55
|
+
European Parliament and of the Council of 11 March 1996 on the legal
|
|
56
|
+
protection of databases, and under any national implementation
|
|
57
|
+
thereof, including any amended or successor version of such
|
|
58
|
+
directive); and
|
|
59
|
+
vii. other similar, equivalent or corresponding rights throughout the
|
|
60
|
+
world based on applicable law or treaty, and any national
|
|
61
|
+
implementations thereof.
|
|
62
|
+
|
|
63
|
+
2. Waiver. To the greatest extent permitted by, but not in contravention
|
|
64
|
+
of, applicable law, Affirmer hereby overtly, fully, permanently,
|
|
65
|
+
irrevocably and unconditionally waives, abandons, and surrenders all of
|
|
66
|
+
Affirmer's Copyright and Related Rights and associated claims and causes
|
|
67
|
+
of action, whether now known or unknown (including existing as well as
|
|
68
|
+
future claims and causes of action), in the Work (i) in all territories
|
|
69
|
+
worldwide, (ii) for the maximum duration provided by applicable law or
|
|
70
|
+
treaty (including future time extensions), (iii) in any current or future
|
|
71
|
+
medium and for any number of copies, and (iv) for any purpose whatsoever,
|
|
72
|
+
including without limitation commercial, advertising or promotional
|
|
73
|
+
purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each
|
|
74
|
+
member of the public at large and to the detriment of Affirmer's heirs and
|
|
75
|
+
successors, fully intending that such Waiver shall not be subject to
|
|
76
|
+
revocation, rescission, cancellation, termination, or any other legal or
|
|
77
|
+
equitable action to disrupt the quiet enjoyment of the Work by the public
|
|
78
|
+
as contemplated by Affirmer's express Statement of Purpose.
|
|
79
|
+
|
|
80
|
+
3. Public License Fallback. Should any part of the Waiver for any reason
|
|
81
|
+
be judged legally invalid or ineffective under applicable law, then the
|
|
82
|
+
Waiver shall be preserved to the maximum extent permitted taking into
|
|
83
|
+
account Affirmer's express Statement of Purpose. In addition, to the
|
|
84
|
+
extent the Waiver is so judged Affirmer hereby grants to each affected
|
|
85
|
+
person a royalty-free, non transferable, non sublicensable, non exclusive,
|
|
86
|
+
irrevocable and unconditional license to exercise Affirmer's Copyright and
|
|
87
|
+
Related Rights in the Work (i) in all territories worldwide, (ii) for the
|
|
88
|
+
maximum duration provided by applicable law or treaty (including future
|
|
89
|
+
time extensions), (iii) in any current or future medium and for any number
|
|
90
|
+
of copies, and (iv) for any purpose whatsoever, including without
|
|
91
|
+
limitation commercial, advertising or promotional purposes (the
|
|
92
|
+
"License"). The License shall be deemed effective as of the date CC0 was
|
|
93
|
+
applied by Affirmer to the Work. Should any part of the License for any
|
|
94
|
+
reason be judged legally invalid or ineffective under applicable law, such
|
|
95
|
+
partial invalidity or ineffectiveness shall not invalidate the remainder
|
|
96
|
+
of the License, and in such case Affirmer hereby affirms that he or she
|
|
97
|
+
will not (i) exercise any of his or her remaining Copyright and Related
|
|
98
|
+
Rights in the Work or (ii) assert any associated claims and causes of
|
|
99
|
+
action with respect to the Work, in either case contrary to Affirmer's
|
|
100
|
+
express Statement of Purpose.
|
|
101
|
+
|
|
102
|
+
4. Limitations and Disclaimers.
|
|
103
|
+
|
|
104
|
+
a. No trademark or patent rights held by Affirmer are waived, abandoned,
|
|
105
|
+
surrendered, licensed or otherwise affected by this document.
|
|
106
|
+
b. Affirmer offers the Work as-is and makes no representations or
|
|
107
|
+
warranties of any kind concerning the Work, express, implied,
|
|
108
|
+
statutory or otherwise, including without limitation warranties of
|
|
109
|
+
title, merchantability, fitness for a particular purpose, non
|
|
110
|
+
infringement, or the absence of latent or other defects, accuracy, or
|
|
111
|
+
the present or absence of errors, whether or not discoverable, all to
|
|
112
|
+
the greatest extent permissible under applicable law.
|
|
113
|
+
c. Affirmer disclaims responsibility for clearing rights of other persons
|
|
114
|
+
that may apply to the Work or any use thereof, including without
|
|
115
|
+
limitation any person's Copyright and Related Rights in the Work.
|
|
116
|
+
Further, Affirmer disclaims responsibility for obtaining any necessary
|
|
117
|
+
consents, permissions or other rights required for any use of the
|
|
118
|
+
Work.
|
|
119
|
+
d. Affirmer understands and acknowledges that Creative Commons is not a
|
|
120
|
+
party to this document and has no duty or obligation with respect to
|
|
121
|
+
this CC0 or use of the Work.
|
package/README.md
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
# Speed-highlight JS
|
|
2
|
+
|
|
3
|
+
Light, fast, and easy to use, dependencies free javascript syntax highlighter, with automatic language detection, [try it out here](https://speed-highlight.github.io/core/examples/)
|
|
4
|
+
|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
## Light 📦
|
|
8
|
+
|
|
9
|
+
* The core is about **1kB** (gzipped & minified)
|
|
10
|
+
* Languages definition are from **a few bytes** to **1kB**
|
|
11
|
+
* Themes are about **1kB**
|
|
12
|
+
* Language rules needed are automatically loaded
|
|
13
|
+
|
|
14
|
+
## Fast ⚡
|
|
15
|
+
|
|
16
|
+
Blazing fast highlighting using regex
|
|
17
|
+
|
|
18
|
+
## Simple setup 🚀
|
|
19
|
+
|
|
20
|
+
### Web
|
|
21
|
+
|
|
22
|
+
Style/theme (in the header of your html file):
|
|
23
|
+
```html
|
|
24
|
+
<link rel="stylesheet" href="/path/dist/themes/default.css">
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
In the body of your html file:
|
|
28
|
+
```html
|
|
29
|
+
<div class='shj-lang-[code-language]'>[code]</div>
|
|
30
|
+
or
|
|
31
|
+
<code class='shj-lang-[code-language]'>[inline code]</code>
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Highlight the code (in your javascript):
|
|
35
|
+
```js
|
|
36
|
+
import { highlightAll } from '/path/dist/index.js'
|
|
37
|
+
highlightAll();
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Auto language detection
|
|
41
|
+
```js
|
|
42
|
+
import { highlightElement } from '../src/index.js';
|
|
43
|
+
import { detectLanguage } from '../src/detect.js';
|
|
44
|
+
|
|
45
|
+
elm.textContent = code;
|
|
46
|
+
highlightElement(elm, detectLanguage(code));
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Load custom language
|
|
50
|
+
```js
|
|
51
|
+
import { loadLanguage } from '../src/index.js';
|
|
52
|
+
|
|
53
|
+
loadLanguage('language-name', customLanguage);
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
#### CDN
|
|
57
|
+
|
|
58
|
+
```html
|
|
59
|
+
<link rel="stylesheet" href="https://unpkg.com/@speed-highlight/core/dist/themes/default.css">
|
|
60
|
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/speed-highlight/core/dist/themes/default.css">
|
|
61
|
+
```
|
|
62
|
+
```js
|
|
63
|
+
import ... from 'https://unpkg.com/@speed-highlight/core/dist/index.js'
|
|
64
|
+
import ... from 'https://cdn.jsdelivr.net/gh/speed-highlight/core/dist/index.js'
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Deno
|
|
68
|
+
|
|
69
|
+
Use the [deno module](https://deno.land/x/speed_highlight_js)
|
|
70
|
+
|
|
71
|
+
```js
|
|
72
|
+
import { setTheme, printHighlight } from 'https://x.nest.land/speed_highlight_js/dist/terminal.js';
|
|
73
|
+
|
|
74
|
+
await setTheme('[theme-name]')
|
|
75
|
+
printHighlight('console.log("hello")', 'js')
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Node
|
|
79
|
+
|
|
80
|
+
Use the [npm package](https://www.npmjs.com/package/@speed-highlight/core)
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
npm i @speed-highlight/core
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
```js
|
|
87
|
+
const { setTheme, printHighlight } = require('@speed-highlight/core/terminal.js');
|
|
88
|
+
|
|
89
|
+
setTheme('[theme-name]')
|
|
90
|
+
printHighlight('console.log("hello")', 'js')
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## Migrating from prism
|
|
94
|
+
|
|
95
|
+
Speed-highlight JS is a lighter and faster version of prism that share a similar API
|
|
96
|
+
|
|
97
|
+
### Style
|
|
98
|
+
Remove the prism stylesheet in the head of your html file
|
|
99
|
+
Clone this repository or use a cdn to load our stylesheet
|
|
100
|
+
```diff
|
|
101
|
+
<head>
|
|
102
|
+
- <link href="themes/prism.css" rel="stylesheet" />
|
|
103
|
+
+ <link rel="stylesheet" href="https://unpkg.com/@speed-highlight/core/dist/themes/default.css">
|
|
104
|
+
</head>
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### Script
|
|
108
|
+
For the script part remove the prism.js script and replace it by a import and a call to `highlightAll`
|
|
109
|
+
```diff
|
|
110
|
+
<body>
|
|
111
|
+
- <script src="prism.js"></script>
|
|
112
|
+
+<script>
|
|
113
|
+
+ import { highlightAll } from 'https://unpkg.com/@speed-highlight/core/dist/index.js'
|
|
114
|
+
+ highlightAll()
|
|
115
|
+
+</script>
|
|
116
|
+
</body>
|
|
117
|
+
```
|
|
118
|
+
If you want to highlight only a specific element you can use the `highlightElement` function instead
|
|
119
|
+
|
|
120
|
+
### Code block
|
|
121
|
+
For the code blocks replace the `<pre><code>` by only one `<div>`
|
|
122
|
+
And use `shj-lang-` prefix instead of `language-` for the class property
|
|
123
|
+
```diff
|
|
124
|
+
-<pre><code class="language-css">p { color: red }</code></pre>
|
|
125
|
+
+<div class="shj-lang-css">p { color: red }</div>
|
|
126
|
+
```
|
|
127
|
+
And for inline code block you just have to change the class property
|
|
128
|
+
```diff
|
|
129
|
+
-<code class="language-css">p { color: red }</code>
|
|
130
|
+
+<code class="shj-lang-css">p { color: red }</code>
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## Languages supported 🌐
|
|
134
|
+
|
|
135
|
+
| Name | Class name | Support | Language detection |
|
|
136
|
+
| ---------- | ------------------- | --------------------------------------------------- | ------------------ |
|
|
137
|
+
| bash | shj-lang-bash | | ✅ |
|
|
138
|
+
| brainfuck | shj-lang-bf | increment, operator, print, comment | ❌ |
|
|
139
|
+
| css | shj-lang-css | comment, str, selector, units, function, ... | ✅ |
|
|
140
|
+
| csv | shj-lang-csv | punctuation, ... | ❌ |
|
|
141
|
+
| diff | shj-lang-diff | | ✅ |
|
|
142
|
+
| git | shj-lang-git | comment, insert, deleted, string, ... | ❌ |
|
|
143
|
+
| html | shj-lang-html | | ✅ |
|
|
144
|
+
| http | shj-lang-http | keywork, string, punctuation, variable, version | ✅ |
|
|
145
|
+
| ini | shj-lang-ini | | ❌ |
|
|
146
|
+
| javascipt | shj-lang-js | basic syntax, regex, jsdoc, json, template literals | ✅ |
|
|
147
|
+
| jsdoc | shj-lang-jsdoc | | ❌ |
|
|
148
|
+
| json | shj-lang-json | string, number, bool, ... | ❌ |
|
|
149
|
+
| leanpub-md | shj-lang-leanpub-md | | ❌ |
|
|
150
|
+
| log | shj-lang-log | number, string, comment, errors | ❌ |
|
|
151
|
+
| lua | shj-lang-lua | | ✅ |
|
|
152
|
+
| makefile | shj-lang-make | | ✅ |
|
|
153
|
+
| markdown | shj-lang-md | | ✅ |
|
|
154
|
+
| perl | shj-lang-pl | | ✅ |
|
|
155
|
+
| plain | shj-lang-plain | | ❌ |
|
|
156
|
+
| python | shj-lang-py | | ✅ |
|
|
157
|
+
| regex | shj-lang-regex | count, set, ... | ❌ |
|
|
158
|
+
| sql | shj-lang-sql | number, string, function, ... | ✅ |
|
|
159
|
+
| todo | shj-lang-todo | | ❌ |
|
|
160
|
+
| toml | shj-lang-toml | comment, table, string, bool, variable | ❌ |
|
|
161
|
+
| typescript | shj-lang-ts | js syntax, ts keyword, types | ✅ |
|
|
162
|
+
| uri | shj-lang-uri | | ✅ |
|
|
163
|
+
| yaml | shj-lang-yaml | comment, numbers, variable, string, bool | ❌ |
|
|
164
|
+
| docker | shj-lang-docker | | ✅ |
|
|
165
|
+
| c | shj-lang-c | | ✅ |
|
|
166
|
+
| xml | shj-lang-xml | | ✅ |
|
|
167
|
+
| rust | shj-lang-rs | | ✅ |
|
|
168
|
+
| go | shj-lang-go | | ✅ |
|
|
169
|
+
| java | shj-lang-java | | ✅ |
|
|
170
|
+
| asm | shj-lang-asm | | ✅ |
|
|
171
|
+
|
|
172
|
+
## Themes 🌈
|
|
173
|
+
|
|
174
|
+
A modern theme by default
|
|
175
|
+
|
|
176
|
+
| Name | Terminal | Web |
|
|
177
|
+
| ------------------- | -------- | --- |
|
|
178
|
+
| default | ✅ | ✅ |
|
|
179
|
+
| github-dark | ❌ | ✅ |
|
|
180
|
+
| github-light | ❌ | ✅ |
|
|
181
|
+
| github-dim | ❌ | ✅ |
|
|
182
|
+
| atom-dark | ✅ | ✅ |
|
|
183
|
+
| visual-studio-dark | ❌ | ✅ |
|
|
184
|
+
|
|
185
|
+
## Documentation 👀
|
|
186
|
+
|
|
187
|
+
Further in-depth documentation for the API and other topics is in our [Wiki](https://github.com/speed-highlight/core/wiki) and our [Documentation](https://speed-highlight.github.io/core/doc/)
|
|
188
|
+
|
|
189
|
+
## License 📃
|
|
190
|
+
|
|
191
|
+
Shj is released under the Creative Commons Zero License. See our [LICENSE](https://github.com/speed-highlight/core/blob/main/LICENSE) file for details.
|
package/dist/common.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var t={num:{type:"num",match:/(\.e?|\b)\d(e-|[\d.oxa-fA-F_])*(\.|\b)/g},str:{type:"str",match:/(["'])(\\[^]|(?!\1)[^\r\n\\])*\1?/g},strDouble:{type:"str",match:/"((?!")[^\r\n\\]|\\[^])*"?/g}};export{t as default};
|
package/dist/detect.d.ts
ADDED
package/dist/detect.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const t=[["bash",[/#!(\/usr)?\/bin\/bash/g,500],[/\b(if|elif|then|fi|echo)\b|\$/g,10]],["html",[/<\/?[a-z-]+[^\n>]*>/g,10],[/^\s+<!DOCTYPE\s+html/g,500]],["http",[/^(GET|HEAD|POST|PUT|DELETE|PATCH|HTTP)\b/g,500]],["js",[/\b(console|await|async|function|export|import|this|class|for|let|const|map|join|require)\b/g,10]],["ts",[/\b(console|await|async|function|export|import|this|class|for|let|const|map|join|require|implements|interface|namespace)\b/g,10]],["py",[/\b(def|print|class|and|or|lambda)\b/g,10]],["sql",[/\b(SELECT|INSERT|FROM)\b/g,50]],["pl",[/#!(\/usr)?\/bin\/perl/g,500],[/\b(use|print)\b|\$/g,10]],["lua",[/#!(\/usr)?\/bin\/lua/g,500]],["make",[/\b(ifneq|endif|if|elif|then|fi|echo|.PHONY|^[a-z]+ ?:$)\b|\$/gm,10]],["uri",[/https?:|mailto:|tel:|ftp:/g,30]],["css",[/^(@import|@page|@media|(\.|#)[a-z]+)/gm,20]],["diff",[/^[+><-]/gm,10],[/^@@ ?[-+,0-9 ]+ ?@@/gm,25]],["md",[/^(>|\t\*|\t\d+.)/gm,10],[/\[.*\](.*)/g,10]],["docker",[/^(FROM|ENTRYPOINT|RUN)/gm,500]],["xml",[/<\/?[a-z-]+[^\n>]*>/g,10],[/^<\?xml/g,500]],["c",[/#include\b|\bprintf\s+\(/g,100]],["rs",[/^\s+(use|fn|mut|match)\b/gm,100]],["go",[/\b(func|fmt|package)\b/g,100]],["java",[/^import\s+java/gm,500]],["asm",[/^(section|global main|extern|\t(call|mov|ret))/gm,100]],["css",[/^(@import|@page|@media|(\.|#)[a-z]+)/gm,20]],["json",[/\b(true|false|null)\b/g,10]],["yaml",[/^(\s+)?[a-z]+:/gm,10]]],a=a=>t.map((([t,...e])=>[t,e.reduce(((t,[e,s])=>t+[...a.matchAll(e)].length*s),0)])).filter((([t,a])=>a>20)).sort(((t,a)=>a[1]-t[1]))[0]?.[0]||"plain";export{a as detectLanguage};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/////////// typedef.js ///////////
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Supported languages.
|
|
5
|
+
*/
|
|
6
|
+
export type ShjLanguage = 'asm'|'bash'|'bf'|'c'|'css'|'csv'|'diff'|'docker'|'git'|'go'|'html'|'http'|'ini'|'java'|'js'|'jsdoc'|'json'|'leanpub-md'|'log'|'lua'|'make'|'md'|'pl'|'plain'|'py'|'regex'|'rs'|'sql'|'todo'|'toml'|'ts'|'uri'|'xml'|'yaml';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Themes supported in the browser.
|
|
10
|
+
*/
|
|
11
|
+
export type ShjBrowserTheme = 'atom-dark'|'github-dark'|'github-dim'|'dark'|'default'|'github-light'|'visual-studio-dark';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Languages supported in the terminal.
|
|
15
|
+
*/
|
|
16
|
+
export type ShjTerminalTheme = 'default'|'atom-dark';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* * `inline` inside `code` element
|
|
20
|
+
* * `oneline` inside `div` element and containing only one line
|
|
21
|
+
* * `multiline` inside `div` element
|
|
22
|
+
*/
|
|
23
|
+
export type ShjDisplayMode = 'inline'|'oneline'|'multiline';
|
|
24
|
+
|
|
25
|
+
export type ShjToken = 'deleted'|'err'|'var'|'section'|'kwd'|'class'|'cmnt'|'insert'|'type'|'func'|'bool'|'num'|'oper'|'str'|'esc';
|
|
26
|
+
|
|
27
|
+
export interface ShjOptions {
|
|
28
|
+
/**
|
|
29
|
+
* Indicates whether to hide line numbers.
|
|
30
|
+
* @default false
|
|
31
|
+
*/
|
|
32
|
+
hideLineNumbers: boolean;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/////////// Custom Types ///////////
|
|
36
|
+
|
|
37
|
+
export type ShjLanguageComponent =
|
|
38
|
+
| { type: string; match: RegExp }
|
|
39
|
+
| { extand: string }
|
|
40
|
+
| {
|
|
41
|
+
match: RegExp;
|
|
42
|
+
sub:
|
|
43
|
+
| string
|
|
44
|
+
| ((code: string) => {
|
|
45
|
+
type: string;
|
|
46
|
+
sub: Array<{ match: RegExp; sub: string | Promise<string> }>
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export type ShjLanguageDefinition = Array<ShjLanguageComponent>;
|
|
51
|
+
|
|
52
|
+
/////////// index.js ///////////
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Find the tokens in the given code and call the callback
|
|
56
|
+
* @param src The code
|
|
57
|
+
* @param lang The language of the code
|
|
58
|
+
* @param callback The callback function
|
|
59
|
+
* this function will be given
|
|
60
|
+
* * the text of the token
|
|
61
|
+
* * the type of the token
|
|
62
|
+
*/
|
|
63
|
+
export declare function tokenize<T extends string = ShjLanguage>(
|
|
64
|
+
src: string,
|
|
65
|
+
lang: T,
|
|
66
|
+
callback: (value: string, token: ShjToken) => void
|
|
67
|
+
): Promise<void>;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Highlight a string passed as argument and return it
|
|
71
|
+
* @example
|
|
72
|
+
* elm.innerHTML = await highlightText(code, 'js');
|
|
73
|
+
* @param src The code
|
|
74
|
+
* @param lang The language of the code
|
|
75
|
+
* @param multiline If it is multiline, it will add a wrapper for the line numbering and header
|
|
76
|
+
* @param Customization options
|
|
77
|
+
* @returns The highlighted string
|
|
78
|
+
*/
|
|
79
|
+
export declare function highlightText<T extends string = ShjLanguage>(
|
|
80
|
+
src: string,
|
|
81
|
+
lang: T,
|
|
82
|
+
multiline?: boolean,
|
|
83
|
+
opt?: ShjOptions
|
|
84
|
+
): Promise<string>;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Highlight a DOM element by getting the new innerHTML with highlightText
|
|
88
|
+
* @param elm The DOM element
|
|
89
|
+
* @param lang The language of the code (seaching by default on `elm` for a 'shj-lang-' class)
|
|
90
|
+
* @param mode The display mode (guessed by default)
|
|
91
|
+
* @param opt Customization options
|
|
92
|
+
*/
|
|
93
|
+
export declare function highlightElement<T extends string = ShjLanguage>(
|
|
94
|
+
elm: Element,
|
|
95
|
+
lang?: T,
|
|
96
|
+
mode?: ShjDisplayMode,
|
|
97
|
+
opt?: ShjOptions
|
|
98
|
+
): Promise<void>;
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Call highlightElement on element with a css class starting with `shj-lang-`
|
|
102
|
+
* @param opt Customization options
|
|
103
|
+
*/
|
|
104
|
+
export declare function highlightAll(opt?: ShjOptions): Promise<void>;
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Load a language and add it to the langs object
|
|
108
|
+
* @param name The name of the language
|
|
109
|
+
* @param module Module that has the language as the default export
|
|
110
|
+
*/
|
|
111
|
+
export declare function loadLanguage(
|
|
112
|
+
name: string,
|
|
113
|
+
module: { default: ShjLanguageDefinition }
|
|
114
|
+
): void;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import a from"./common.js";const s={},e=(a="")=>a.replaceAll("&","&").replaceAll?.("<","<").replaceAll?.(">",">"),n=(a,s)=>s?`<span class="shj-syn-${s}">${a}</span>`:a;async function t(e,n,g){try{let r,l,u,i={},c=[],j=0,o="string"==typeof n?await(s[n]??=function(a){switch(a){case"./languages/asm.js":return import("./languages/asm.js");case"./languages/bash.js":return import("./languages/bash.js");case"./languages/bf.js":return import("./languages/bf.js");case"./languages/c.js":return import("./languages/c.js");case"./languages/css.js":return import("./languages/css.js");case"./languages/csv.js":return import("./languages/csv.js");case"./languages/diff.js":return import("./languages/diff.js");case"./languages/docker.js":return import("./languages/docker.js");case"./languages/git.js":return import("./languages/git.js");case"./languages/go.js":return import("./languages/go.js");case"./languages/html.js":return import("./languages/html.js");case"./languages/http.js":return import("./languages/http.js");case"./languages/ini.js":return import("./languages/ini.js");case"./languages/java.js":return import("./languages/java.js");case"./languages/js.js":return import("./languages/js.js");case"./languages/js_template_literals.js":return import("./languages/js_template_literals.js");case"./languages/jsdoc.js":return import("./languages/jsdoc.js");case"./languages/json.js":return import("./languages/json.js");case"./languages/leanpub-md.js":return import("./languages/leanpub-md.js");case"./languages/log.js":return import("./languages/log.js");case"./languages/lua.js":return import("./languages/lua.js");case"./languages/make.js":return import("./languages/make.js");case"./languages/md.js":return import("./languages/md.js");case"./languages/pl.js":return import("./languages/pl.js");case"./languages/plain.js":return import("./languages/plain.js");case"./languages/py.js":return import("./languages/py.js");case"./languages/regex.js":return import("./languages/regex.js");case"./languages/rs.js":return import("./languages/rs.js");case"./languages/sql.js":return import("./languages/sql.js");case"./languages/todo.js":return import("./languages/todo.js");case"./languages/toml.js":return import("./languages/toml.js");case"./languages/ts.js":return import("./languages/ts.js");case"./languages/uri.js":return import("./languages/uri.js");case"./languages/xml.js":return import("./languages/xml.js");case"./languages/yaml.js":return import("./languages/yaml.js");default:return new Promise((function(s,e){("function"==typeof queueMicrotask?queueMicrotask:setTimeout)(e.bind(null,new Error("Unknown variable dynamic import: "+a)))}))}}(`./languages/${n}.js`)):n,m=[..."string"==typeof n?o.default:n.sub];for(;j<e.length;){for(i.index=null,r=m.length;r-- >0;){if(l=m[r].expand?a[m[r].expand]:m[r],void 0===c[r]||c[r].match.index<j){if(l.match.lastIndex=j,u=l.match.exec(e),null===u){m.splice(r,1),c.splice(r,1);continue}c[r]={match:u,lastIndex:l.match.lastIndex}}c[r].match[0]&&(c[r].match.index<=i.index||null===i.index)&&(i={part:l,index:c[r].match.index,match:c[r].match[0],end:c[r].lastIndex})}if(null===i.index)break;g(e.slice(j,i.index),o.type),j=i.end,i.part.sub?await t(i.match,"string"==typeof i.part.sub?i.part.sub:"function"==typeof i.part.sub?i.part.sub(i.match):i.part,g):g(i.match,i.part.type)}g(e.slice(j,e.length),o.type)}catch{g(e)}}async function g(a,s,g=!0,r={}){let l="";return await t(a,s,((a,s)=>l+=n(e(a),s))),g?`<div><div class="shj-numbers">${"<div></div>".repeat(!r.hideLineNumbers&&a.split("\n").length)}</div><div>${l}</div></div>`:l}async function r(a,s=a.className.match(/shj-lang-([\w-]+)/)?.[1],e,n){let t=a.textContent;e??=("CODE"==a.tagName?"in":t.split("\n").length<2?"one":"multi")+"line",a.dataset.lang=s,a.className=`${[...a.classList].filter((a=>!a.startsWith("shj-")||a.startsWith("shj-mode-"))).join(" ")} shj-lang-${s} shj-${e}`,a.innerHTML=await g(t,s,"multiline"==e,n)}let l=async a=>document.querySelectorAll('[class*="shj-lang-"]').forEach((s=>r(s,void 0,void 0,a))),u=(a,e)=>{s[a]=e};export{l as highlightAll,r as highlightElement,g as highlightText,u as loadLanguage,t as tokenize};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var t=[{type:"cmnt",match:/;.*/gm},{expand:"str"},{expand:"num"},{type:"kwd",match:/^[a-z]+\s+[a-z.]+/gm,sub:[{type:"func",match:/^[a-z]+/g}]},{type:"kwd",match:/^\t*[a-z]+/gm},{match:/%|\$/g,type:"oper"}];export{t as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
let e={type:"var",match:/\$\w+|\${[^}]*}|\$\([^)]*\)/g};var t=[{sub:"todo",match:/#.*/g},{type:"str",match:/(["'])((?!\1)[^\r\n\\]|\\[^])*\1?/g,sub:[e]},{type:"kwd",match:/-[a-zA-Z]+|$<|[&|;]+|\b(unset|readonly|shift|export|if|fi|else|elif|while|do|done|for|until|case|esac|break|continue|exit|return|trap|wait|eval|exec|then|declare|enable|local|select|typeset|time|add|remove|install|update|delete)\b/g},{expand:"num"},{type:"func",match:/\b(set|alias|bg|bind|builtin|caller|command|compgen|complete|dirs|disown|echo|enable|eval|exec|exit|fc|fg|getopts|hash|help|history|jobs|kill|let|logout|popd|printf|pushd|pwd|read|set|shift|shopt|source|suspend|test|times|trap|type|ulimit|umask|unalias|unset)\b/g},{type:"bool",match:/\b(true|false)\b/g},{type:"func",match:/[a-z_]+(?=\s*\()/g},{type:"oper",match:/[=(){}<>+*/!?~^-]+/g},{type:"var",match:/\w+(?=\s*=)/g},e];export{t as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var t=[{match:/[^\[\->+.<\]\s].*/g,sub:"todo"},{type:"func",match:/\.+/g},{type:"kwd",match:/[<>]+/g},{type:"oper",match:/[+-]+/g}];export{t as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var t=[{match:/\/\/.*\n?|\/\*((?!\*\/)[^])*(\*\/)?/g,sub:"todo"},{expand:"str"},{expand:"num"},{type:"kwd",match:/#\s*include (<.*>|".*")/g,sub:[{type:"str",match:/(<|").*/g}]},{match:/asm\s*{[^}]*}/g,sub:[{type:"kwd",match:/^asm/g},{match:/[^{}]*(?=}$)/g,sub:"asm"}]},{type:"kwd",match:/\*|&|#[a-z]+\b|\b(asm|auto|double|int|struct|break|else|long|switch|case|enum|register|typedef|char|extern|return|union|const|float|short|unsigned|continue|for|signed|void|default|goto|sizeof|volatile|do|if|static|while)\b/g},{type:"oper",match:/[/*+:?&|%^~=!,<>.^-]+/g},{type:"func",match:/[a-zA-Z_][\w_]*(?=\s*\()/g},{type:"class",match:/\b[A-Z][\w_]*\b/g}];export{t as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var t=[{match:/\/\*((?!\*\/)[^])*(\*\/)?/g,sub:"todo"},{expand:"str"},{type:"kwd",match:/@\w+\b|\b(and|not|only|or)\b|\b[a-z-]+(?=[^{}]*{)/g},{type:"var",match:/\b[\w-]+(?=\s*:)|(::?|\.)[\w-]+(?=[^{}]*{)/g},{type:"func",match:/#[\w-]+(?=[^{}]*{)/g},{type:"num",match:/#[\da-f]{3,8}/g},{type:"num",match:/\d+(\.\d+)?(cm|mm|in|px|pt|pc|em|ex|ch|rem|vm|vh|vmin|vmax|%)?/g,sub:[{type:"var",match:/[a-z]+|%/g}]},{match:/url\([^)]*\)/g,sub:[{type:"func",match:/url(?=\()/g},{type:"str",match:/[^()]+/g}]},{type:"func",match:/\b[a-zA-Z]\w*(?=\s*\()/g},{type:"num",match:/\b[a-z-]+\b/g}];export{t as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e=[{expand:"strDouble"},{type:"oper",match:/,/g}];export{e as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var t=[{type:"deleted",match:/^[-<].*/gm},{type:"insert",match:/^[+>].*/gm},{type:"kwd",match:/!.*/gm},{type:"section",match:/^@@.*@@$|^\d.*|^([*-+])\1\1.*/gm}];export{t as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import E from"./bash.js";var L=[{type:"kwd",match:/^(FROM|RUN|CMD|LABEL|MAINTAINER|EXPOSE|ENV|ADD|COPY|ENTRYPOINT|VOLUME|USER|WORKDIR|ARG|ONBUILD|STOPSIGNAL|HEALTHCHECK|SHELL)\b/gim},...E];export{L as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import t from"./diff.js";var m=[{match:/^#.*/gm,sub:"todo"},{expand:"str"},...t,{type:"func",match:/^(\$ )?git(\s.*)?$/gm},{type:"kwd",match:/^commit \w+$/gm}];export{m as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var t=[{match:/\/\/.*\n?|\/\*((?!\*\/)[^])*(\*\/)?/g,sub:"todo"},{expand:"str"},{expand:"num"},{type:"kwd",match:/\*|&|\b(break|case|chan|const|continue|default|defer|else|fallthrough|for|func|go|goto|if|import|interface|map|package|range|return|select|struct|switch|type|var)\b/g},{type:"func",match:/[a-zA-Z_][\w_]*(?=\s*\()/g},{type:"class",match:/\b[A-Z][\w_]*\b/g},{type:"oper",match:/[+\-*\/%&|^~=!<>.^-]+/g}];export{t as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import s,{property as t,xmlElement as c}from"./xml.js";var e=[{type:"class",match:/<!DOCTYPE("[^"]*"|'[^']*'|[^"'>])*>/gi,sub:[{type:"str",match:/"[^"]*"|'[^']*'/g},{type:"oper",match:/^<!|>$/g},{type:"var",match:/DOCTYPE/gi}]},{match:RegExp(`<style${t}>((?!</style>)[^])*</style\\s*>`,"g"),sub:[{match:RegExp(`^<style${t}>`,"g"),sub:c.sub},{match:RegExp(`${c.match}|[^]*(?=</style\\s*>$)`,"g"),sub:"css"},c]},{match:RegExp(`<script${t}>((?!<\/script>)[^])*</script\\s*>`,"g"),sub:[{match:RegExp(`^<script${t}>`,"g"),sub:c.sub},{match:RegExp(`${c.match}|[^]*(?=</script\\s*>$)`,"g"),sub:"js"},c]},...s];export{e as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{detectLanguage as t}from"../detect.js";var a=[{type:"kwd",match:/^(GET|HEAD|POST|PUT|DELETE|CONNECT|OPTIONS|TRACE|PATCH|PRI|SEARCH)\b/gm},{expand:"str"},{type:"section",match:/\bHTTP\/[\d.]+\b/g},{expand:"num"},{type:"oper",match:/[,;:=]/g},{type:"var",match:/[a-zA-Z][\w-]*(?=:)/g},{match:/\n\n[^]*/g,sub:t}];export{a as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var t=[{match:/(^[ \f\t\v]*)[#;].*/gm,sub:"todo"},{type:"str",match:/.*/g},{type:"var",match:/.*(?==)/g},{type:"section",match:/^\s*\[.+\]\s*$/gm},{type:"oper",match:/=/g}];export{t as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var t=[{match:/\/\/.*\n?|\/\*((?!\*\/)[^])*(\*\/)?/g,sub:"todo"},{expand:"str"},{expand:"num"},{type:"kwd",match:/\b(abstract|assert|boolean|break|byte|case|catch|char|class|continue|const|default|do|double|else|enum|exports|extends|final|finally|float|for|goto|if|implements|import|instanceof|int|interface|long|module|native|new|package|private|protected|public|requires|return|short|static|strictfp|super|switch|synchronized|this|throw|throws|transient|try|var|void|volatile|while)\b/g},{type:"oper",match:/[/*+:?&|%^~=!,<>.^-]+/g},{type:"func",match:/[a-zA-Z_][\w_]*(?=\s*\()/g},{type:"class",match:/\b[A-Z][\w_]*\b/g}];export{t as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var t=[{match:/\/\*\*((?!\*\/)[^])*(\*\/)?/g,sub:"jsdoc"},{match:/\/\/.*\n?|\/\*((?!\*\/)[^])*(\*\/)?/g,sub:"todo"},{expand:"str"},{match:/`((?!`)[^]|\\[^])*`?/g,sub:"js_template_literals"},{type:"kwd",match:/=>|\b(this|set|get|as|async|await|break|case|catch|class|const|constructor|continue|debugger|default|delete|do|else|enum|export|extends|finally|for|from|function|if|implements|import|in|instanceof|interface|let|var|of|new|package|private|protected|public|return|static|super|switch|throw|throws|try|typeof|void|while|with|yield)\b/g},{match:/\/((?!\/)[^\r\n\\]|\\.)+\/[dgimsuy]*/g,sub:"regex"},{expand:"num"},{type:"num",match:/\b(NaN|null|undefined|[A-Z][A-Z_]*)\b/g},{type:"bool",match:/\b(true|false)\b/g},{type:"oper",match:/[/*+:?&|%^~=!,<>.^-]+/g},{type:"class",match:/\b[A-Z][\w_]*\b/g},{type:"func",match:/[a-zA-Z$_][\w$_]*(?=\s*((\?\.)?\s*\(|=\s*(\(?[\w,{}\[\])]+\)? =>|function\b)))/g}];export{t as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e=[{match:new class{exec(e){let t,s=this.lastIndex,l=t=>{for(;++s<e.length-2;)if("{"==e[s])l();else if("}"==e[s])return};for(;s<e.length;s++)if("\\"!=e[s-1]&&"$"==e[s]&&"{"==e[s+1])return t=s++,l(),this.lastIndex=s+1,{index:t,0:e.slice(t,s+1)};return null}},sub:[{type:"kwd",match:/^\${|}$/g},{match:/(?!^\$|{)[^]+(?=}$)/g,sub:"js"}]}];let t="str";export{e as default,t as type};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import t from"./todo.js";var a=[{type:"kwd",match:/@\w+/g},{type:"class",match:/{[\w\s|<>,.@\[\]]+}/g},{type:"var",match:/\[[\w\s="']+\]/g},...t];let e="cmnt";export{a as default,e as type};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var a=[{type:"var",match:/("|')?[a-zA-Z]\w*\1(?=\s*:)/g},{expand:"str"},{expand:"num"},{type:"num",match:/\bnull\b/g},{type:"bool",match:/\b(true|false)\b/g}];export{a as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import e from"./md.js";import{detectLanguage as t}from"../detect.js";var n=[{type:"insert",match:/(leanpub-start-insert)((?!leanpub-end-insert)[^])*(leanpub-end-insert)?/g,sub:[{type:"insert",match:/leanpub-(start|end)-insert/g},{match:/(?!leanpub-start-insert)((?!leanpub-end-insert)[^])*/g,sub:t}]},{type:"deleted",match:/(leanpub-start-delete)((?!leanpub-end-delete)[^])*(leanpub-end-delete)?/g,sub:[{type:"deleted",match:/leanpub-(start|end)-delete/g},{match:/(?!leanpub-start-delete)((?!leanpub-end-delete)[^])*/g,sub:t}]},...e];export{n as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e=[{type:"cmnt",match:/^#.*/gm},{expand:"strDouble"},{expand:"num"},{type:"err",match:/\b(err(or)?|[a-z_-]*exception|warn|warning|failed|ko|invalid|not ?found|alert|fatal)\b/gi},{type:"num",match:/\b(null|undefined)\b/gi},{type:"bool",match:/\b(false|true|yes|no)\b/gi},{type:"oper",match:/\.|,/g}];export{e as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e=[{match:/^#!.*|--(\[(=*)\[((?!--\]\2\])[^])*--\]\2\]|.*)/g,sub:"todo"},{expand:"str"},{type:"kwd",match:/\b(and|break|do|else|elseif|end|for|function|if|in|local|not|or|repeat|return|then|until|while)\b/g},{type:"bool",match:/\b(true|false|nil)\b/g},{type:"oper",match:/[+*/%^#=~<>:,.-]+/g},{expand:"num"},{type:"func",match:/[a-z_]+(?=\s*[({])/g}];export{e as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var t=[{match:/^\s*#.*/gm,sub:"todo"},{expand:"str"},{type:"oper",match:/[${}()]+/g},{type:"class",match:/.PHONY:/gm},{type:"section",match:/^[\w.]+:/gm},{type:"kwd",match:/\b(ifneq|endif)\b/g},{expand:"num"},{type:"var",match:/[A-Z_]+(?=\s*=)/g},{match:/^.*$/gm,sub:"bash"}];export{t as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{detectLanguage as t}from"../detect.js";var a=[{type:"cmnt",match:/^>.*|(=|-)\1+/gm},{type:"class",match:/\*\*((?!\*\*).)*\*\*/g},{match:/```((?!```)[^])*\n```/g,sub:a=>({type:"kwd",sub:[{match:/\n[^]*(?=```)/g,sub:a.split("\n")[0].slice(3)||t(a)}]})},{type:"str",match:/`[^`]*`/g},{type:"var",match:/~~((?!~~).)*~~/g},{type:"kwd",match:/_[^_]*_|\*[^*]*\*/g},{type:"kwd",match:/^\s*(\*|\d+\.)\s/gm},{type:"oper",match:/\[[^\]]*]/g},{type:"func",match:/\([^)]*\)/g}];export{a as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e=[{match:/#.*/g,sub:"todo"},{type:"str",match:/(["'])(\\[^]|(?!\1)[^])*\1?/g},{expand:"num"},{type:"kwd",match:/\b(any|break|continue|default|delete|die|do|else|elsif|eval|for|foreach|given|goto|if|last|local|my|next|our|package|print|redo|require|return|say|state|sub|switch|undef|unless|until|use|when|while|not|and|or|xor)\b/g},{type:"oper",match:/[-+*/%~!&<>|=?,]+/g},{type:"func",match:/[a-z_]+(?=\s*\()/g}];export{e as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var a=[{expand:"strDouble"}];export{a as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var a=[{match:/#.*/g,sub:"todo"},{match:/("""|''')(\\[^]|(?!\1)[^])*\1?/g,sub:"todo"},{type:"str",match:/f("|')(\\[^]|(?!\1).)*\1?|f((["'])\4\4)(\\[^]|(?!\3)[^])*\3?/gi,sub:[{type:"var",match:/{[^{}]*}/g,sub:[{match:/(?!^{)[^]*(?=}$)/g,sub:"py"}]}]},{expand:"str"},{type:"kwd",match:/\b(and|as|assert|break|class|continue|def|del|elif|else|except|finally|for|from|global|if|import|in|is|lambda|nonlocal|not|or|pass|raise|return|try|while|with|yield)\b/g},{type:"bool",match:/\b(False|True|None)\b/g},{expand:"num"},{type:"func",match:/[a-z_]+(?=\s*\()/g},{type:"oper",match:/[-/*+<>,=!&|^%]+/g},{type:"class",match:/\b[A-Z][\w_]*\b/g}];export{a as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var t=[{match:/^(?!\/).*/gm,sub:"todo"},{type:"num",match:/\[((?!\])[^\\]|\\.)*\]/g},{type:"kwd",match:/\||\^|\$|\\.|\w+($|\r|\n)/g},{type:"var",match:/\*|\+|\{\d+,\d+\}/g}];let a="oper";export{t as default,a as type};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e=[{match:/\/\/.*\n?|\/\*((?!\*\/)[^])*(\*\/)?/g,sub:"todo"},{expand:"str"},{expand:"num"},{type:"kwd",match:/\b(as|break|const|continue|crate|else|enum|extern|false|fn|for|if|impl|in|let|loop|match|mod|move|mut|pub|ref|return|self|Self|static|struct|super|trait|true|type|unsafe|use|where|while|async|await|dyn|abstract|become|box|do|final|macro|override|priv|typeof|unsized|virtual|yield|try)\b/g},{type:"oper",match:/[/*+:?&|%^~=!,<>.^-]+/g},{type:"class",match:/\b[A-Z][\w_]*\b/g},{type:"func",match:/[a-zA-Z_][\w_]*(?=\s*!?\s*\()/g}];export{e as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var E=[{match:/--.*\n?|\/\*((?!\*\/)[^])*(\*\/)?/g,sub:"todo"},{expand:"str"},{type:"func",match:/\b(AVG|COUNT|FIRST|FORMAT|LAST|LCASE|LEN|MAX|MID|MIN|MOD|NOW|ROUND|SUM|UCASE)(?=\s*\()/g},{type:"kwd",match:/\b(ACTION|ADD|AFTER|ALGORITHM|ALL|ALTER|ANALYZE|ANY|APPLY|AS|ASC|AUTHORIZATION|AUTO_INCREMENT|BACKUP|BDB|BEGIN|BERKELEYDB|BIGINT|BINARY|BIT|BLOB|BOOL|BOOLEAN|BREAK|BROWSE|BTREE|BULK|BY|CALL|CASCADED?|CASE|CHAIN|CHAR(?:ACTER|SET)?|CHECK(?:POINT)?|CLOSE|CLUSTERED|COALESCE|COLLATE|COLUMNS?|COMMENT|COMMIT(?:TED)?|COMPUTE|CONNECT|CONSISTENT|CONSTRAINT|CONTAINS(?:TABLE)?|CONTINUE|CONVERT|CREATE|CROSS|CURRENT(?:_DATE|_TIME|_TIMESTAMP|_USER)?|CURSOR|CYCLE|DATA(?:BASES?)?|DATE(?:TIME)?|DAY|DBCC|DEALLOCATE|DEC|DECIMAL|DECLARE|DEFAULT|DEFINER|DELAYED|DELETE|DELIMITERS?|DENY|DESC|DESCRIBE|DETERMINISTIC|DISABLE|DISCARD|DISK|DISTINCT|DISTINCTROW|DISTRIBUTED|DO|DOUBLE|DROP|DUMMY|DUMP(?:FILE)?|DUPLICATE|ELSE(?:IF)?|ENABLE|ENCLOSED|END|ENGINE|ENUM|ERRLVL|ERRORS|ESCAPED?|EXCEPT|EXEC(?:UTE)?|EXISTS|EXIT|EXPLAIN|EXTENDED|FETCH|FIELDS|FILE|FILLFACTOR|FIRST|FIXED|FLOAT|FOLLOWING|FOR(?: EACH ROW)?|FORCE|FOREIGN|FREETEXT(?:TABLE)?|FROM|FULL|FUNCTION|GEOMETRY(?:COLLECTION)?|GLOBAL|GOTO|GRANT|GROUP|HANDLER|HASH|HAVING|HOLDLOCK|HOUR|IDENTITY(?:_INSERT|COL)?|IF|IGNORE|IMPORT|INDEX|INFILE|INNER|INNODB|INOUT|INSERT|INT|INTEGER|INTERSECT|INTERVAL|INTO|INVOKER|ISOLATION|ITERATE|JOIN|kwdS?|KILL|LANGUAGE|LAST|LEAVE|LEFT|LEVEL|LIMIT|LINENO|LINES|LINESTRING|LOAD|LOCAL|LOCK|LONG(?:BLOB|TEXT)|LOOP|MATCH(?:ED)?|MEDIUM(?:BLOB|INT|TEXT)|MERGE|MIDDLEINT|MINUTE|MODE|MODIFIES|MODIFY|MONTH|MULTI(?:LINESTRING|POINT|POLYGON)|NATIONAL|NATURAL|NCHAR|NEXT|NO|NONCLUSTERED|NULLIF|NUMERIC|OFF?|OFFSETS?|ON|OPEN(?:DATASOURCE|QUERY|ROWSET)?|OPTIMIZE|OPTION(?:ALLY)?|ORDER|OUT(?:ER|FILE)?|OVER|PARTIAL|PARTITION|PERCENT|PIVOT|PLAN|POINT|POLYGON|PRECEDING|PRECISION|PREPARE|PREV|PRIMARY|PRINT|PRIVILEGES|PROC(?:EDURE)?|PUBLIC|PURGE|QUICK|RAISERROR|READS?|REAL|RECONFIGURE|REFERENCES|RELEASE|RENAME|REPEAT(?:ABLE)?|REPLACE|REPLICATION|REQUIRE|RESIGNAL|RESTORE|RESTRICT|RETURN(?:S|ING)?|REVOKE|RIGHT|ROLLBACK|ROUTINE|ROW(?:COUNT|GUIDCOL|S)?|RTREE|RULE|SAVE(?:POINT)?|SCHEMA|SECOND|SELECT|SERIAL(?:IZABLE)?|SESSION(?:_USER)?|SET(?:USER)?|SHARE|SHOW|SHUTDOWN|SIMPLE|SMALLINT|SNAPSHOT|SOME|SONAME|SQL|START(?:ING)?|STATISTICS|STATUS|STRIPED|SYSTEM_USER|TABLES?|TABLESPACE|TEMP(?:ORARY|TABLE)?|TERMINATED|TEXT(?:SIZE)?|THEN|TIME(?:STAMP)?|TINY(?:BLOB|INT|TEXT)|TOP?|TRAN(?:SACTIONS?)?|TRIGGER|TRUNCATE|TSEQUAL|TYPES?|UNBOUNDED|UNCOMMITTED|UNDEFINED|UNION|UNIQUE|UNLOCK|UNPIVOT|UNSIGNED|UPDATE(?:TEXT)?|USAGE|USE|USER|USING|VALUES?|VAR(?:BINARY|CHAR|CHARACTER|YING)|VIEW|WAITFOR|WARNINGS|WHEN|WHERE|WHILE|WITH(?: ROLLUP|IN)?|WORK|WRITE(?:TEXT)?|YEAR)\b/g},{type:"num",match:/\.?\d[\d.oxa-fA-F-]*|\bNULL\b/g},{type:"bool",match:/\b(TRUE|FALSE)\b/g},{type:"oper",match:/[-+*\/=%^~]|&&?|\|\|?|!=?|<(?:=>?|<|>)?|>[>=]?|\b(?:AND|BETWEEN|DIV|IN|ILIKE|IS|LIKE|NOT|OR|REGEXP|RLIKE|SOUNDS LIKE|XOR)\b/g},{type:"var",match:/@\S+/g}];export{E as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var t=[{type:"err",match:/\b(TODO|FIXME|DEBUG|OPTIMIZE|WARNING|XXX|BUG)\b/g},{type:"class",match:/\bIDEA\b/g},{type:"insert",match:/\b(CHANGED|FIX|CHANGE)\b/g},{type:"oper",match:/\bQUESTION\b/g}];let e="cmnt";export{t as default,e as type};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var t=[{match:/#.*/g,sub:"todo"},{type:"str",match:/("""|''')((?!\1)[^]|\\[^])*\1?/g},{expand:"str"},{type:"section",match:/^\[.+\]\s*$/gm},{type:"num",match:/\b(inf|nan)\b|\d[\d:ZT.-]*/g},{expand:"num"},{type:"bool",match:/\b(true|false)\b/g},{type:"oper",match:/[+,.=-]/g},{type:"var",match:/\w+(?= \=)/g}];export{t as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import e from"./js.js";var t=[{type:"type",match:/:\s*(any|void|number|boolean|string|object|never|enum)\b/g},{type:"kwd",match:/\b(type|namespace|typedef|interface|public|private|protected|implements|declare|abstract|readonly)\b/g},...e];export{t as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var t=[{match:/^#.*/gm,sub:"todo"},{type:"class",match:/^\w+(?=:?)/gm},{type:"num",match:/:\d+/g},{type:"oper",match:/[:/&?]|\w+=/g},{type:"func",match:/[.\w]+@|#[\w]+$/gm},{type:"var",match:/\w+\.\w+(\.\w+)*/g}];export{t as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
let t="\\s*(\\s+[a-z-]+\\s*(=\\s*([^\"']\\S*|(\"|')(\\\\[^]|(?!\\4)[^])*\\4?)?)?\\s*)*",a={match:RegExp(`</?[a-z_-]+${t}/?>`,"g"),sub:[{type:"var",match:/^<\/?[^\s>\/]+/g,sub:[{type:"oper",match:/^<\/?/g}]},{type:"str",match:/=\s*([^"']\S*|("|')(\\[^]|(?!\2)[^])*\2?)/g,sub:[{type:"oper",match:/^=/g}]},{type:"oper",match:/\/?>/g},{type:"class",match:/[a-z-]+/gi}]};var s=[{match:/<!--((?!-->)[^])*-->/g,sub:"todo"},{type:"class",match:RegExp(`<\\?xml${t}\\?>`,"gi"),sub:[{type:"oper",match:/^<\?|\?>$/g},{type:"str",match:/"[^"]*"|'[^']*'/g},{type:"var",match:/xml/gi}]},{type:"class",match:/<!\[CDATA\[[\s\S]*?\]\]>/gi},a,{type:"var",match:/&(#x?)?[\da-z]{1,8};/gi}];export{s as default,t as property,a as xmlElement};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var t=[{match:/#.*/g,sub:"todo"},{expand:"str"},{type:"str",match:/(>|\|)\r?\n((\s[^\n]*)?(\r?\n|$))*/g},{type:"type",match:/!![a-z]+/g},{type:"bool",match:/\b(Yes|No)\b/g},{type:"oper",match:/[+:-]/g},{expand:"num"},{type:"var",match:/[a-zA-Z]\w*(?=:)/g}];export{t as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});exports.default={num:{type:"num",match:/(\.e?|\b)\d(e-|[\d.oxa-fA-F_])*(\.|\b)/g},str:{type:"str",match:/(["'])(\\[^]|(?!\1)[^\r\n\\])*\1?/g},strDouble:{type:"str",match:/"((?!")[^\r\n\\]|\\[^])*"?/g}};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const e=[["bash",[/#!(\/usr)?\/bin\/bash/g,500],[/\b(if|elif|then|fi|echo)\b|\$/g,10]],["html",[/<\/?[a-z-]+[^\n>]*>/g,10],[/^\s+<!DOCTYPE\s+html/g,500]],["http",[/^(GET|HEAD|POST|PUT|DELETE|PATCH|HTTP)\b/g,500]],["js",[/\b(console|await|async|function|export|import|this|class|for|let|const|map|join|require)\b/g,10]],["ts",[/\b(console|await|async|function|export|import|this|class|for|let|const|map|join|require|implements|interface|namespace)\b/g,10]],["py",[/\b(def|print|class|and|or|lambda)\b/g,10]],["sql",[/\b(SELECT|INSERT|FROM)\b/g,50]],["pl",[/#!(\/usr)?\/bin\/perl/g,500],[/\b(use|print)\b|\$/g,10]],["lua",[/#!(\/usr)?\/bin\/lua/g,500]],["make",[/\b(ifneq|endif|if|elif|then|fi|echo|.PHONY|^[a-z]+ ?:$)\b|\$/gm,10]],["uri",[/https?:|mailto:|tel:|ftp:/g,30]],["css",[/^(@import|@page|@media|(\.|#)[a-z]+)/gm,20]],["diff",[/^[+><-]/gm,10],[/^@@ ?[-+,0-9 ]+ ?@@/gm,25]],["md",[/^(>|\t\*|\t\d+.)/gm,10],[/\[.*\](.*)/g,10]],["docker",[/^(FROM|ENTRYPOINT|RUN)/gm,500]],["xml",[/<\/?[a-z-]+[^\n>]*>/g,10],[/^<\?xml/g,500]],["c",[/#include\b|\bprintf\s+\(/g,100]],["rs",[/^\s+(use|fn|mut|match)\b/gm,100]],["go",[/\b(func|fmt|package)\b/g,100]],["java",[/^import\s+java/gm,500]],["asm",[/^(section|global main|extern|\t(call|mov|ret))/gm,100]],["css",[/^(@import|@page|@media|(\.|#)[a-z]+)/gm,20]],["json",[/\b(true|false|null)\b/g,10]],["yaml",[/^(\s+)?[a-z]+:/gm,10]]];exports.detectLanguage=t=>e.map((([e,...a])=>[e,a.reduce(((e,[a,s])=>e+[...t.matchAll(a)].length*s),0)])).filter((([e,t])=>t>20)).sort(((e,t)=>t[1]-e[1]))[0]?.[0]||"plain";
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/////////// typedef.js ///////////
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Supported languages.
|
|
5
|
+
*/
|
|
6
|
+
export type ShjLanguage = 'asm'|'bash'|'bf'|'c'|'css'|'csv'|'diff'|'docker'|'git'|'go'|'html'|'http'|'ini'|'java'|'js'|'jsdoc'|'json'|'leanpub-md'|'log'|'lua'|'make'|'md'|'pl'|'plain'|'py'|'regex'|'rs'|'sql'|'todo'|'toml'|'ts'|'uri'|'xml'|'yaml';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Themes supported in the browser.
|
|
10
|
+
*/
|
|
11
|
+
export type ShjBrowserTheme = 'atom-dark'|'github-dark'|'github-dim'|'dark'|'default'|'github-light'|'visual-studio-dark';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Languages supported in the terminal.
|
|
15
|
+
*/
|
|
16
|
+
export type ShjTerminalTheme = 'default'|'atom-dark';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* * `inline` inside `code` element
|
|
20
|
+
* * `oneline` inside `div` element and containing only one line
|
|
21
|
+
* * `multiline` inside `div` element
|
|
22
|
+
*/
|
|
23
|
+
export type ShjDisplayMode = 'inline'|'oneline'|'multiline';
|
|
24
|
+
|
|
25
|
+
export type ShjToken = 'deleted'|'err'|'var'|'section'|'kwd'|'class'|'cmnt'|'insert'|'type'|'func'|'bool'|'num'|'oper'|'str'|'esc';
|
|
26
|
+
|
|
27
|
+
export interface ShjOptions {
|
|
28
|
+
/**
|
|
29
|
+
* Indicates whether to hide line numbers.
|
|
30
|
+
* @default false
|
|
31
|
+
*/
|
|
32
|
+
hideLineNumbers: boolean;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/////////// Custom Types ///////////
|
|
36
|
+
|
|
37
|
+
export type ShjLanguageComponent =
|
|
38
|
+
| { type: string; match: RegExp }
|
|
39
|
+
| { extand: string }
|
|
40
|
+
| {
|
|
41
|
+
match: RegExp;
|
|
42
|
+
sub:
|
|
43
|
+
| string
|
|
44
|
+
| ((code: string) => {
|
|
45
|
+
type: string;
|
|
46
|
+
sub: Array<{ match: RegExp; sub: string | Promise<string> }>
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export type ShjLanguageDefinition = Array<ShjLanguageComponent>;
|
|
51
|
+
|
|
52
|
+
/////////// index.js ///////////
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Find the tokens in the given code and call the callback
|
|
56
|
+
* @param src The code
|
|
57
|
+
* @param lang The language of the code
|
|
58
|
+
* @param callback The callback function
|
|
59
|
+
* this function will be given
|
|
60
|
+
* * the text of the token
|
|
61
|
+
* * the type of the token
|
|
62
|
+
*/
|
|
63
|
+
export declare function tokenize<T extends string = ShjLanguage>(
|
|
64
|
+
src: string,
|
|
65
|
+
lang: T,
|
|
66
|
+
callback: (value: string, token: ShjToken) => void
|
|
67
|
+
): Promise<void>;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Highlight a string passed as argument and return it
|
|
71
|
+
* @example
|
|
72
|
+
* elm.innerHTML = await highlightText(code, 'js');
|
|
73
|
+
* @param src The code
|
|
74
|
+
* @param lang The language of the code
|
|
75
|
+
* @param multiline If it is multiline, it will add a wrapper for the line numbering and header
|
|
76
|
+
* @param Customization options
|
|
77
|
+
* @returns The highlighted string
|
|
78
|
+
*/
|
|
79
|
+
export declare function highlightText<T extends string = ShjLanguage>(
|
|
80
|
+
src: string,
|
|
81
|
+
lang: T,
|
|
82
|
+
multiline?: boolean,
|
|
83
|
+
opt?: ShjOptions
|
|
84
|
+
): Promise<string>;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Highlight a DOM element by getting the new innerHTML with highlightText
|
|
88
|
+
* @param elm The DOM element
|
|
89
|
+
* @param lang The language of the code (seaching by default on `elm` for a 'shj-lang-' class)
|
|
90
|
+
* @param mode The display mode (guessed by default)
|
|
91
|
+
* @param opt Customization options
|
|
92
|
+
*/
|
|
93
|
+
export declare function highlightElement<T extends string = ShjLanguage>(
|
|
94
|
+
elm: Element,
|
|
95
|
+
lang?: T,
|
|
96
|
+
mode?: ShjDisplayMode,
|
|
97
|
+
opt?: ShjOptions
|
|
98
|
+
): Promise<void>;
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Call highlightElement on element with a css class starting with `shj-lang-`
|
|
102
|
+
* @param opt Customization options
|
|
103
|
+
*/
|
|
104
|
+
export declare function highlightAll(opt?: ShjOptions): Promise<void>;
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Load a language and add it to the langs object
|
|
108
|
+
* @param name The name of the language
|
|
109
|
+
* @param module Module that has the language as the default export
|
|
110
|
+
*/
|
|
111
|
+
export declare function loadLanguage(
|
|
112
|
+
name: string,
|
|
113
|
+
module: { default: ShjLanguageDefinition }
|
|
114
|
+
): void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./common.js");const s={},r=(e="")=>e.replaceAll("&","&").replaceAll?.("<","<").replaceAll?.(">",">"),n=(e,s)=>s?`<span class="shj-syn-${s}">${e}</span>`:e;async function a(r,n,t){try{let u,l,i,g={},o=[],c=0,j="string"==typeof n?await(s[n]??=function(e){switch(e){case"./languages/asm.js":return Promise.resolve().then((function(){return require("./languages/asm.js")}));case"./languages/bash.js":return Promise.resolve().then((function(){return require("./languages/bash.js")}));case"./languages/bf.js":return Promise.resolve().then((function(){return require("./languages/bf.js")}));case"./languages/c.js":return Promise.resolve().then((function(){return require("./languages/c.js")}));case"./languages/css.js":return Promise.resolve().then((function(){return require("./languages/css.js")}));case"./languages/csv.js":return Promise.resolve().then((function(){return require("./languages/csv.js")}));case"./languages/diff.js":return Promise.resolve().then((function(){return require("./languages/diff.js")}));case"./languages/docker.js":return Promise.resolve().then((function(){return require("./languages/docker.js")}));case"./languages/git.js":return Promise.resolve().then((function(){return require("./languages/git.js")}));case"./languages/go.js":return Promise.resolve().then((function(){return require("./languages/go.js")}));case"./languages/html.js":return Promise.resolve().then((function(){return require("./languages/html.js")}));case"./languages/http.js":return Promise.resolve().then((function(){return require("./languages/http.js")}));case"./languages/ini.js":return Promise.resolve().then((function(){return require("./languages/ini.js")}));case"./languages/java.js":return Promise.resolve().then((function(){return require("./languages/java.js")}));case"./languages/js.js":return Promise.resolve().then((function(){return require("./languages/js.js")}));case"./languages/js_template_literals.js":return Promise.resolve().then((function(){return require("./languages/js_template_literals.js")}));case"./languages/jsdoc.js":return Promise.resolve().then((function(){return require("./languages/jsdoc.js")}));case"./languages/json.js":return Promise.resolve().then((function(){return require("./languages/json.js")}));case"./languages/leanpub-md.js":return Promise.resolve().then((function(){return require("./languages/leanpub-md.js")}));case"./languages/log.js":return Promise.resolve().then((function(){return require("./languages/log.js")}));case"./languages/lua.js":return Promise.resolve().then((function(){return require("./languages/lua.js")}));case"./languages/make.js":return Promise.resolve().then((function(){return require("./languages/make.js")}));case"./languages/md.js":return Promise.resolve().then((function(){return require("./languages/md.js")}));case"./languages/pl.js":return Promise.resolve().then((function(){return require("./languages/pl.js")}));case"./languages/plain.js":return Promise.resolve().then((function(){return require("./languages/plain.js")}));case"./languages/py.js":return Promise.resolve().then((function(){return require("./languages/py.js")}));case"./languages/regex.js":return Promise.resolve().then((function(){return require("./languages/regex.js")}));case"./languages/rs.js":return Promise.resolve().then((function(){return require("./languages/rs.js")}));case"./languages/sql.js":return Promise.resolve().then((function(){return require("./languages/sql.js")}));case"./languages/todo.js":return Promise.resolve().then((function(){return require("./languages/todo.js")}));case"./languages/toml.js":return Promise.resolve().then((function(){return require("./languages/toml.js")}));case"./languages/ts.js":return Promise.resolve().then((function(){return require("./languages/ts.js")}));case"./languages/uri.js":return Promise.resolve().then((function(){return require("./languages/uri.js")}));case"./languages/xml.js":return Promise.resolve().then((function(){return require("./languages/xml.js")}));case"./languages/yaml.js":return Promise.resolve().then((function(){return require("./languages/yaml.js")}));default:return new Promise((function(s,r){("function"==typeof queueMicrotask?queueMicrotask:setTimeout)(r.bind(null,new Error("Unknown variable dynamic import: "+e)))}))}}(`./languages/${n}.js`)):n,h=[..."string"==typeof n?j.default:n.sub];for(;c<r.length;){for(g.index=null,u=h.length;u-- >0;){if(l=h[u].expand?e.default[h[u].expand]:h[u],void 0===o[u]||o[u].match.index<c){if(l.match.lastIndex=c,i=l.match.exec(r),null===i){h.splice(u,1),o.splice(u,1);continue}o[u]={match:i,lastIndex:l.match.lastIndex}}o[u].match[0]&&(o[u].match.index<=g.index||null===g.index)&&(g={part:l,index:o[u].match.index,match:o[u].match[0],end:o[u].lastIndex})}if(null===g.index)break;t(r.slice(c,g.index),j.type),c=g.end,g.part.sub?await a(g.match,"string"==typeof g.part.sub?g.part.sub:"function"==typeof g.part.sub?g.part.sub(g.match):g.part,t):t(g.match,g.part.type)}t(r.slice(c,r.length),j.type)}catch{t(r)}}async function t(e,s,t=!0,u={}){let l="";return await a(e,s,((e,s)=>l+=n(r(e),s))),t?`<div><div class="shj-numbers">${"<div></div>".repeat(!u.hideLineNumbers&&e.split("\n").length)}</div><div>${l}</div></div>`:l}async function u(e,s=e.className.match(/shj-lang-([\w-]+)/)?.[1],r,n){let a=e.textContent;r??=("CODE"==e.tagName?"in":a.split("\n").length<2?"one":"multi")+"line",e.dataset.lang=s,e.className=`${[...e.classList].filter((e=>!e.startsWith("shj-")||e.startsWith("shj-mode-"))).join(" ")} shj-lang-${s} shj-${r}`,e.innerHTML=await t(a,s,"multiline"==r,n)}exports.highlightAll=async e=>document.querySelectorAll('[class*="shj-lang-"]').forEach((s=>u(s,void 0,void 0,e))),exports.highlightElement=u,exports.highlightText=t,exports.loadLanguage=(e,r)=>{s[e]=r},exports.tokenize=a;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});exports.default=[{type:"cmnt",match:/;.*/gm},{expand:"str"},{expand:"num"},{type:"kwd",match:/^[a-z]+\s+[a-z.]+/gm,sub:[{type:"func",match:/^[a-z]+/g}]},{type:"kwd",match:/^\t*[a-z]+/gm},{match:/%|\$/g,type:"oper"}];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});let e={type:"var",match:/\$\w+|\${[^}]*}|\$\([^)]*\)/g};var t=[{sub:"todo",match:/#.*/g},{type:"str",match:/(["'])((?!\1)[^\r\n\\]|\\[^])*\1?/g,sub:[e]},{type:"kwd",match:/-[a-zA-Z]+|$<|[&|;]+|\b(unset|readonly|shift|export|if|fi|else|elif|while|do|done|for|until|case|esac|break|continue|exit|return|trap|wait|eval|exec|then|declare|enable|local|select|typeset|time|add|remove|install|update|delete)\b/g},{expand:"num"},{type:"func",match:/\b(set|alias|bg|bind|builtin|caller|command|compgen|complete|dirs|disown|echo|enable|eval|exec|exit|fc|fg|getopts|hash|help|history|jobs|kill|let|logout|popd|printf|pushd|pwd|read|set|shift|shopt|source|suspend|test|times|trap|type|ulimit|umask|unalias|unset)\b/g},{type:"bool",match:/\b(true|false)\b/g},{type:"func",match:/[a-z_]+(?=\s*\()/g},{type:"oper",match:/[=(){}<>+*/!?~^-]+/g},{type:"var",match:/\w+(?=\s*=)/g},e];exports.default=t;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});exports.default=[{match:/[^\[\->+.<\]\s].*/g,sub:"todo"},{type:"func",match:/\.+/g},{type:"kwd",match:/[<>]+/g},{type:"oper",match:/[+-]+/g}];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});exports.default=[{match:/\/\/.*\n?|\/\*((?!\*\/)[^])*(\*\/)?/g,sub:"todo"},{expand:"str"},{expand:"num"},{type:"kwd",match:/#\s*include (<.*>|".*")/g,sub:[{type:"str",match:/(<|").*/g}]},{match:/asm\s*{[^}]*}/g,sub:[{type:"kwd",match:/^asm/g},{match:/[^{}]*(?=}$)/g,sub:"asm"}]},{type:"kwd",match:/\*|&|#[a-z]+\b|\b(asm|auto|double|int|struct|break|else|long|switch|case|enum|register|typedef|char|extern|return|union|const|float|short|unsigned|continue|for|signed|void|default|goto|sizeof|volatile|do|if|static|while)\b/g},{type:"oper",match:/[/*+:?&|%^~=!,<>.^-]+/g},{type:"func",match:/[a-zA-Z_][\w_]*(?=\s*\()/g},{type:"class",match:/\b[A-Z][\w_]*\b/g}];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});exports.default=[{match:/\/\*((?!\*\/)[^])*(\*\/)?/g,sub:"todo"},{expand:"str"},{type:"kwd",match:/@\w+\b|\b(and|not|only|or)\b|\b[a-z-]+(?=[^{}]*{)/g},{type:"var",match:/\b[\w-]+(?=\s*:)|(::?|\.)[\w-]+(?=[^{}]*{)/g},{type:"func",match:/#[\w-]+(?=[^{}]*{)/g},{type:"num",match:/#[\da-f]{3,8}/g},{type:"num",match:/\d+(\.\d+)?(cm|mm|in|px|pt|pc|em|ex|ch|rem|vm|vh|vmin|vmax|%)?/g,sub:[{type:"var",match:/[a-z]+|%/g}]},{match:/url\([^)]*\)/g,sub:[{type:"func",match:/url(?=\()/g},{type:"str",match:/[^()]+/g}]},{type:"func",match:/\b[a-zA-Z]\w*(?=\s*\()/g},{type:"num",match:/\b[a-z-]+\b/g}];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});exports.default=[{expand:"strDouble"},{type:"oper",match:/,/g}];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});exports.default=[{type:"deleted",match:/^[-<].*/gm},{type:"insert",match:/^[+>].*/gm},{type:"kwd",match:/!.*/gm},{type:"section",match:/^@@.*@@$|^\d.*|^([*-+])\1\1.*/gm}];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=[{type:"kwd",match:/^(FROM|RUN|CMD|LABEL|MAINTAINER|EXPOSE|ENV|ADD|COPY|ENTRYPOINT|VOLUME|USER|WORKDIR|ARG|ONBUILD|STOPSIGNAL|HEALTHCHECK|SHELL)\b/gim},...require("./bash.js").default];exports.default=e;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=[{match:/^#.*/gm,sub:"todo"},{expand:"str"},...require("./diff.js").default,{type:"func",match:/^(\$ )?git(\s.*)?$/gm},{type:"kwd",match:/^commit \w+$/gm}];exports.default=e;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});exports.default=[{match:/\/\/.*\n?|\/\*((?!\*\/)[^])*(\*\/)?/g,sub:"todo"},{expand:"str"},{expand:"num"},{type:"kwd",match:/\*|&|\b(break|case|chan|const|continue|default|defer|else|fallthrough|for|func|go|goto|if|import|interface|map|package|range|return|select|struct|switch|type|var)\b/g},{type:"func",match:/[a-zA-Z_][\w_]*(?=\s*\()/g},{type:"class",match:/\b[A-Z][\w_]*\b/g},{type:"oper",match:/[+\-*\/%&|^~=!<>.^-]+/g}];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./xml.js"),t=[{type:"class",match:/<!DOCTYPE("[^"]*"|'[^']*'|[^"'>])*>/gi,sub:[{type:"str",match:/"[^"]*"|'[^']*'/g},{type:"oper",match:/^<!|>$/g},{type:"var",match:/DOCTYPE/gi}]},{match:RegExp(`<style${e.property}>((?!</style>)[^])*</style\\s*>`,"g"),sub:[{match:RegExp(`^<style${e.property}>`,"g"),sub:e.xmlElement.sub},{match:RegExp(`${e.xmlElement.match}|[^]*(?=</style\\s*>$)`,"g"),sub:"css"},e.xmlElement]},{match:RegExp(`<script${e.property}>((?!<\/script>)[^])*</script\\s*>`,"g"),sub:[{match:RegExp(`^<script${e.property}>`,"g"),sub:e.xmlElement.sub},{match:RegExp(`${e.xmlElement.match}|[^]*(?=</script\\s*>$)`,"g"),sub:"js"},e.xmlElement]},...e.default];exports.default=t;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=[{type:"kwd",match:/^(GET|HEAD|POST|PUT|DELETE|CONNECT|OPTIONS|TRACE|PATCH|PRI|SEARCH)\b/gm},{expand:"str"},{type:"section",match:/\bHTTP\/[\d.]+\b/g},{expand:"num"},{type:"oper",match:/[,;:=]/g},{type:"var",match:/[a-zA-Z][\w-]*(?=:)/g},{match:/\n\n[^]*/g,sub:require("../detect.js").detectLanguage}];exports.default=e;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});exports.default=[{match:/(^[ \f\t\v]*)[#;].*/gm,sub:"todo"},{type:"str",match:/.*/g},{type:"var",match:/.*(?==)/g},{type:"section",match:/^\s*\[.+\]\s*$/gm},{type:"oper",match:/=/g}];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});exports.default=[{match:/\/\/.*\n?|\/\*((?!\*\/)[^])*(\*\/)?/g,sub:"todo"},{expand:"str"},{expand:"num"},{type:"kwd",match:/\b(abstract|assert|boolean|break|byte|case|catch|char|class|continue|const|default|do|double|else|enum|exports|extends|final|finally|float|for|goto|if|implements|import|instanceof|int|interface|long|module|native|new|package|private|protected|public|requires|return|short|static|strictfp|super|switch|synchronized|this|throw|throws|transient|try|var|void|volatile|while)\b/g},{type:"oper",match:/[/*+:?&|%^~=!,<>.^-]+/g},{type:"func",match:/[a-zA-Z_][\w_]*(?=\s*\()/g},{type:"class",match:/\b[A-Z][\w_]*\b/g}];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});exports.default=[{match:/\/\*\*((?!\*\/)[^])*(\*\/)?/g,sub:"jsdoc"},{match:/\/\/.*\n?|\/\*((?!\*\/)[^])*(\*\/)?/g,sub:"todo"},{expand:"str"},{match:/`((?!`)[^]|\\[^])*`?/g,sub:"js_template_literals"},{type:"kwd",match:/=>|\b(this|set|get|as|async|await|break|case|catch|class|const|constructor|continue|debugger|default|delete|do|else|enum|export|extends|finally|for|from|function|if|implements|import|in|instanceof|interface|let|var|of|new|package|private|protected|public|return|static|super|switch|throw|throws|try|typeof|void|while|with|yield)\b/g},{match:/\/((?!\/)[^\r\n\\]|\\.)+\/[dgimsuy]*/g,sub:"regex"},{expand:"num"},{type:"num",match:/\b(NaN|null|undefined|[A-Z][A-Z_]*)\b/g},{type:"bool",match:/\b(true|false)\b/g},{type:"oper",match:/[/*+:?&|%^~=!,<>.^-]+/g},{type:"class",match:/\b[A-Z][\w_]*\b/g},{type:"func",match:/[a-zA-Z$_][\w$_]*(?=\s*((\?\.)?\s*\(|=\s*(\(?[\w,{}\[\])]+\)? =>|function\b)))/g}];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=[{match:new class{exec(e){let t,s=this.lastIndex,r=t=>{for(;++s<e.length-2;)if("{"==e[s])r();else if("}"==e[s])return};for(;s<e.length;s++)if("\\"!=e[s-1]&&"$"==e[s]&&"{"==e[s+1])return t=s++,r(),this.lastIndex=s+1,{index:t,0:e.slice(t,s+1)};return null}},sub:[{type:"kwd",match:/^\${|}$/g},{match:/(?!^\$|{)[^]+(?=}$)/g,sub:"js"}]}];exports.default=e,exports.type="str";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=[{type:"kwd",match:/@\w+/g},{type:"class",match:/{[\w\s|<>,.@\[\]]+}/g},{type:"var",match:/\[[\w\s="']+\]/g},...require("./todo.js").default];exports.default=e,exports.type="cmnt";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});exports.default=[{type:"var",match:/("|')?[a-zA-Z]\w*\1(?=\s*:)/g},{expand:"str"},{expand:"num"},{type:"num",match:/\bnull\b/g},{type:"bool",match:/\b(true|false)\b/g}];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./md.js"),t=require("../detect.js"),a=[{type:"insert",match:/(leanpub-start-insert)((?!leanpub-end-insert)[^])*(leanpub-end-insert)?/g,sub:[{type:"insert",match:/leanpub-(start|end)-insert/g},{match:/(?!leanpub-start-insert)((?!leanpub-end-insert)[^])*/g,sub:t.detectLanguage}]},{type:"deleted",match:/(leanpub-start-delete)((?!leanpub-end-delete)[^])*(leanpub-end-delete)?/g,sub:[{type:"deleted",match:/leanpub-(start|end)-delete/g},{match:/(?!leanpub-start-delete)((?!leanpub-end-delete)[^])*/g,sub:t.detectLanguage}]},...e.default];exports.default=a;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});exports.default=[{type:"cmnt",match:/^#.*/gm},{expand:"strDouble"},{expand:"num"},{type:"err",match:/\b(err(or)?|[a-z_-]*exception|warn|warning|failed|ko|invalid|not ?found|alert|fatal)\b/gi},{type:"num",match:/\b(null|undefined)\b/gi},{type:"bool",match:/\b(false|true|yes|no)\b/gi},{type:"oper",match:/\.|,/g}];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});exports.default=[{match:/^#!.*|--(\[(=*)\[((?!--\]\2\])[^])*--\]\2\]|.*)/g,sub:"todo"},{expand:"str"},{type:"kwd",match:/\b(and|break|do|else|elseif|end|for|function|if|in|local|not|or|repeat|return|then|until|while)\b/g},{type:"bool",match:/\b(true|false|nil)\b/g},{type:"oper",match:/[+*/%^#=~<>:,.-]+/g},{expand:"num"},{type:"func",match:/[a-z_]+(?=\s*[({])/g}];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});exports.default=[{match:/^\s*#.*/gm,sub:"todo"},{expand:"str"},{type:"oper",match:/[${}()]+/g},{type:"class",match:/.PHONY:/gm},{type:"section",match:/^[\w.]+:/gm},{type:"kwd",match:/\b(ifneq|endif)\b/g},{expand:"num"},{type:"var",match:/[A-Z_]+(?=\s*=)/g},{match:/^.*$/gm,sub:"bash"}];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("../detect.js"),e=[{type:"cmnt",match:/^>.*|(=|-)\1+/gm},{type:"class",match:/\*\*((?!\*\*).)*\*\*/g},{match:/```((?!```)[^])*\n```/g,sub:e=>({type:"kwd",sub:[{match:/\n[^]*(?=```)/g,sub:e.split("\n")[0].slice(3)||t.detectLanguage(e)}]})},{type:"str",match:/`[^`]*`/g},{type:"var",match:/~~((?!~~).)*~~/g},{type:"kwd",match:/_[^_]*_|\*[^*]*\*/g},{type:"kwd",match:/^\s*(\*|\d+\.)\s/gm},{type:"oper",match:/\[[^\]]*]/g},{type:"func",match:/\([^)]*\)/g}];exports.default=e;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});exports.default=[{match:/#.*/g,sub:"todo"},{type:"str",match:/(["'])(\\[^]|(?!\1)[^])*\1?/g},{expand:"num"},{type:"kwd",match:/\b(any|break|continue|default|delete|die|do|else|elsif|eval|for|foreach|given|goto|if|last|local|my|next|our|package|print|redo|require|return|say|state|sub|switch|undef|unless|until|use|when|while|not|and|or|xor)\b/g},{type:"oper",match:/[-+*/%~!&<>|=?,]+/g},{type:"func",match:/[a-z_]+(?=\s*\()/g}];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});exports.default=[{expand:"strDouble"}];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});exports.default=[{match:/#.*/g,sub:"todo"},{match:/("""|''')(\\[^]|(?!\1)[^])*\1?/g,sub:"todo"},{type:"str",match:/f("|')(\\[^]|(?!\1).)*\1?|f((["'])\4\4)(\\[^]|(?!\3)[^])*\3?/gi,sub:[{type:"var",match:/{[^{}]*}/g,sub:[{match:/(?!^{)[^]*(?=}$)/g,sub:"py"}]}]},{expand:"str"},{type:"kwd",match:/\b(and|as|assert|break|class|continue|def|del|elif|else|except|finally|for|from|global|if|import|in|is|lambda|nonlocal|not|or|pass|raise|return|try|while|with|yield)\b/g},{type:"bool",match:/\b(False|True|None)\b/g},{expand:"num"},{type:"func",match:/[a-z_]+(?=\s*\()/g},{type:"oper",match:/[-/*+<>,=!&|^%]+/g},{type:"class",match:/\b[A-Z][\w_]*\b/g}];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});exports.default=[{match:/^(?!\/).*/gm,sub:"todo"},{type:"num",match:/\[((?!\])[^\\]|\\.)*\]/g},{type:"kwd",match:/\||\^|\$|\\.|\w+($|\r|\n)/g},{type:"var",match:/\*|\+|\{\d+,\d+\}/g}],exports.type="oper";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});exports.default=[{match:/\/\/.*\n?|\/\*((?!\*\/)[^])*(\*\/)?/g,sub:"todo"},{expand:"str"},{expand:"num"},{type:"kwd",match:/\b(as|break|const|continue|crate|else|enum|extern|false|fn|for|if|impl|in|let|loop|match|mod|move|mut|pub|ref|return|self|Self|static|struct|super|trait|true|type|unsafe|use|where|while|async|await|dyn|abstract|become|box|do|final|macro|override|priv|typeof|unsized|virtual|yield|try)\b/g},{type:"oper",match:/[/*+:?&|%^~=!,<>.^-]+/g},{type:"class",match:/\b[A-Z][\w_]*\b/g},{type:"func",match:/[a-zA-Z_][\w_]*(?=\s*!?\s*\()/g}];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});exports.default=[{match:/--.*\n?|\/\*((?!\*\/)[^])*(\*\/)?/g,sub:"todo"},{expand:"str"},{type:"func",match:/\b(AVG|COUNT|FIRST|FORMAT|LAST|LCASE|LEN|MAX|MID|MIN|MOD|NOW|ROUND|SUM|UCASE)(?=\s*\()/g},{type:"kwd",match:/\b(ACTION|ADD|AFTER|ALGORITHM|ALL|ALTER|ANALYZE|ANY|APPLY|AS|ASC|AUTHORIZATION|AUTO_INCREMENT|BACKUP|BDB|BEGIN|BERKELEYDB|BIGINT|BINARY|BIT|BLOB|BOOL|BOOLEAN|BREAK|BROWSE|BTREE|BULK|BY|CALL|CASCADED?|CASE|CHAIN|CHAR(?:ACTER|SET)?|CHECK(?:POINT)?|CLOSE|CLUSTERED|COALESCE|COLLATE|COLUMNS?|COMMENT|COMMIT(?:TED)?|COMPUTE|CONNECT|CONSISTENT|CONSTRAINT|CONTAINS(?:TABLE)?|CONTINUE|CONVERT|CREATE|CROSS|CURRENT(?:_DATE|_TIME|_TIMESTAMP|_USER)?|CURSOR|CYCLE|DATA(?:BASES?)?|DATE(?:TIME)?|DAY|DBCC|DEALLOCATE|DEC|DECIMAL|DECLARE|DEFAULT|DEFINER|DELAYED|DELETE|DELIMITERS?|DENY|DESC|DESCRIBE|DETERMINISTIC|DISABLE|DISCARD|DISK|DISTINCT|DISTINCTROW|DISTRIBUTED|DO|DOUBLE|DROP|DUMMY|DUMP(?:FILE)?|DUPLICATE|ELSE(?:IF)?|ENABLE|ENCLOSED|END|ENGINE|ENUM|ERRLVL|ERRORS|ESCAPED?|EXCEPT|EXEC(?:UTE)?|EXISTS|EXIT|EXPLAIN|EXTENDED|FETCH|FIELDS|FILE|FILLFACTOR|FIRST|FIXED|FLOAT|FOLLOWING|FOR(?: EACH ROW)?|FORCE|FOREIGN|FREETEXT(?:TABLE)?|FROM|FULL|FUNCTION|GEOMETRY(?:COLLECTION)?|GLOBAL|GOTO|GRANT|GROUP|HANDLER|HASH|HAVING|HOLDLOCK|HOUR|IDENTITY(?:_INSERT|COL)?|IF|IGNORE|IMPORT|INDEX|INFILE|INNER|INNODB|INOUT|INSERT|INT|INTEGER|INTERSECT|INTERVAL|INTO|INVOKER|ISOLATION|ITERATE|JOIN|kwdS?|KILL|LANGUAGE|LAST|LEAVE|LEFT|LEVEL|LIMIT|LINENO|LINES|LINESTRING|LOAD|LOCAL|LOCK|LONG(?:BLOB|TEXT)|LOOP|MATCH(?:ED)?|MEDIUM(?:BLOB|INT|TEXT)|MERGE|MIDDLEINT|MINUTE|MODE|MODIFIES|MODIFY|MONTH|MULTI(?:LINESTRING|POINT|POLYGON)|NATIONAL|NATURAL|NCHAR|NEXT|NO|NONCLUSTERED|NULLIF|NUMERIC|OFF?|OFFSETS?|ON|OPEN(?:DATASOURCE|QUERY|ROWSET)?|OPTIMIZE|OPTION(?:ALLY)?|ORDER|OUT(?:ER|FILE)?|OVER|PARTIAL|PARTITION|PERCENT|PIVOT|PLAN|POINT|POLYGON|PRECEDING|PRECISION|PREPARE|PREV|PRIMARY|PRINT|PRIVILEGES|PROC(?:EDURE)?|PUBLIC|PURGE|QUICK|RAISERROR|READS?|REAL|RECONFIGURE|REFERENCES|RELEASE|RENAME|REPEAT(?:ABLE)?|REPLACE|REPLICATION|REQUIRE|RESIGNAL|RESTORE|RESTRICT|RETURN(?:S|ING)?|REVOKE|RIGHT|ROLLBACK|ROUTINE|ROW(?:COUNT|GUIDCOL|S)?|RTREE|RULE|SAVE(?:POINT)?|SCHEMA|SECOND|SELECT|SERIAL(?:IZABLE)?|SESSION(?:_USER)?|SET(?:USER)?|SHARE|SHOW|SHUTDOWN|SIMPLE|SMALLINT|SNAPSHOT|SOME|SONAME|SQL|START(?:ING)?|STATISTICS|STATUS|STRIPED|SYSTEM_USER|TABLES?|TABLESPACE|TEMP(?:ORARY|TABLE)?|TERMINATED|TEXT(?:SIZE)?|THEN|TIME(?:STAMP)?|TINY(?:BLOB|INT|TEXT)|TOP?|TRAN(?:SACTIONS?)?|TRIGGER|TRUNCATE|TSEQUAL|TYPES?|UNBOUNDED|UNCOMMITTED|UNDEFINED|UNION|UNIQUE|UNLOCK|UNPIVOT|UNSIGNED|UPDATE(?:TEXT)?|USAGE|USE|USER|USING|VALUES?|VAR(?:BINARY|CHAR|CHARACTER|YING)|VIEW|WAITFOR|WARNINGS|WHEN|WHERE|WHILE|WITH(?: ROLLUP|IN)?|WORK|WRITE(?:TEXT)?|YEAR)\b/g},{type:"num",match:/\.?\d[\d.oxa-fA-F-]*|\bNULL\b/g},{type:"bool",match:/\b(TRUE|FALSE)\b/g},{type:"oper",match:/[-+*\/=%^~]|&&?|\|\|?|!=?|<(?:=>?|<|>)?|>[>=]?|\b(?:AND|BETWEEN|DIV|IN|ILIKE|IS|LIKE|NOT|OR|REGEXP|RLIKE|SOUNDS LIKE|XOR)\b/g},{type:"var",match:/@\S+/g}];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});exports.default=[{type:"err",match:/\b(TODO|FIXME|DEBUG|OPTIMIZE|WARNING|XXX|BUG)\b/g},{type:"class",match:/\bIDEA\b/g},{type:"insert",match:/\b(CHANGED|FIX|CHANGE)\b/g},{type:"oper",match:/\bQUESTION\b/g}],exports.type="cmnt";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});exports.default=[{match:/#.*/g,sub:"todo"},{type:"str",match:/("""|''')((?!\1)[^]|\\[^])*\1?/g},{expand:"str"},{type:"section",match:/^\[.+\]\s*$/gm},{type:"num",match:/\b(inf|nan)\b|\d[\d:ZT.-]*/g},{expand:"num"},{type:"bool",match:/\b(true|false)\b/g},{type:"oper",match:/[+,.=-]/g},{type:"var",match:/\w+(?= \=)/g}];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=[{type:"type",match:/:\s*(any|void|number|boolean|string|object|never|enum)\b/g},{type:"kwd",match:/\b(type|namespace|typedef|interface|public|private|protected|implements|declare|abstract|readonly)\b/g},...require("./js.js").default];exports.default=e;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});exports.default=[{match:/^#.*/gm,sub:"todo"},{type:"class",match:/^\w+(?=:?)/gm},{type:"num",match:/:\d+/g},{type:"oper",match:/[:/&?]|\w+=/g},{type:"func",match:/[.\w]+@|#[\w]+$/gm},{type:"var",match:/\w+\.\w+(\.\w+)*/g}];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});let t="\\s*(\\s+[a-z-]+\\s*(=\\s*([^\"']\\S*|(\"|')(\\\\[^]|(?!\\4)[^])*\\4?)?)?\\s*)*",e={match:RegExp(`</?[a-z_-]+${t}/?>`,"g"),sub:[{type:"var",match:/^<\/?[^\s>\/]+/g,sub:[{type:"oper",match:/^<\/?/g}]},{type:"str",match:/=\s*([^"']\S*|("|')(\\[^]|(?!\2)[^])*\2?)/g,sub:[{type:"oper",match:/^=/g}]},{type:"oper",match:/\/?>/g},{type:"class",match:/[a-z-]+/gi}]};var s=[{match:/<!--((?!-->)[^])*-->/g,sub:"todo"},{type:"class",match:RegExp(`<\\?xml${t}\\?>`,"gi"),sub:[{type:"oper",match:/^<\?|\?>$/g},{type:"str",match:/"[^"]*"|'[^']*'/g},{type:"var",match:/xml/gi}]},{type:"class",match:/<!\[CDATA\[[\s\S]*?\]\]>/gi},e,{type:"var",match:/&(#x?)?[\da-z]{1,8};/gi}];exports.default=s,exports.property=t,exports.xmlElement=e;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});exports.default=[{match:/#.*/g,sub:"todo"},{expand:"str"},{type:"str",match:/(>|\|)\r?\n((\s[^\n]*)?(\r?\n|$))*/g},{type:"type",match:/!![a-z]+/g},{type:"bool",match:/\b(Yes|No)\b/g},{type:"oper",match:/[+:-]/g},{expand:"num"},{type:"var",match:/[a-zA-Z]\w*(?=:)/g}];
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Highlight a string passed as argument and return a string that can directly be printed
|
|
3
|
+
* @param src The code
|
|
4
|
+
* @param ang The language of the code
|
|
5
|
+
* @returns The highlighted string
|
|
6
|
+
*/
|
|
7
|
+
export declare function highlightText<T extends string = import('.').ShjLanguage>(
|
|
8
|
+
src: string,
|
|
9
|
+
lang: T
|
|
10
|
+
): Promise<string>;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Highlight and print a given string
|
|
14
|
+
* @param src The code
|
|
15
|
+
* @param lang The language of the code
|
|
16
|
+
*/
|
|
17
|
+
export declare function printHighlight<T extends string = import('.').ShjLanguage>(
|
|
18
|
+
src: string,
|
|
19
|
+
lang: T
|
|
20
|
+
): Promise<void>;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Change the current used theme for highlighting
|
|
24
|
+
* @param name The name of the theme
|
|
25
|
+
*/
|
|
26
|
+
export declare function setTheme(name: import('.').ShjBrowserTheme): Promise<void>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./index.js");let t=Promise.resolve().then((function(){return require("./themes/default.js")}));const r=async(r,s)=>{let n="",o=(await t).default;return await e.tokenize(r,s,((e,t)=>n+=t?`${o[t]??""}${e}[0m`:e)),n};exports.highlightText=r,exports.printHighlight=async(e,t)=>console.log(await r(e,t)),exports.setTheme=async e=>t=function(e){switch(e){case"./themes/atom-dark.js":return Promise.resolve().then((function(){return require("./themes/atom-dark.js")}));case"./themes/default.js":return Promise.resolve().then((function(){return require("./themes/default.js")}));case"./themes/termcolor.js":return Promise.resolve().then((function(){return require("./themes/termcolor.js")}));default:return new Promise((function(t,r){("function"==typeof queueMicrotask?queueMicrotask:setTimeout)(r.bind(null,new Error("Unknown variable dynamic import: "+e)))}))}}(`./themes/${e}.js`);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./termcolor.js"),t={deleted:e.default.red,var:e.default.red,err:e.default.red,kwd:e.default.magenta,num:e.default.yellow,class:e.default.yellow,cmnt:e.default.gray,insert:e.default.green,str:e.default.green,bool:e.default.cyan,type:e.default.blue,oper:e.default.blue,section:e.default.magenta,func:e.default.blue};exports.default=t;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./termcolor.js"),t={deleted:e.default.red,var:e.default.red,err:e.default.red,kwd:e.default.red,num:e.default.yellow,class:e.default.yellow,cmnt:e.default.gray,insert:e.default.green,str:e.default.green,bool:e.default.cyan,type:e.default.blue,oper:e.default.blue,section:e.default.magenta,func:e.default.magenta};exports.default=t;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});exports.default={black:"[30m",red:"[31m",green:"[32m",gray:"[90m",yellow:"[33m",blue:"[34m",magenta:"[35m",cyan:"[36m",white:"[37m"};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Highlight a string passed as argument and return a string that can directly be printed
|
|
3
|
+
* @param src The code
|
|
4
|
+
* @param ang The language of the code
|
|
5
|
+
* @returns The highlighted string
|
|
6
|
+
*/
|
|
7
|
+
export declare function highlightText<T extends string = import('.').ShjLanguage>(
|
|
8
|
+
src: string,
|
|
9
|
+
lang: T
|
|
10
|
+
): Promise<string>;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Highlight and print a given string
|
|
14
|
+
* @param src The code
|
|
15
|
+
* @param lang The language of the code
|
|
16
|
+
*/
|
|
17
|
+
export declare function printHighlight<T extends string = import('.').ShjLanguage>(
|
|
18
|
+
src: string,
|
|
19
|
+
lang: T
|
|
20
|
+
): Promise<void>;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Change the current used theme for highlighting
|
|
24
|
+
* @param name The name of the theme
|
|
25
|
+
*/
|
|
26
|
+
export declare function setTheme(name: import('.').ShjBrowserTheme): Promise<void>;
|
package/dist/terminal.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{tokenize as e}from"./index.js";let t=import("./themes/default.js");const r=async(r,s)=>{let o="",a=(await t).default;return await e(r,s,((e,t)=>o+=t?`${a[t]??""}${e}[0m`:e)),o},s=async(e,t)=>console.log(await r(e,t)),o=async e=>t=function(e){switch(e){case"./themes/atom-dark.js":return import("./themes/atom-dark.js");case"./themes/default.js":return import("./themes/default.js");case"./themes/termcolor.js":return import("./themes/termcolor.js");default:return new Promise((function(t,r){("function"==typeof queueMicrotask?queueMicrotask:setTimeout)(r.bind(null,new Error("Unknown variable dynamic import: "+e)))}))}}(`./themes/${e}.js`);export{r as highlightText,s as printHighlight,o as setTheme};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import e from"./termcolor.js";var r={deleted:e.red,var:e.red,err:e.red,kwd:e.magenta,num:e.yellow,class:e.yellow,cmnt:e.gray,insert:e.green,str:e.green,bool:e.cyan,type:e.blue,oper:e.blue,section:e.magenta,func:e.blue};export{r as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import e from"./termcolor.js";var r={deleted:e.red,var:e.red,err:e.red,kwd:e.red,num:e.yellow,class:e.yellow,cmnt:e.gray,insert:e.green,str:e.green,bool:e.cyan,type:e.blue,oper:e.blue,section:e.magenta,func:e.magenta};export{r as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var m={black:"[30m",red:"[31m",green:"[32m",gray:"[90m",yellow:"[33m",blue:"[34m",magenta:"[35m",cyan:"[36m",white:"[37m"};export{m as default};
|
package/package.json
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@speed-highlight/core",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "🌈 Light, fast, and easy to use, dependencies free javascript syntax highlighter, with automatic language detection",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./dist/index.js",
|
|
9
|
+
"./index.js": "./dist/index.js",
|
|
10
|
+
"./detect.js": "./dist/detect.js",
|
|
11
|
+
"./terminal.js": "./dist/terminal.js",
|
|
12
|
+
"./cjs/index.js": "./dist/node/index.js",
|
|
13
|
+
"./cjs/detect.js": "./dist/node/detect.js",
|
|
14
|
+
"./cjs/terminal.js": "./dist/node/terminal.js"
|
|
15
|
+
},
|
|
16
|
+
"directories": {
|
|
17
|
+
"example": "examples"
|
|
18
|
+
},
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "rollup --config"
|
|
21
|
+
},
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "git://github.com/speed-highlight/core.git"
|
|
25
|
+
},
|
|
26
|
+
"bugs": {
|
|
27
|
+
"url": "https://github.com/speed-highlight/core/issues"
|
|
28
|
+
},
|
|
29
|
+
"keywords": [
|
|
30
|
+
"javascript",
|
|
31
|
+
"syntax-highlighting",
|
|
32
|
+
"language",
|
|
33
|
+
"fast",
|
|
34
|
+
"js",
|
|
35
|
+
"simple",
|
|
36
|
+
"highlighter",
|
|
37
|
+
"regex",
|
|
38
|
+
"highlighting",
|
|
39
|
+
"highlightjs",
|
|
40
|
+
"small",
|
|
41
|
+
"deno"
|
|
42
|
+
],
|
|
43
|
+
"author": "matubu",
|
|
44
|
+
"license": "CC0-1.0",
|
|
45
|
+
"homepage": "https://github.com/speed-highlight/core#readme",
|
|
46
|
+
"release": {
|
|
47
|
+
"branches": [
|
|
48
|
+
"main"
|
|
49
|
+
]
|
|
50
|
+
},
|
|
51
|
+
"private": false,
|
|
52
|
+
"publishConfig": {
|
|
53
|
+
"access": "public",
|
|
54
|
+
"provenance": true
|
|
55
|
+
},
|
|
56
|
+
"files": [
|
|
57
|
+
"dist"
|
|
58
|
+
],
|
|
59
|
+
"devDependencies": {
|
|
60
|
+
"@rollup/plugin-dynamic-import-vars": "^2.0.4",
|
|
61
|
+
"@rollup/plugin-terser": "^0.4.3",
|
|
62
|
+
"rollup": "^2.75.7",
|
|
63
|
+
"rollup-plugin-copy": "^3.4.0",
|
|
64
|
+
"semantic-release": "^21.0.7"
|
|
65
|
+
},
|
|
66
|
+
"typesVersions": {
|
|
67
|
+
"*": {
|
|
68
|
+
"*": [
|
|
69
|
+
"dist/*",
|
|
70
|
+
"dist"
|
|
71
|
+
]
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
"type": "module"
|
|
75
|
+
}
|