@robot-inventor/shell-session-syntax 1.0.0
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 +21 -0
- package/README.md +65 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +2 -0
- package/package.json +38 -0
- package/syntaxes/shell-session.tmLanguage.json +2379 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 ろぼいん
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# shell-session-syntax
|
|
2
|
+
|
|
3
|
+
Grammar files for better syntax highlight of Shell Session. This repository provides a TextMate grammar file in JSON format for ``shellsession`` syntax highlighting.
|
|
4
|
+
|
|
5
|
+
I have merged the ``shellsession`` syntax used by GitHub and the powerful ``shellscript`` syntax used by VS Code.
|
|
6
|
+
|
|
7
|
+
> [!NOTE]
|
|
8
|
+
> You may also be interested in [regex-syntax](https://github.com/Robot-Inventor/regex-syntax) for syntax highlight of regular expressions.
|
|
9
|
+
|
|
10
|
+
## Why?
|
|
11
|
+
|
|
12
|
+
This project was created to more properly syntax highlight ``shellsession`` in [Shiki.js](https://shiki.style/).
|
|
13
|
+
|
|
14
|
+
The grammar file used by Shiki does not highlight the first command in Shell Session, but it is difficult to change the existing behavior for [several reasons](https://github.com/shikijs/textmate-grammars-themes/issues/43).
|
|
15
|
+
|
|
16
|
+
If you load shell-session-syntax as a custom language grammar in Shiki, you will get better syntax highlighting of ``shellsession``.
|
|
17
|
+
|
|
18
|
+
| Shiki's default syntax | shell-session-syntax |
|
|
19
|
+
| :-----------------------------------------------: | :----------------------------------------------------: |
|
|
20
|
+
|  |  |
|
|
21
|
+
|
|
22
|
+
This project automatically generates the grammar file. It uses [better-shell-syntax](https://github.com/jeff-hykin/better-shell-syntax/blob/master/autogenerated/shell.tmLanguage.json) for Shell grammar and [Linguist](https://github.com/github-linguist/linguist/) for Shell Session grammar. When merging these grammars, some patches are automatically applied.
|
|
23
|
+
|
|
24
|
+
## Usage
|
|
25
|
+
|
|
26
|
+
To use shell-session-syntax in Shiki, please download ``./syntaxes/shell-session.tmLanguage.json`` and load it as a custom language grammar. It automatically overwrites the default ``shellsession`` grammar.
|
|
27
|
+
|
|
28
|
+
```javascript
|
|
29
|
+
import { getHighlighter } from "shiki";
|
|
30
|
+
import shellSession from "./shell-session.tmLanguage.json" assert { type: "json" };
|
|
31
|
+
|
|
32
|
+
const code = `
|
|
33
|
+
user@foo$ echo "Hello, World!" > hello.txt
|
|
34
|
+
Hello, World!
|
|
35
|
+
user@foo$ ls -l | grep ".txt"
|
|
36
|
+
hello.txt
|
|
37
|
+
`.trim();
|
|
38
|
+
|
|
39
|
+
const highlighter = await getHighlighter({
|
|
40
|
+
langs: [shellSession],
|
|
41
|
+
themes: ["vitesse-dark"]
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
const html = highlighter.codeToHtml(code, {
|
|
45
|
+
lang: "shellsession",
|
|
46
|
+
theme: "vitesse-dark"
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
console.log(html);
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Update Grammar
|
|
53
|
+
|
|
54
|
+
To update the grammar file, run the following command. It automatically downloads the latest upstream grammar files and applies patches.
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
npm run build
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Grammar Sources
|
|
61
|
+
|
|
62
|
+
shell-session-syntax is generated by automatically applying patches to the following grammar files and merging them.
|
|
63
|
+
|
|
64
|
+
- [better-shell-syntax](https://github.com/jeff-hykin/better-shell-syntax) ([MIT License](https://github.com/jeff-hykin/better-shell-syntax/blob/master/LICENSE))
|
|
65
|
+
- [Linguist](https://github.com/github-linguist/linguist/) ([MIT License](https://github.com/github-linguist/linguist/blob/master/LICENSE))
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@robot-inventor/shell-session-syntax",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Grammar files for better syntax highlight of Shell Session.",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist",
|
|
10
|
+
"syntaxes"
|
|
11
|
+
],
|
|
12
|
+
"scripts": {
|
|
13
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
14
|
+
"build": "ts-node ./scripts/generate.ts && tsc"
|
|
15
|
+
},
|
|
16
|
+
"publishConfig": {
|
|
17
|
+
"access": "public"
|
|
18
|
+
},
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/Robot-Inventor/shell-session-syntax.git"
|
|
22
|
+
},
|
|
23
|
+
"author": "Robot-Inventor",
|
|
24
|
+
"license": "MIT",
|
|
25
|
+
"bugs": {
|
|
26
|
+
"url": "https://github.com/Robot-Inventor/shell-session-syntax/issues"
|
|
27
|
+
},
|
|
28
|
+
"homepage": "https://github.com/Robot-Inventor/shell-session-syntax#readme",
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"rss-parser": "^3.13.0",
|
|
31
|
+
"tar": "^7.0.0",
|
|
32
|
+
"ts-node": "^10.9.2",
|
|
33
|
+
"typescript": "^5.4.2"
|
|
34
|
+
},
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"shiki": "^1.3.0"
|
|
37
|
+
}
|
|
38
|
+
}
|