@robot-inventor/regex-syntax
TypeScript icon, indicating that this package has built-in type declarations

1.0.13 • Public • Published

regex-syntax

Grammar files for syntax highlight of regex. The grammar files are automatically generated from Linguist's regex grammars.

[!NOTE] You may also be interested in shell-session-syntax for syntax highlight of shell sessions.

Before After
before after

Usage

To use regex-syntax in Shiki.js, please download ./syntaxes/regex.tmLanguage.json or install the package and load it as a custom language grammar. Language name is regex and regexp.

npm install @robot-inventor/regex-syntax
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.

npm run build

Grammar Sources

regex-syntax is generated by automatically applying patches to the following grammar file.

Readme

Keywords

none

Package Sidebar

Install

npm i @robot-inventor/regex-syntax

Weekly Downloads

181

Version

1.0.13

License

MIT

Unpacked Size

10.7 kB

Total Files

6

Last publish

Collaborators

  • robot-inventor