Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/robot-inventor/regex-syntax
Grammar files for syntax highlight of regex
https://github.com/robot-inventor/regex-syntax
Last synced: 24 days ago
JSON representation
Grammar files for syntax highlight of regex
- Host: GitHub
- URL: https://github.com/robot-inventor/regex-syntax
- Owner: Robot-Inventor
- License: mit
- Created: 2024-03-12T12:20:37.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2024-06-11T16:37:50.000Z (5 months ago)
- Last Synced: 2024-06-11T20:53:47.363Z (5 months ago)
- Language: TypeScript
- Size: 392 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# regex-syntax
Grammar files for syntax highlight of regex. The grammar files are automatically generated from [Linguist](https://github.com/github-linguist/linguist/)'s regex grammars.
> [!NOTE]
> You may also be interested in [shell-session-syntax](https://github.com/Robot-Inventor/shell-session-syntax/) for syntax highlight of shell sessions.| Before | After |
| :--------------------------------------: | :-----------------------------: |
| ![before](docs/without-regex-syntax.png) | ![after](docs/regex-syntax.png) |## Usage
To use regex-syntax in [Shiki.js](https://shiki.style/), please download ``./syntaxes/regex.tmLanguage.json`` or install the package and load it as a custom language grammar. Language name is ``regex`` and ``regexp``.
```bash
npm install @robot-inventor/regex-syntax
``````typescript
import { getHighlighter } from "shiki";
// Directly import the downloaded file.
import regex from "./regex.tmLanguage.json";
// Or import the package.
import regex from "@robot-inventor/regex-syntax";const code = `
^[a-zA-Z0-9.!#$%&'*+/=?^_\`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$
`.trim();const highlighter = await getHighlighter({
langs: [regex],
themes: ["vitesse-dark"]
});const html = highlighter.codeToHtml(code, {
lang: "regex",
theme: "vitesse-dark"
});console.log(html);
```## Update Grammar
To update the grammar file, run the following command. It automatically downloads the latest upstream grammar files and applies patches.
```bash
npm run build
```## Grammar Sources
regex-syntax is generated by automatically applying patches to the following grammar file.
- [Linguist](https://github.com/github-linguist/linguist/) ([MIT License](https://github.com/github-linguist/linguist/blob/master/LICENSE))