@scalar/code-highlight 0.0.25 → 0.0.26
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/CHANGELOG.md +6 -0
- package/dist/languages/basic.js +2 -2
- package/dist/languages/standard.d.ts.map +1 -1
- package/dist/languages/standard.js +3 -1
- package/dist/rehype-alert/rehype-alert.d.ts.map +1 -1
- package/dist/rehype-alert/rehype-alert.js +14 -7
- package/dist/rehype-highlight/rehype-highlight.d.ts.map +1 -1
- package/dist/rehype-highlight/rehype-highlight.js +12 -6
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
package/dist/languages/basic.js
CHANGED
|
@@ -15,9 +15,9 @@ import yaml from 'highlight.js/lib/languages/yaml';
|
|
|
15
15
|
const basicLanguages = {
|
|
16
16
|
bash,
|
|
17
17
|
css,
|
|
18
|
+
html: xml,
|
|
18
19
|
javascript,
|
|
19
20
|
json,
|
|
20
|
-
html: xml,
|
|
21
21
|
less,
|
|
22
22
|
markdown,
|
|
23
23
|
plaintext,
|
|
@@ -25,8 +25,8 @@ const basicLanguages = {
|
|
|
25
25
|
scss,
|
|
26
26
|
shell,
|
|
27
27
|
typescript,
|
|
28
|
-
yaml,
|
|
29
28
|
xml,
|
|
29
|
+
yaml,
|
|
30
30
|
};
|
|
31
31
|
|
|
32
32
|
export { basicLanguages };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"standard.d.ts","sourceRoot":"","sources":["../../src/languages/standard.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"standard.d.ts","sourceRoot":"","sources":["../../src/languages/standard.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAuC9C,QAAA,MAAM,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAsCjD,CAAA;AAED,OAAO,EAAE,iBAAiB,EAAE,CAAA"}
|
|
@@ -4,6 +4,7 @@ import clojure from 'highlight.js/lib/languages/clojure';
|
|
|
4
4
|
import cpp from 'highlight.js/lib/languages/cpp';
|
|
5
5
|
import csharp from 'highlight.js/lib/languages/csharp';
|
|
6
6
|
import css from 'highlight.js/lib/languages/css';
|
|
7
|
+
import dart from 'highlight.js/lib/languages/dart';
|
|
7
8
|
import elixir from 'highlight.js/lib/languages/elixir';
|
|
8
9
|
import go from 'highlight.js/lib/languages/go';
|
|
9
10
|
import graphql from 'highlight.js/lib/languages/graphql';
|
|
@@ -39,9 +40,10 @@ const standardLanguages = {
|
|
|
39
40
|
c,
|
|
40
41
|
clojure,
|
|
41
42
|
cpp,
|
|
43
|
+
csharp,
|
|
42
44
|
css,
|
|
43
45
|
curl,
|
|
44
|
-
|
|
46
|
+
dart,
|
|
45
47
|
elixir,
|
|
46
48
|
go,
|
|
47
49
|
graphql,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rehype-alert.d.ts","sourceRoot":"","sources":["../../src/rehype-alert/rehype-alert.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,OAAO,CAAA;AASjC,wBAAgB,WAAW,WACX,IAAI,
|
|
1
|
+
{"version":3,"file":"rehype-alert.d.ts","sourceRoot":"","sources":["../../src/rehype-alert/rehype-alert.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,OAAO,CAAA;AASjC,wBAAgB,WAAW,WACX,IAAI,UAgGnB"}
|
|
@@ -13,29 +13,36 @@ function rehypeAlert() {
|
|
|
13
13
|
}
|
|
14
14
|
// Find the first non-whitespace child
|
|
15
15
|
const headIndex = node.children.findIndex((child) => !isWhitespace(child));
|
|
16
|
-
if (headIndex === -1)
|
|
16
|
+
if (headIndex === -1) {
|
|
17
17
|
return;
|
|
18
|
+
}
|
|
18
19
|
const head = node.children[headIndex];
|
|
19
|
-
if (!head || head.type !== 'element' || head.tagName !== 'p')
|
|
20
|
+
if (!head || head.type !== 'element' || head.tagName !== 'p') {
|
|
20
21
|
return;
|
|
22
|
+
}
|
|
21
23
|
const text = head.children[0];
|
|
22
|
-
if (!text || text.type !== 'text' || !text.value.startsWith('[!'))
|
|
24
|
+
if (!text || text.type !== 'text' || !text.value.startsWith('[!')) {
|
|
23
25
|
return;
|
|
26
|
+
}
|
|
24
27
|
const end = text.value.indexOf(']');
|
|
25
|
-
if (end === -1)
|
|
28
|
+
if (end === -1) {
|
|
26
29
|
return;
|
|
30
|
+
}
|
|
27
31
|
// Extract the alert type
|
|
28
32
|
const alertType = text.value.slice(2, end).toLowerCase();
|
|
29
|
-
if (!ALERT_TYPES.includes(alertType))
|
|
33
|
+
if (!ALERT_TYPES.includes(alertType)) {
|
|
30
34
|
return;
|
|
35
|
+
}
|
|
31
36
|
// Remove the blockquote if it's empty
|
|
32
37
|
if (end + 1 === text.value.length) {
|
|
33
38
|
const next = head.children[1];
|
|
34
39
|
if (next) {
|
|
35
|
-
if (next.type !== 'element' || next.tagName !== 'br')
|
|
40
|
+
if (next.type !== 'element' || next.tagName !== 'br') {
|
|
36
41
|
return;
|
|
37
|
-
|
|
42
|
+
}
|
|
43
|
+
if (!head.children[2]) {
|
|
38
44
|
return;
|
|
45
|
+
}
|
|
39
46
|
head.children = head.children.slice(2);
|
|
40
47
|
const node = head.children[0];
|
|
41
48
|
if (node && node.type === 'text' && node.value.charAt(0) === '\n') {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rehype-highlight.d.ts","sourceRoot":"","sources":["../../src/rehype-highlight/rehype-highlight.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAA2B,IAAI,EAAE,MAAM,MAAM,CAAA;AAEzD,OAAO,EAAE,cAAc,EAAE,KAAK,UAAU,EAAE,MAAM,UAAU,CAAA;AAE1D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,OAAO,CAAA;AAIlC,KAAK,gBAAgB,GAAG;IAC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AQ,CAAC,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC,GAAG,IAAI,GAAG,SAAS,CAAA;IACrF,2EAA2E;IAC3E,SAAS,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,GAAG,IAAI,GAAG,SAAS,CAAA;IACnE,yGAAyG;IACzG,SAAS,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,GAAG,IAAI,GAAG,SAAS,CAAA;IACpD,wCAAwC;IACxC,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAA;IAClC,qFAAqF;IACrF,MAAM,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,GAAG,IAAI,GAAG,SAAS,CAAA;IACjD,qCAAqC;IACrC,MAAM,CAAC,EAAE,OAAO,CAAA;CACjB,CAAA;AAID;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,OAAO,CAAC,EAAE,QAAQ,CAAC,gBAAgB,CAAC,GAAG,IAAI,GAAG,SAAS,UAuBvE,IAAI,QAAQ,KAAK,UAsDhC"}
|
|
@@ -20,8 +20,9 @@ function rehypeHighlight(options) {
|
|
|
20
20
|
let name = 'hljs';
|
|
21
21
|
// Create a lowlight instance if not provided
|
|
22
22
|
const lowlight = options?.lowlight ?? createLowlight(languages);
|
|
23
|
-
if (aliases)
|
|
23
|
+
if (aliases) {
|
|
24
24
|
lowlight.registerAlias(aliases);
|
|
25
|
+
}
|
|
25
26
|
if (prefix) {
|
|
26
27
|
const pos = prefix.indexOf('-');
|
|
27
28
|
name = pos > -1 ? prefix.slice(0, pos) : prefix;
|
|
@@ -75,18 +76,23 @@ function rehypeHighlight(options) {
|
|
|
75
76
|
/** Get the programming language of `node` or an empty string */
|
|
76
77
|
function language(node) {
|
|
77
78
|
const list = node.properties.className;
|
|
78
|
-
if (!Array.isArray(list))
|
|
79
|
+
if (!Array.isArray(list)) {
|
|
79
80
|
return '';
|
|
81
|
+
}
|
|
80
82
|
const name = list.reduce((result, _item) => {
|
|
81
|
-
if (result)
|
|
83
|
+
if (result) {
|
|
82
84
|
return result;
|
|
85
|
+
}
|
|
83
86
|
const item = String(_item);
|
|
84
|
-
if (item === 'no-highlight' || item === 'nohighlight')
|
|
87
|
+
if (item === 'no-highlight' || item === 'nohighlight') {
|
|
85
88
|
return 'no-highlight';
|
|
86
|
-
|
|
89
|
+
}
|
|
90
|
+
if (item.slice(0, 5) === 'lang-') {
|
|
87
91
|
return item.slice(5);
|
|
88
|
-
|
|
92
|
+
}
|
|
93
|
+
if (item.slice(0, 9) === 'language-') {
|
|
89
94
|
return item.slice(9);
|
|
95
|
+
}
|
|
90
96
|
return result;
|
|
91
97
|
}, '');
|
|
92
98
|
return lowlightLanguageMappings[name || ''] || name;
|
package/package.json
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"lowlight",
|
|
17
17
|
"highlightjs"
|
|
18
18
|
],
|
|
19
|
-
"version": "0.0.
|
|
19
|
+
"version": "0.0.26",
|
|
20
20
|
"engines": {
|
|
21
21
|
"node": ">=18"
|
|
22
22
|
},
|
|
@@ -98,7 +98,7 @@
|
|
|
98
98
|
"vite": "^5.4.10",
|
|
99
99
|
"vue": "^3.5.12",
|
|
100
100
|
"@scalar/build-tooling": "0.1.17",
|
|
101
|
-
"@scalar/themes": "0.9.
|
|
101
|
+
"@scalar/themes": "0.9.84"
|
|
102
102
|
},
|
|
103
103
|
"scripts": {
|
|
104
104
|
"build": "scalar-build-rollup",
|