@scalar/code-highlight 0.0.19 → 0.0.21
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 +13 -0
- package/dist/code/highlight.d.ts +3 -0
- package/dist/code/highlight.d.ts.map +1 -1
- package/dist/code/highlight.js +7 -2
- package/dist/markdown/markdown.d.ts.map +1 -1
- package/dist/markdown/markdown.js +9 -11
- package/dist/rehype-highlight/rehype-highlight.d.ts +1 -1
- package/dist/rehype-highlight/rehype-highlight.d.ts.map +1 -1
- package/dist/rehype-highlight/rehype-highlight.js +2 -2
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @scalar/code-highlight
|
|
2
2
|
|
|
3
|
+
## 0.0.21
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- fa6afe8: chore: code formatting
|
|
8
|
+
- 1223c1f: chore: code style
|
|
9
|
+
|
|
10
|
+
## 0.0.20
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- 109e320: fix: removes regex for highlight credentials
|
|
15
|
+
|
|
3
16
|
## 0.0.19
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
package/dist/code/highlight.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"highlight.d.ts","sourceRoot":"","sources":["../../src/code/highlight.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"highlight.d.ts","sourceRoot":"","sources":["../../src/code/highlight.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAW9C;;GAEG;AACH,wBAAgB,eAAe,CAC7B,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE;IACP,IAAI,EAAE,MAAM,CAAA;IACZ,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAA;IACrC,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,eAAe,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;CACpC,UAiDF"}
|
package/dist/code/highlight.js
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
import { lowlightLanguageMappings } from '../constants.js';
|
|
2
1
|
import rehypeParse from 'rehype-parse';
|
|
3
2
|
import rehypeStringify from 'rehype-stringify';
|
|
4
3
|
import { unified } from 'unified';
|
|
5
4
|
import { visit } from 'unist-util-visit';
|
|
5
|
+
import { lowlightLanguageMappings } from '../constants.js';
|
|
6
6
|
import { codeBlockLinesPlugin } from './line-numbers.js';
|
|
7
7
|
import { rehypeHighlight } from '../rehype-highlight/rehype-highlight.js';
|
|
8
8
|
|
|
9
|
+
/**
|
|
10
|
+
* Syntax highlights a code string using the `rehype-highlight` library.
|
|
11
|
+
*/
|
|
9
12
|
function syntaxHighlight(codeString, options) {
|
|
10
13
|
// Simple restriction on credentials to prevent unexpected behavior
|
|
11
14
|
const credentials = (typeof options?.maskCredentials === 'string'
|
|
@@ -38,7 +41,9 @@ function syntaxHighlight(codeString, options) {
|
|
|
38
41
|
const htmlString = html.toString();
|
|
39
42
|
// Replace any credentials with a wrapper element
|
|
40
43
|
return credentials.length
|
|
41
|
-
?
|
|
44
|
+
? credentials.reduce((acc, credential) => acc
|
|
45
|
+
.split(credential)
|
|
46
|
+
.join(`<span class="credentials">${credential}</span>`), htmlString)
|
|
42
47
|
: htmlString;
|
|
43
48
|
}
|
|
44
49
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"markdown.d.ts","sourceRoot":"","sources":["../../src/markdown/markdown.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"markdown.d.ts","sourceRoot":"","sources":["../../src/markdown/markdown.ts"],"names":[],"mappings":"AA6CA;;GAEG;AACH,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE;IACR,UAAU,CAAC,EAAE,MAAM,EAAE,CAAA;IACrB,SAAS,CAAC,EAAE,MAAM,EAAE,CAAA;IACpB,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC9D,aAAa,CAAC,EAAE,MAAM,CAAA;CACvB,UAkDF;AASD;;GAEG;AACH,wBAAgB,WAAW,CACzB,QAAQ,EAAE,MAAM,EAChB,KAAK,GAAE,MAAU,GAChB;IACD,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,MAAM,CAAA;CACd,EAAE,CAiBF;AAuBD;;GAEG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,YAgC5C"}
|
|
@@ -15,19 +15,17 @@ import { standardLanguages } from '../languages/standard.js';
|
|
|
15
15
|
/**
|
|
16
16
|
* Plugin to transform nodes in a Markdown AST
|
|
17
17
|
*/
|
|
18
|
-
const transformNodes =
|
|
18
|
+
const transformNodes = (options,
|
|
19
19
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
20
|
-
..._ignored) {
|
|
21
|
-
|
|
22
|
-
if (!options?.transform || !options?.type) {
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
visit(tree, options?.type, (node) => {
|
|
26
|
-
options?.transform ? options?.transform(node) : node;
|
|
27
|
-
return SKIP;
|
|
28
|
-
});
|
|
20
|
+
..._ignored) => (tree) => {
|
|
21
|
+
if (!options?.transform || !options?.type) {
|
|
29
22
|
return;
|
|
30
|
-
}
|
|
23
|
+
}
|
|
24
|
+
visit(tree, options?.type, (node) => {
|
|
25
|
+
options?.transform ? options?.transform(node) : node;
|
|
26
|
+
return SKIP;
|
|
27
|
+
});
|
|
28
|
+
return;
|
|
31
29
|
};
|
|
32
30
|
/**
|
|
33
31
|
* Take a Markdown string and generate HTML from it
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Root } from 'hast';
|
|
2
|
-
import { type LanguageFn
|
|
2
|
+
import { createLowlight, type LanguageFn } from 'lowlight';
|
|
3
3
|
import type { VFile } from 'vfile';
|
|
4
4
|
type HighlightOptions = {
|
|
5
5
|
/** Optional existing lowlight instance to use */
|
|
@@ -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,KAAK,UAAU,EAAE,
|
|
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;IACtB,iDAAiD;IACjD,QAAQ,CAAC,EAAE,UAAU,CAAC,OAAO,cAAc,CAAC,GAAG,SAAS,CAAA;IACxD,2EAA2E;IAC3E,OAAO,CAAC,EACJ,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC,GACxD,IAAI,GACJ,SAAS,CAAA;IACb,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,CAC7B,OAAO,CAAC,EAAE,QAAQ,CAAC,gBAAgB,CAAC,GAAG,IAAI,GAAG,SAAS,UAsBzC,IAAI,QAAQ,KAAK,UAkEhC"}
|
|
@@ -27,8 +27,8 @@ function rehypeHighlight(options) {
|
|
|
27
27
|
name = pos > -1 ? prefix.slice(0, pos) : prefix;
|
|
28
28
|
}
|
|
29
29
|
/** Transform.*/
|
|
30
|
-
return
|
|
31
|
-
visit(tree, 'element',
|
|
30
|
+
return (tree, file) => {
|
|
31
|
+
visit(tree, 'element', (node, _, parent) => {
|
|
32
32
|
if (node.tagName !== 'code' ||
|
|
33
33
|
!parent ||
|
|
34
34
|
parent.type !== 'element' ||
|
package/package.json
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"lowlight",
|
|
17
17
|
"highlightjs"
|
|
18
18
|
],
|
|
19
|
-
"version": "0.0.
|
|
19
|
+
"version": "0.0.21",
|
|
20
20
|
"engines": {
|
|
21
21
|
"node": ">=18"
|
|
22
22
|
},
|
|
@@ -92,8 +92,8 @@
|
|
|
92
92
|
"vfile": "^6.0.1",
|
|
93
93
|
"vite": "^5.4.10",
|
|
94
94
|
"vue": "^3.5.12",
|
|
95
|
-
"@scalar/build-tooling": "0.1.
|
|
96
|
-
"@scalar/themes": "0.9.
|
|
95
|
+
"@scalar/build-tooling": "0.1.13",
|
|
96
|
+
"@scalar/themes": "0.9.67"
|
|
97
97
|
},
|
|
98
98
|
"scripts": {
|
|
99
99
|
"build": "scalar-build-rollup",
|