marked-prismjs-linenumber 0.0.6 → 0.0.7
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/index.cjs +13 -4
- package/index.d.ts +21 -0
- package/package.json +14 -4
package/index.cjs
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
const Prism = require('prismjs');
|
|
2
2
|
const loadLanguages = require('prismjs/components/');
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* @param {string} code
|
|
6
|
+
* @param {string} [lang]
|
|
7
|
+
* @returns {string}
|
|
8
|
+
*/
|
|
4
9
|
function highlightWithLineNumbers(code, lang = 'plaintext') {
|
|
5
10
|
const grammar = Prism.languages[lang] || Prism.languages.plaintext;
|
|
6
11
|
|
|
@@ -21,19 +26,23 @@ function highlightWithLineNumbers(code, lang = 'plaintext') {
|
|
|
21
26
|
}
|
|
22
27
|
|
|
23
28
|
const renderer = {
|
|
29
|
+
/**
|
|
30
|
+
* @param {{ text: string; lang?: string }} args
|
|
31
|
+
* @returns {string}
|
|
32
|
+
*/
|
|
24
33
|
code({ text, lang }) {
|
|
25
34
|
const trimmedCode = text.trimEnd();
|
|
26
35
|
return highlightWithLineNumbers(trimmedCode, lang || 'plaintext');
|
|
27
36
|
}
|
|
28
37
|
};
|
|
29
38
|
|
|
39
|
+
/**
|
|
40
|
+
* @param {{ languages?: string[] }} [options]
|
|
41
|
+
*/
|
|
30
42
|
function init(options = {}) {
|
|
31
43
|
if (Array.isArray(options.languages)) {
|
|
32
44
|
loadLanguages(options.languages);
|
|
33
45
|
}
|
|
34
46
|
}
|
|
35
47
|
|
|
36
|
-
module.exports = {
|
|
37
|
-
renderer,
|
|
38
|
-
init
|
|
39
|
-
};
|
|
48
|
+
module.exports = { renderer, init };
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export interface PrismJsLineNumberOptions {
|
|
2
|
+
languages?: string[];
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export interface MarkedCodeArgs {
|
|
6
|
+
text: string;
|
|
7
|
+
lang?: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const renderer: {
|
|
11
|
+
code(args: MarkedCodeArgs): string;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export function init(options?: PrismJsLineNumberOptions): void;
|
|
15
|
+
|
|
16
|
+
declare const _default: {
|
|
17
|
+
renderer: typeof renderer;
|
|
18
|
+
init: typeof init;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export default _default;
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "marked-prismjs-linenumber",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"description": "Return HTML with prismjs line-number structure",
|
|
5
|
-
"type": "module",
|
|
6
5
|
"main": "./index.cjs",
|
|
7
6
|
"module": "./index.mjs",
|
|
7
|
+
"types": "./index.d.ts",
|
|
8
8
|
"exports": {
|
|
9
9
|
".": {
|
|
10
|
+
"types": "./index.d.ts",
|
|
10
11
|
"import": "./index.mjs",
|
|
11
12
|
"require": "./index.cjs",
|
|
12
13
|
"default": "./index.mjs"
|
|
@@ -14,13 +15,22 @@
|
|
|
14
15
|
},
|
|
15
16
|
"files": [
|
|
16
17
|
"index.mjs",
|
|
17
|
-
"index.cjs"
|
|
18
|
+
"index.cjs",
|
|
19
|
+
"index.d.ts"
|
|
18
20
|
],
|
|
19
21
|
"repository": {
|
|
20
22
|
"type": "git",
|
|
21
23
|
"url": "https://github.com/Yz0012/y_z00blog/tree/main/marked-extensions/marked-prismjs-linenumber"
|
|
22
24
|
},
|
|
23
|
-
"
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"marked": ">=4",
|
|
27
|
+
"prismjs": "^1.29.0"
|
|
28
|
+
},
|
|
29
|
+
"keywords": [
|
|
30
|
+
"marked",
|
|
31
|
+
"prismjs",
|
|
32
|
+
"linenumber"
|
|
33
|
+
],
|
|
24
34
|
"author": "Y_z00",
|
|
25
35
|
"license": "MIT"
|
|
26
36
|
}
|