rehype-pre-language 1.1.7 → 1.1.9
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 +1 -1
- package/README.md +21 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -5
- package/dist/index.js.map +1 -1
- package/package.json +12 -12
- package/dist/tsconfig.tsbuildinfo +0 -1
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,18 +1,11 @@
|
|
|
1
|
+
# rehype-pre-language
|
|
2
|
+
|
|
1
3
|
**A robust Next.js newsletter `Next.js Weekly` is sponsoring me** 💖
|
|
2
4
|
[](https://nextjsweekly.com/)
|
|
3
5
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
If you find **`rehype-pre-language`** useful in your projects, consider supporting my work.
|
|
7
|
-
Your sponsorship means a lot 💖
|
|
8
|
-
|
|
9
|
-
My sponsors are going to be featured here and on [my sponsor wall](https://github.com/sponsors/ipikuka).
|
|
6
|
+
A warm thanks 🙌 to [@ErfanEbrahimnia](https://github.com/ErfanEbrahimnia), [@recepkyk](https://github.com/recepkyk), and [@LSeaburg](https://github.com/LSeaburg) for the [support](https://github.com/sponsors/ipikuka) 💖
|
|
10
7
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
Thank you for supporting open source! 🙌
|
|
14
|
-
|
|
15
|
-
# rehype-pre-language
|
|
8
|
+
---
|
|
16
9
|
|
|
17
10
|
[![npm version][badge-npm-version]][url-npm-package]
|
|
18
11
|
[![npm downloads][badge-npm-download]][url-npm-package]
|
|
@@ -141,6 +134,14 @@ Use of **`rehype-pre-language`** involves rehype (hast), but doesn't lead to cro
|
|
|
141
134
|
|
|
142
135
|
I like to contribute the Unified / Remark / MDX ecosystem, so I recommend you to have a look my plugins.
|
|
143
136
|
|
|
137
|
+
### Support My Work ([become a sponsor](https://github.com/sponsors/ipikuka) 🚀)
|
|
138
|
+
|
|
139
|
+
If you find **`rehype-pre-language`** or any of my projects is useful and helpful, please consider supporting my work. Your sponsorship means a lot to me and keeps these projects alive and updated! 💖
|
|
140
|
+
|
|
141
|
+
My sponsors are going to be featured at the very top of the page and proudly displayed on my [Sponsor Wall](https://github.com/sponsors/ipikuka).
|
|
142
|
+
|
|
143
|
+
Thank you for supporting open source! 🙌
|
|
144
|
+
|
|
144
145
|
### My Remark Plugins
|
|
145
146
|
|
|
146
147
|
- [`remark-flexible-code-titles`](https://www.npmjs.com/package/remark-flexible-code-titles)
|
|
@@ -188,6 +189,15 @@ I like to contribute the Unified / Remark / MDX ecosystem, so I recommend you to
|
|
|
188
189
|
- [`recma-mdx-interpolate`](https://www.npmjs.com/package/recma-mdx-interpolate)
|
|
189
190
|
– Recma plugin to enable interpolation of identifiers wrapped in curly braces within the `alt`, `src`, `href`, and `title` attributes of markdown link and image syntax in MDX.
|
|
190
191
|
|
|
192
|
+
### My Unist Utils and Unified Plugins
|
|
193
|
+
|
|
194
|
+
I also build low-level utilities and plugins for the Unified ecosystem that can be used across Remark, Rehype, Recma, and other unist-based abstract syntax trees (ASTs).
|
|
195
|
+
|
|
196
|
+
- [`unist-util-find-between`](https://www.npmjs.com/package/unist-util-find-between)
|
|
197
|
+
– Unist utility to find the nodes between two nodes.
|
|
198
|
+
- [`unified-log-tree`](https://www.npmjs.com/package/unified-log-tree)
|
|
199
|
+
– Unified plugin to log abstract syntax trees (ASTs) for debugging without mutating.
|
|
200
|
+
|
|
191
201
|
## License
|
|
192
202
|
|
|
193
203
|
[MIT License](./LICENSE) © ipikuka
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACtC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAGjC,MAAM,MAAM,iBAAiB,GAAG,MAAM,CAAC;AAUvC;;;;GAIG;AACH,QAAA,MAAM,MAAM,EAAE,MAAM,CAAC,CAAC,iBAAiB,CAAC,CAAC,EAAE,IAAI,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACtC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAGjC,MAAM,MAAM,iBAAiB,GAAG,MAAM,CAAC;AAUvC;;;;GAIG;AACH,QAAA,MAAM,MAAM,EAAE,MAAM,CAAC,CAAC,iBAAiB,CAAC,CAAC,EAAE,IAAI,CA2D9C,CAAC;AAEF,eAAe,MAAM,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -51,11 +51,11 @@ const plugin = (option) => {
|
|
|
51
51
|
parent.properties[property] = language;
|
|
52
52
|
}
|
|
53
53
|
else {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
54
|
+
/* v8 ignore next -- @preserve */
|
|
55
|
+
if (!isStringArray(parent.properties.className)) {
|
|
56
|
+
parent.properties.className = [];
|
|
57
|
+
}
|
|
58
|
+
parent.properties.className.push(language);
|
|
59
59
|
}
|
|
60
60
|
});
|
|
61
61
|
};
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAsB,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAI7D,gCAAgC;AAChC,SAAS,aAAa,CAAC,KAAc;IACnC,OAAO;IACL,iCAAiC;IACjC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,IAAI,KAAK,QAAQ,CAAC,CACxE,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,MAAM,GAAuC,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AC,WAAW,EAAE,CAAC;QAErF,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED;;;;;;;OAOG;IACH,OAAO,CAAC,IAAU,EAAa,EAAE;QAC/B,KAAK,CAAC,IAAI,EAAE,SAAS,EAAE,UAAU,IAAI,EAAE,KAAK,EAAE,MAAM;YAClD,IAAI,CAAC,MAAM,IAAI,KAAK,KAAK,SAAS,IAAI,IAAI,CAAC,OAAO,KAAK,MAAM,EAAE,CAAC;gBAC9D,OAAO;YACT,CAAC;YAED,IAAI,MAAM,CAAC,IAAI,KAAK,SAAS,IAAI,MAAM,CAAC,OAAO,KAAK,KAAK,EAAE,CAAC;gBAC1D,OAAO;YACT,CAAC;YAED,MAAM,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC;YAE7C,IAAI,CAAC,aAAa,CAAC,UAAU,CAAC;gBAAE,OAAO;YAEvC,MAAM,QAAQ,GAAG,WAAW,CAAC,UAAU,CAAC,CAAC;YAEzC,IAAI,CAAC,QAAQ;gBAAE,OAAO;YAEtB,IAAI,QAAQ,KAAK,WAAW,EAAE,CAAC;gBAC7B,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,GAAG,QAAQ,CAAC;YACzC,CAAC;iBAAM,CAAC;gBACN,iCAAiC;gBACjC,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;oBAChD,MAAM,CAAC,UAAU,CAAC,SAAS,GAAG,EAAE,CAAC;gBACnC,CAAC;gBAED,MAAM,CAAC,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YAC7C,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,MAAM,CAAC","sourcesContent":["import type { Plugin } from \"unified\";\nimport type { Root } from \"hast\";\nimport { type VisitorResult, visit } from \"unist-util-visit\";\n\nexport type PreLanguageOption = string;\n\n// check if it is a string array\nfunction isStringArray(value: unknown): value is string[] {\n return (\n // type-coverage:ignore-next-line\n Array.isArray(value) && value.every((item) => typeof item === \"string\")\n );\n}\n\n/**\n *\n * add code language to <pre> element as a property\n *\n */\nconst plugin: Plugin<[PreLanguageOption?], Root> = (option) => {\n const property = option ? (option.startsWith(\"on\") ? option.slice(2) : option) : \"className\";\n\n /**\n *\n * get the language from classNames\n *\n */\n function getLanguage(classNames: string[]): string | undefined {\n const isLanguageString = (element: string): boolean =>\n element.startsWith(\"language-\") || element.startsWith(\"lang-\");\n\n const languageString = classNames.find(isLanguageString);\n\n if (!languageString) return;\n\n const language = languageString.slice(languageString.indexOf(\"-\") + 1).toLowerCase();\n\n return language;\n }\n\n /**\n * Transform.\n *\n * @param {Root} tree\n * Tree.\n * @returns {undefined}\n * Nothing.\n */\n return (tree: Root): undefined => {\n visit(tree, \"element\", function (code, index, parent): VisitorResult {\n if (!parent || index === undefined || code.tagName !== \"code\") {\n return;\n }\n\n if (parent.type !== \"element\" || parent.tagName !== \"pre\") {\n return;\n }\n\n const classNames = code.properties.className;\n\n if (!isStringArray(classNames)) return;\n\n const language = getLanguage(classNames);\n\n if (!language) return;\n\n if (property !== \"className\") {\n parent.properties[property] = language;\n } else {\n /* v8 ignore next -- @preserve */\n if (!isStringArray(parent.properties.className)) {\n parent.properties.className = [];\n }\n\n parent.properties.className.push(language);\n }\n });\n };\n};\n\nexport default plugin;\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rehype-pre-language",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.9",
|
|
4
4
|
"description": "Rehype plugin to add language information as a property to pre element",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
}
|
|
14
14
|
},
|
|
15
15
|
"scripts": {
|
|
16
|
-
"build": "rimraf dist && tsc --build && type-coverage",
|
|
16
|
+
"build": "rimraf dist && tsc --build tsconfig.build.json && type-coverage",
|
|
17
17
|
"format": "npm run prettier && npm run lint",
|
|
18
18
|
"prettier": "prettier --write .",
|
|
19
19
|
"lint": "eslint .",
|
|
@@ -54,29 +54,29 @@
|
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@eslint/js": "^10.0.1",
|
|
56
56
|
"@types/dedent": "^0.7.2",
|
|
57
|
-
"@types/node": "^24.
|
|
58
|
-
"@vitest/coverage-v8": "^4.
|
|
59
|
-
"@vitest/eslint-plugin": "^1.6.
|
|
60
|
-
"dedent": "^1.7.
|
|
61
|
-
"eslint": "^10.
|
|
57
|
+
"@types/node": "^24.12.4",
|
|
58
|
+
"@vitest/coverage-v8": "^4.1.7",
|
|
59
|
+
"@vitest/eslint-plugin": "^1.6.18",
|
|
60
|
+
"dedent": "^1.7.2",
|
|
61
|
+
"eslint": "^10.4.0",
|
|
62
62
|
"eslint-config-prettier": "^10.1.8",
|
|
63
63
|
"eslint-plugin-prettier": "^5.5.5",
|
|
64
|
-
"globals": "^17.
|
|
65
|
-
"prettier": "^3.8.
|
|
64
|
+
"globals": "^17.6.0",
|
|
65
|
+
"prettier": "^3.8.3",
|
|
66
66
|
"rehype-highlight": "^7.0.2",
|
|
67
67
|
"rehype-parse": "^9.0.1",
|
|
68
68
|
"rehype-stringify": "^10.0.1",
|
|
69
|
-
"remark-flexible-code-titles": "^1.3.
|
|
69
|
+
"remark-flexible-code-titles": "^1.3.4",
|
|
70
70
|
"remark-gfm": "^4.0.1",
|
|
71
71
|
"remark-parse": "^11.0.0",
|
|
72
72
|
"remark-rehype": "^11.1.2",
|
|
73
73
|
"rimraf": "^6.1.3",
|
|
74
74
|
"type-coverage": "^2.29.7",
|
|
75
75
|
"typescript": "^5.9.3",
|
|
76
|
-
"typescript-eslint": "^8.
|
|
76
|
+
"typescript-eslint": "^8.60.0",
|
|
77
77
|
"unified": "^11.0.5",
|
|
78
78
|
"vfile": "^6.0.3",
|
|
79
|
-
"vitest": "^4.
|
|
79
|
+
"vitest": "^4.1.7"
|
|
80
80
|
},
|
|
81
81
|
"dependencies": {
|
|
82
82
|
"@types/hast": "^3.0.4",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"root":["../src/index.ts"],"version":"5.9.3"}
|