fix: resolve TypeScript errors in frontend build

This commit is contained in:
Hiro
2026-03-30 23:16:07 +00:00
parent b733306773
commit 24925e1acb
2941 changed files with 418042 additions and 49 deletions

22
node_modules/lowlight/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,22 @@
export type {LanguageFn} from 'highlight.js'
export type {AutoOptions, Options} from './lib/index.js'
export {grammars as all} from './lib/all.js'
export {grammars as common} from './lib/common.js'
export {createLowlight} from './lib/index.js'
// Register data on hast.
declare module 'hast' {
interface RootData {
/**
* Field exposed by `lowlight` to contain the detected programming language
* name.
*/
language?: string | undefined
/**
* Field exposed by `lowlight` to contain a relevance: how sure `lowlight`
* is that the given code is in the language.
*/
relevance?: number | undefined
}
}

4
node_modules/lowlight/index.js generated vendored Normal file
View File

@@ -0,0 +1,4 @@
// Note: types exposed from `index.d.ts`.
export {grammars as all} from './lib/all.js'
export {grammars as common} from './lib/common.js'
export {createLowlight} from './lib/index.js'

8
node_modules/lowlight/lib/all.d.ts generated vendored Normal file
View File

@@ -0,0 +1,8 @@
/**
* Map of grammars.
*
* @type {Record<string, LanguageFn>}
*/
export const grammars: Record<string, LanguageFn>;
import type { LanguageFn } from 'highlight.js';
//# sourceMappingURL=all.d.ts.map

1
node_modules/lowlight/lib/all.d.ts.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"all.d.ts","sourceRoot":"","sources":["all.js"],"names":[],"mappings":"AAkKA;;;;GAIG;AACH,uBAFU,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CA+JnC;gCAnU4B,cAAc"}

324
node_modules/lowlight/lib/all.js generated vendored Normal file
View File

@@ -0,0 +1,324 @@
/**
* @import {LanguageFn} from 'highlight.js'
*/
import $1c from 'highlight.js/lib/languages/1c'
import abnf from 'highlight.js/lib/languages/abnf'
import accesslog from 'highlight.js/lib/languages/accesslog'
import actionscript from 'highlight.js/lib/languages/actionscript'
import ada from 'highlight.js/lib/languages/ada'
import angelscript from 'highlight.js/lib/languages/angelscript'
import apache from 'highlight.js/lib/languages/apache'
import applescript from 'highlight.js/lib/languages/applescript'
import arcade from 'highlight.js/lib/languages/arcade'
import armasm from 'highlight.js/lib/languages/armasm'
import asciidoc from 'highlight.js/lib/languages/asciidoc'
import aspectj from 'highlight.js/lib/languages/aspectj'
import autohotkey from 'highlight.js/lib/languages/autohotkey'
import autoit from 'highlight.js/lib/languages/autoit'
import avrasm from 'highlight.js/lib/languages/avrasm'
import awk from 'highlight.js/lib/languages/awk'
import axapta from 'highlight.js/lib/languages/axapta'
import basic from 'highlight.js/lib/languages/basic'
import bnf from 'highlight.js/lib/languages/bnf'
import brainfuck from 'highlight.js/lib/languages/brainfuck'
import cal from 'highlight.js/lib/languages/cal'
import capnproto from 'highlight.js/lib/languages/capnproto'
import ceylon from 'highlight.js/lib/languages/ceylon'
import clean from 'highlight.js/lib/languages/clean'
import clojure from 'highlight.js/lib/languages/clojure'
import clojureRepl from 'highlight.js/lib/languages/clojure-repl'
import cmake from 'highlight.js/lib/languages/cmake'
import coffeescript from 'highlight.js/lib/languages/coffeescript'
import coq from 'highlight.js/lib/languages/coq'
import cos from 'highlight.js/lib/languages/cos'
import crmsh from 'highlight.js/lib/languages/crmsh'
import crystal from 'highlight.js/lib/languages/crystal'
import csp from 'highlight.js/lib/languages/csp'
import d from 'highlight.js/lib/languages/d'
import dart from 'highlight.js/lib/languages/dart'
import delphi from 'highlight.js/lib/languages/delphi'
import django from 'highlight.js/lib/languages/django'
import dns from 'highlight.js/lib/languages/dns'
import dockerfile from 'highlight.js/lib/languages/dockerfile'
import dos from 'highlight.js/lib/languages/dos'
import dsconfig from 'highlight.js/lib/languages/dsconfig'
import dts from 'highlight.js/lib/languages/dts'
import dust from 'highlight.js/lib/languages/dust'
import ebnf from 'highlight.js/lib/languages/ebnf'
import elixir from 'highlight.js/lib/languages/elixir'
import elm from 'highlight.js/lib/languages/elm'
import erb from 'highlight.js/lib/languages/erb'
import erlang from 'highlight.js/lib/languages/erlang'
import erlangRepl from 'highlight.js/lib/languages/erlang-repl'
import excel from 'highlight.js/lib/languages/excel'
import fix from 'highlight.js/lib/languages/fix'
import flix from 'highlight.js/lib/languages/flix'
import fortran from 'highlight.js/lib/languages/fortran'
import fsharp from 'highlight.js/lib/languages/fsharp'
import gams from 'highlight.js/lib/languages/gams'
import gauss from 'highlight.js/lib/languages/gauss'
import gcode from 'highlight.js/lib/languages/gcode'
import gherkin from 'highlight.js/lib/languages/gherkin'
import glsl from 'highlight.js/lib/languages/glsl'
import gml from 'highlight.js/lib/languages/gml'
import golo from 'highlight.js/lib/languages/golo'
import gradle from 'highlight.js/lib/languages/gradle'
import groovy from 'highlight.js/lib/languages/groovy'
import haml from 'highlight.js/lib/languages/haml'
import handlebars from 'highlight.js/lib/languages/handlebars'
import haskell from 'highlight.js/lib/languages/haskell'
import haxe from 'highlight.js/lib/languages/haxe'
import hsp from 'highlight.js/lib/languages/hsp'
import http from 'highlight.js/lib/languages/http'
import hy from 'highlight.js/lib/languages/hy'
import inform7 from 'highlight.js/lib/languages/inform7'
import irpf90 from 'highlight.js/lib/languages/irpf90'
import isbl from 'highlight.js/lib/languages/isbl'
import jbossCli from 'highlight.js/lib/languages/jboss-cli'
import julia from 'highlight.js/lib/languages/julia'
import juliaRepl from 'highlight.js/lib/languages/julia-repl'
import lasso from 'highlight.js/lib/languages/lasso'
import latex from 'highlight.js/lib/languages/latex'
import ldif from 'highlight.js/lib/languages/ldif'
import leaf from 'highlight.js/lib/languages/leaf'
import lisp from 'highlight.js/lib/languages/lisp'
import livecodeserver from 'highlight.js/lib/languages/livecodeserver'
import livescript from 'highlight.js/lib/languages/livescript'
import llvm from 'highlight.js/lib/languages/llvm'
import lsl from 'highlight.js/lib/languages/lsl'
import mathematica from 'highlight.js/lib/languages/mathematica'
import matlab from 'highlight.js/lib/languages/matlab'
import maxima from 'highlight.js/lib/languages/maxima'
import mel from 'highlight.js/lib/languages/mel'
import mercury from 'highlight.js/lib/languages/mercury'
import mipsasm from 'highlight.js/lib/languages/mipsasm'
import mizar from 'highlight.js/lib/languages/mizar'
import mojolicious from 'highlight.js/lib/languages/mojolicious'
import monkey from 'highlight.js/lib/languages/monkey'
import moonscript from 'highlight.js/lib/languages/moonscript'
import n1ql from 'highlight.js/lib/languages/n1ql'
import nestedtext from 'highlight.js/lib/languages/nestedtext'
import nginx from 'highlight.js/lib/languages/nginx'
import nim from 'highlight.js/lib/languages/nim'
import nix from 'highlight.js/lib/languages/nix'
import nodeRepl from 'highlight.js/lib/languages/node-repl'
import nsis from 'highlight.js/lib/languages/nsis'
import ocaml from 'highlight.js/lib/languages/ocaml'
import openscad from 'highlight.js/lib/languages/openscad'
import oxygene from 'highlight.js/lib/languages/oxygene'
import parser3 from 'highlight.js/lib/languages/parser3'
import pf from 'highlight.js/lib/languages/pf'
import pgsql from 'highlight.js/lib/languages/pgsql'
import pony from 'highlight.js/lib/languages/pony'
import powershell from 'highlight.js/lib/languages/powershell'
import processing from 'highlight.js/lib/languages/processing'
import profile from 'highlight.js/lib/languages/profile'
import prolog from 'highlight.js/lib/languages/prolog'
import properties from 'highlight.js/lib/languages/properties'
import protobuf from 'highlight.js/lib/languages/protobuf'
import puppet from 'highlight.js/lib/languages/puppet'
import purebasic from 'highlight.js/lib/languages/purebasic'
import q from 'highlight.js/lib/languages/q'
import qml from 'highlight.js/lib/languages/qml'
import reasonml from 'highlight.js/lib/languages/reasonml'
import rib from 'highlight.js/lib/languages/rib'
import roboconf from 'highlight.js/lib/languages/roboconf'
import routeros from 'highlight.js/lib/languages/routeros'
import rsl from 'highlight.js/lib/languages/rsl'
import ruleslanguage from 'highlight.js/lib/languages/ruleslanguage'
import sas from 'highlight.js/lib/languages/sas'
import scala from 'highlight.js/lib/languages/scala'
import scheme from 'highlight.js/lib/languages/scheme'
import scilab from 'highlight.js/lib/languages/scilab'
import smali from 'highlight.js/lib/languages/smali'
import smalltalk from 'highlight.js/lib/languages/smalltalk'
import sml from 'highlight.js/lib/languages/sml'
import sqf from 'highlight.js/lib/languages/sqf'
import stan from 'highlight.js/lib/languages/stan'
import stata from 'highlight.js/lib/languages/stata'
import step21 from 'highlight.js/lib/languages/step21'
import stylus from 'highlight.js/lib/languages/stylus'
import subunit from 'highlight.js/lib/languages/subunit'
import taggerscript from 'highlight.js/lib/languages/taggerscript'
import tap from 'highlight.js/lib/languages/tap'
import tcl from 'highlight.js/lib/languages/tcl'
import thrift from 'highlight.js/lib/languages/thrift'
import tp from 'highlight.js/lib/languages/tp'
import twig from 'highlight.js/lib/languages/twig'
import vala from 'highlight.js/lib/languages/vala'
import vbscript from 'highlight.js/lib/languages/vbscript'
import vbscriptHtml from 'highlight.js/lib/languages/vbscript-html'
import verilog from 'highlight.js/lib/languages/verilog'
import vhdl from 'highlight.js/lib/languages/vhdl'
import vim from 'highlight.js/lib/languages/vim'
import wren from 'highlight.js/lib/languages/wren'
import x86asm from 'highlight.js/lib/languages/x86asm'
import xl from 'highlight.js/lib/languages/xl'
import xquery from 'highlight.js/lib/languages/xquery'
import zephir from 'highlight.js/lib/languages/zephir'
import {grammars as base} from './common.js'
/**
* Map of grammars.
*
* @type {Record<string, LanguageFn>}
*/
export const grammars = {
...base,
'1c': $1c,
abnf,
accesslog,
actionscript,
ada,
angelscript,
apache,
applescript,
arcade,
armasm,
asciidoc,
aspectj,
autohotkey,
autoit,
avrasm,
awk,
axapta,
basic,
bnf,
brainfuck,
cal,
capnproto,
ceylon,
clean,
clojure,
'clojure-repl': clojureRepl,
cmake,
coffeescript,
coq,
cos,
crmsh,
crystal,
csp,
d,
dart,
delphi,
django,
dns,
dockerfile,
dos,
dsconfig,
dts,
dust,
ebnf,
elixir,
elm,
erb,
erlang,
'erlang-repl': erlangRepl,
excel,
fix,
flix,
fortran,
fsharp,
gams,
gauss,
gcode,
gherkin,
glsl,
gml,
golo,
gradle,
groovy,
haml,
handlebars,
haskell,
haxe,
hsp,
http,
hy,
inform7,
irpf90,
isbl,
'jboss-cli': jbossCli,
julia,
'julia-repl': juliaRepl,
lasso,
latex,
ldif,
leaf,
lisp,
livecodeserver,
livescript,
llvm,
lsl,
mathematica,
matlab,
maxima,
mel,
mercury,
mipsasm,
mizar,
mojolicious,
monkey,
moonscript,
n1ql,
nestedtext,
nginx,
nim,
nix,
'node-repl': nodeRepl,
nsis,
ocaml,
openscad,
oxygene,
parser3,
pf,
pgsql,
pony,
powershell,
processing,
profile,
prolog,
properties,
protobuf,
puppet,
purebasic,
q,
qml,
reasonml,
rib,
roboconf,
routeros,
rsl,
ruleslanguage,
sas,
scala,
scheme,
scilab,
smali,
smalltalk,
sml,
sqf,
stan,
stata,
step21,
stylus,
subunit,
taggerscript,
tap,
tcl,
thrift,
tp,
twig,
vala,
vbscript,
'vbscript-html': vbscriptHtml,
verilog,
vhdl,
vim,
wren,
x86asm,
xl,
xquery,
zephir
}

8
node_modules/lowlight/lib/common.d.ts generated vendored Normal file
View File

@@ -0,0 +1,8 @@
/**
* Map of grammars.
*
* @type {Record<string, LanguageFn>}
*/
export const grammars: Record<string, LanguageFn>;
import type { LanguageFn } from 'highlight.js';
//# sourceMappingURL=common.d.ts.map

1
node_modules/lowlight/lib/common.d.ts.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["common.js"],"names":[],"mappings":"AA2CA;;;;GAIG;AACH,uBAFU,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAwCnC;gCArF4B,cAAc"}

86
node_modules/lowlight/lib/common.js generated vendored Normal file
View File

@@ -0,0 +1,86 @@
/**
* @import {LanguageFn} from 'highlight.js'
*/
import arduino from 'highlight.js/lib/languages/arduino'
import bash from 'highlight.js/lib/languages/bash'
import c from 'highlight.js/lib/languages/c'
import cpp from 'highlight.js/lib/languages/cpp'
import csharp from 'highlight.js/lib/languages/csharp'
import css from 'highlight.js/lib/languages/css'
import diff from 'highlight.js/lib/languages/diff'
import go from 'highlight.js/lib/languages/go'
import graphql from 'highlight.js/lib/languages/graphql'
import ini from 'highlight.js/lib/languages/ini'
import java from 'highlight.js/lib/languages/java'
import javascript from 'highlight.js/lib/languages/javascript'
import json from 'highlight.js/lib/languages/json'
import kotlin from 'highlight.js/lib/languages/kotlin'
import less from 'highlight.js/lib/languages/less'
import lua from 'highlight.js/lib/languages/lua'
import makefile from 'highlight.js/lib/languages/makefile'
import markdown from 'highlight.js/lib/languages/markdown'
import objectivec from 'highlight.js/lib/languages/objectivec'
import perl from 'highlight.js/lib/languages/perl'
import php from 'highlight.js/lib/languages/php'
import phpTemplate from 'highlight.js/lib/languages/php-template'
import plaintext from 'highlight.js/lib/languages/plaintext'
import python from 'highlight.js/lib/languages/python'
import pythonRepl from 'highlight.js/lib/languages/python-repl'
import r from 'highlight.js/lib/languages/r'
import ruby from 'highlight.js/lib/languages/ruby'
import rust from 'highlight.js/lib/languages/rust'
import scss from 'highlight.js/lib/languages/scss'
import shell from 'highlight.js/lib/languages/shell'
import sql from 'highlight.js/lib/languages/sql'
import swift from 'highlight.js/lib/languages/swift'
import typescript from 'highlight.js/lib/languages/typescript'
import vbnet from 'highlight.js/lib/languages/vbnet'
import wasm from 'highlight.js/lib/languages/wasm'
import xml from 'highlight.js/lib/languages/xml'
import yaml from 'highlight.js/lib/languages/yaml'
/**
* Map of grammars.
*
* @type {Record<string, LanguageFn>}
*/
export const grammars = {
arduino,
bash,
c,
cpp,
csharp,
css,
diff,
go,
graphql,
ini,
java,
javascript,
json,
kotlin,
less,
lua,
makefile,
markdown,
objectivec,
perl,
php,
'php-template': phpTemplate,
plaintext,
python,
'python-repl': pythonRepl,
r,
ruby,
rust,
scss,
shell,
sql,
swift,
typescript,
vbnet,
wasm,
xml,
yaml
}

197
node_modules/lowlight/lib/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,197 @@
/**
* Create a `lowlight` instance.
*
* @param {Readonly<Record<string, LanguageFn>> | null | undefined} [grammars]
* Grammars to add (optional).
* @returns
* Lowlight.
*/
export function createLowlight(grammars?: Readonly<Record<string, LanguageFn>> | null | undefined): {
highlight: (language: string, value: string, options?: Readonly<Options> | null | undefined) => Root;
highlightAuto: (value: string, options?: Readonly<AutoOptions> | null | undefined) => Root;
listLanguages: () => Array<string>;
register: {
/**
* Register languages.
*
* @example
* ```js
* import {createLowlight} from 'lowlight'
* import xml from 'highlight.js/lib/languages/xml'
*
* const lowlight = createLowlight()
*
* lowlight.register({xml})
*
* // Note: `html` is an alias for `xml`.
* console.log(lowlight.highlight('html', '<em>Emphasis</em>'))
* ```
*
* Yields:
*
* ```js
* {type: 'root', children: [Array], data: {language: 'html', relevance: 2}}
* ```
*
* @overload
* @param {Readonly<Record<string, LanguageFn>>} grammars
* @returns {undefined}
*
* @overload
* @param {string} name
* @param {LanguageFn} grammar
* @returns {undefined}
*
* @param {Readonly<Record<string, LanguageFn>> | string} grammarsOrName
* Grammars or programming language name.
* @param {LanguageFn | undefined} [grammar]
* Grammar, if with name.
* @returns {undefined}
* Nothing.
*/
(grammars: Readonly<Record<string, LanguageFn>>): undefined;
/**
* Register languages.
*
* @example
* ```js
* import {createLowlight} from 'lowlight'
* import xml from 'highlight.js/lib/languages/xml'
*
* const lowlight = createLowlight()
*
* lowlight.register({xml})
*
* // Note: `html` is an alias for `xml`.
* console.log(lowlight.highlight('html', '<em>Emphasis</em>'))
* ```
*
* Yields:
*
* ```js
* {type: 'root', children: [Array], data: {language: 'html', relevance: 2}}
* ```
*
* @overload
* @param {Readonly<Record<string, LanguageFn>>} grammars
* @returns {undefined}
*
* @overload
* @param {string} name
* @param {LanguageFn} grammar
* @returns {undefined}
*
* @param {Readonly<Record<string, LanguageFn>> | string} grammarsOrName
* Grammars or programming language name.
* @param {LanguageFn | undefined} [grammar]
* Grammar, if with name.
* @returns {undefined}
* Nothing.
*/
(name: string, grammar: LanguageFn): undefined;
};
registerAlias: {
/**
* Register aliases.
*
* @example
* ```js
* import {createLowlight} from 'lowlight'
* import markdown from 'highlight.js/lib/languages/markdown'
*
* const lowlight = createLowlight()
*
* lowlight.register({markdown})
*
* // lowlight.highlight('mdown', '<em>Emphasis</em>')
* // ^ would throw: Error: Unknown language: `mdown` is not registered
*
* lowlight.registerAlias({markdown: ['mdown', 'mkdn', 'mdwn', 'ron']})
* lowlight.highlight('mdown', '<em>Emphasis</em>')
* // ^ Works!
* ```
*
* @overload
* @param {Readonly<Record<string, ReadonlyArray<string> | string>>} aliases
* @returns {undefined}
*
* @overload
* @param {string} language
* @param {ReadonlyArray<string> | string} alias
* @returns {undefined}
*
* @param {Readonly<Record<string, ReadonlyArray<string> | string>> | string} aliasesOrName
* Map of programming language names to one or more aliases, or programming
* language name.
* @param {ReadonlyArray<string> | string | undefined} [alias]
* One or more aliases for the programming language, if with `name`.
* @returns {undefined}
* Nothing.
*/
(aliases: Readonly<Record<string, ReadonlyArray<string> | string>>): undefined;
/**
* Register aliases.
*
* @example
* ```js
* import {createLowlight} from 'lowlight'
* import markdown from 'highlight.js/lib/languages/markdown'
*
* const lowlight = createLowlight()
*
* lowlight.register({markdown})
*
* // lowlight.highlight('mdown', '<em>Emphasis</em>')
* // ^ would throw: Error: Unknown language: `mdown` is not registered
*
* lowlight.registerAlias({markdown: ['mdown', 'mkdn', 'mdwn', 'ron']})
* lowlight.highlight('mdown', '<em>Emphasis</em>')
* // ^ Works!
* ```
*
* @overload
* @param {Readonly<Record<string, ReadonlyArray<string> | string>>} aliases
* @returns {undefined}
*
* @overload
* @param {string} language
* @param {ReadonlyArray<string> | string} alias
* @returns {undefined}
*
* @param {Readonly<Record<string, ReadonlyArray<string> | string>> | string} aliasesOrName
* Map of programming language names to one or more aliases, or programming
* language name.
* @param {ReadonlyArray<string> | string | undefined} [alias]
* One or more aliases for the programming language, if with `name`.
* @returns {undefined}
* Nothing.
*/
(language: string, alias: ReadonlyArray<string> | string): undefined;
};
registered: (aliasOrName: string) => boolean;
};
/**
* Extra fields.
*/
export type ExtraOptions = {
/**
* List of allowed languages (default: all registered languages).
*/
subset?: ReadonlyArray<string> | null | undefined;
};
/**
* Configuration for `highlight`.
*/
export type Options = {
/**
* Class prefix (default: `'hljs-'`).
*/
prefix?: string | null | undefined;
};
/**
* Configuration for `highlightAuto`.
*/
export type AutoOptions = Options & ExtraOptions;
import type { LanguageFn } from 'highlight.js';
import type { Root } from 'hast';
//# sourceMappingURL=index.d.ts.map

1
node_modules/lowlight/lib/index.d.ts.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.js"],"names":[],"mappings":"AA4BA;;;;;;;GAOG;AACH,0CALW,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,GAAG,IAAI,GAAG,SAAS;0BAuCrD,MAAM,SAEN,MAAM,YAEN,QAAQ,CAAC,OAAO,CAAC,GAAG,IAAI,GAAG,SAAS,KAElC,IAAI;2BA6DN,MAAM,YAEN,QAAQ,CAAC,WAAW,CAAC,GAAG,IAAI,GAAG,SAAS,KAEtC,IAAI;yBA0DJ,KAAK,CAAC,MAAM,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mBA8Bf,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,GAClC,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;eAGX,MAAM,WACN,UAAU,GACR,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBA8CX,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC,GACtD,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mBAGX,MAAM,SACN,aAAa,CAAC,MAAM,CAAC,GAAG,MAAM,GAC5B,SAAS;;8BAmDX,MAAM,KAEJ,OAAO;EAMrB;;;;;;;;aAlVa,aAAa,CAAC,MAAM,CAAC,GAAG,IAAI,GAAG,SAAS;;;;;;;;;aAKxC,MAAM,GAAG,IAAI,GAAG,SAAS;;;;;0BAG1B,OAAO,GAAG,YAAY;gCAdgD,cAAc;0BADvC,MAAM"}

482
node_modules/lowlight/lib/index.js generated vendored Normal file
View File

@@ -0,0 +1,482 @@
/**
* @import {ElementContent, Element, RootData, Root} from 'hast'
* @import {Emitter, HLJSOptions as HljsOptions, HighlightResult, LanguageFn} from 'highlight.js'
*/
/**
* @typedef {Object} ExtraOptions
* Extra fields.
* @property {ReadonlyArray<string> | null | undefined} [subset]
* List of allowed languages (default: all registered languages).
*
* @typedef Options
* Configuration for `highlight`.
* @property {string | null | undefined} [prefix='hljs-']
* Class prefix (default: `'hljs-'`).
*
* @typedef {Options & ExtraOptions} AutoOptions
* Configuration for `highlightAuto`.
*/
import {ok as assert} from 'devlop'
import HighlightJs from 'highlight.js/lib/core'
/** @type {AutoOptions} */
const emptyOptions = {}
const defaultPrefix = 'hljs-'
/**
* Create a `lowlight` instance.
*
* @param {Readonly<Record<string, LanguageFn>> | null | undefined} [grammars]
* Grammars to add (optional).
* @returns
* Lowlight.
*/
export function createLowlight(grammars) {
const high = HighlightJs.newInstance()
if (grammars) {
register(grammars)
}
return {
highlight,
highlightAuto,
listLanguages,
register,
registerAlias,
registered
}
/**
* Highlight `value` (code) as `language` (name).
*
* @example
* ```js
* import {common, createLowlight} from 'lowlight'
*
* const lowlight = createLowlight(common)
*
* console.log(lowlight.highlight('css', 'em { color: red }'))
* ```
*
* Yields:
*
* ```js
* {type: 'root', children: [Array], data: {language: 'css', relevance: 3}}
* ```
*
* @param {string} language
* Programming language name.
* @param {string} value
* Code to highlight.
* @param {Readonly<Options> | null | undefined} [options={}]
* Configuration (optional).
* @returns {Root}
* Tree; with the following `data` fields: `language` (`string`), detected
* programming language name; `relevance` (`number`), how sure lowlight is
* that the given code is in the language.
*/
function highlight(language, value, options) {
assert(typeof language === 'string', 'expected `string` as `name`')
assert(typeof value === 'string', 'expected `string` as `value`')
const settings = options || emptyOptions
const prefix =
typeof settings.prefix === 'string' ? settings.prefix : defaultPrefix
if (!high.getLanguage(language)) {
throw new Error('Unknown language: `' + language + '` is not registered')
}
// See: <https://github.com/highlightjs/highlight.js/issues/3621#issuecomment-1528841888>
high.configure({__emitter: HastEmitter, classPrefix: prefix})
const result = /** @type {HighlightResult & {_emitter: HastEmitter}} */ (
high.highlight(value, {ignoreIllegals: true, language})
)
// `highlight.js` seems to use this (currently) for broken grammars, so lets
// keep it in there just to be sure.
/* c8 ignore next 5 */
if (result.errorRaised) {
throw new Error('Could not highlight with `Highlight.js`', {
cause: result.errorRaised
})
}
const root = result._emitter.root
// Cast because it is always defined.
const data = /** @type {RootData} */ (root.data)
data.language = result.language
data.relevance = result.relevance
return root
}
/**
* Highlight `value` (code) and guess its programming language.
*
* @example
* ```js
* import {common, createLowlight} from 'lowlight'
*
* const lowlight = createLowlight(common)
*
* console.log(lowlight.highlightAuto('"hello, " + name + "!"'))
* ```
*
* Yields:
*
* ```js
* {type: 'root', children: [Array], data: {language: 'arduino', relevance: 2}}
* ```
*
* @param {string} value
* Code to highlight.
* @param {Readonly<AutoOptions> | null | undefined} [options={}]
* Configuration (optional).
* @returns {Root}
* Tree; with the following `data` fields: `language` (`string`), detected
* programming language name; `relevance` (`number`), how sure lowlight is
* that the given code is in the language.
*/
function highlightAuto(value, options) {
assert(typeof value === 'string', 'expected `string` as `value`')
const settings = options || emptyOptions
const subset = settings.subset || listLanguages()
let index = -1
let relevance = 0
/** @type {Root | undefined} */
let result
while (++index < subset.length) {
const name = subset[index]
if (!high.getLanguage(name)) continue
const current = highlight(name, value, options)
if (
current.data &&
current.data.relevance !== undefined &&
current.data.relevance > relevance
) {
relevance = current.data.relevance
result = current
}
}
return (
result || {
type: 'root',
children: [],
data: {language: undefined, relevance}
}
)
}
/**
* List registered languages.
*
* @example
* ```js
* import {createLowlight} from 'lowlight'
* import markdown from 'highlight.js/lib/languages/markdown'
*
* const lowlight = createLowlight()
*
* console.log(lowlight.listLanguages()) // => []
*
* lowlight.register({markdown})
*
* console.log(lowlight.listLanguages()) // => ['markdown']
* ```
*
* @returns {Array<string>}
* Names of registered language.
*/
function listLanguages() {
return high.listLanguages()
}
/**
* Register languages.
*
* @example
* ```js
* import {createLowlight} from 'lowlight'
* import xml from 'highlight.js/lib/languages/xml'
*
* const lowlight = createLowlight()
*
* lowlight.register({xml})
*
* // Note: `html` is an alias for `xml`.
* console.log(lowlight.highlight('html', '<em>Emphasis</em>'))
* ```
*
* Yields:
*
* ```js
* {type: 'root', children: [Array], data: {language: 'html', relevance: 2}}
* ```
*
* @overload
* @param {Readonly<Record<string, LanguageFn>>} grammars
* @returns {undefined}
*
* @overload
* @param {string} name
* @param {LanguageFn} grammar
* @returns {undefined}
*
* @param {Readonly<Record<string, LanguageFn>> | string} grammarsOrName
* Grammars or programming language name.
* @param {LanguageFn | undefined} [grammar]
* Grammar, if with name.
* @returns {undefined}
* Nothing.
*/
function register(grammarsOrName, grammar) {
if (typeof grammarsOrName === 'string') {
assert(grammar !== undefined, 'expected `grammar`')
high.registerLanguage(grammarsOrName, grammar)
} else {
/** @type {string} */
let name
for (name in grammarsOrName) {
if (Object.hasOwn(grammarsOrName, name)) {
high.registerLanguage(name, grammarsOrName[name])
}
}
}
}
/**
* Register aliases.
*
* @example
* ```js
* import {createLowlight} from 'lowlight'
* import markdown from 'highlight.js/lib/languages/markdown'
*
* const lowlight = createLowlight()
*
* lowlight.register({markdown})
*
* // lowlight.highlight('mdown', '<em>Emphasis</em>')
* // ^ would throw: Error: Unknown language: `mdown` is not registered
*
* lowlight.registerAlias({markdown: ['mdown', 'mkdn', 'mdwn', 'ron']})
* lowlight.highlight('mdown', '<em>Emphasis</em>')
* // ^ Works!
* ```
*
* @overload
* @param {Readonly<Record<string, ReadonlyArray<string> | string>>} aliases
* @returns {undefined}
*
* @overload
* @param {string} language
* @param {ReadonlyArray<string> | string} alias
* @returns {undefined}
*
* @param {Readonly<Record<string, ReadonlyArray<string> | string>> | string} aliasesOrName
* Map of programming language names to one or more aliases, or programming
* language name.
* @param {ReadonlyArray<string> | string | undefined} [alias]
* One or more aliases for the programming language, if with `name`.
* @returns {undefined}
* Nothing.
*/
function registerAlias(aliasesOrName, alias) {
if (typeof aliasesOrName === 'string') {
assert(alias !== undefined)
high.registerAliases(
// Note: copy needed because hljs doesnt accept readonly arrays yet.
typeof alias === 'string' ? alias : [...alias],
{languageName: aliasesOrName}
)
} else {
/** @type {string} */
let key
for (key in aliasesOrName) {
if (Object.hasOwn(aliasesOrName, key)) {
const aliases = aliasesOrName[key]
high.registerAliases(
// Note: copy needed because hljs doesnt accept readonly arrays yet.
typeof aliases === 'string' ? aliases : [...aliases],
{languageName: key}
)
}
}
}
}
/**
* Check whether an alias or name is registered.
*
* @example
* ```js
* import {createLowlight} from 'lowlight'
* import javascript from 'highlight.js/lib/languages/javascript'
*
* const lowlight = createLowlight({javascript})
*
* console.log(lowlight.registered('funkyscript')) // => `false`
*
* lowlight.registerAlias({javascript: 'funkyscript'})
* console.log(lowlight.registered('funkyscript')) // => `true`
* ```
*
* @param {string} aliasOrName
* Name of a language or alias for one.
* @returns {boolean}
* Whether `aliasOrName` is registered.
*/
function registered(aliasOrName) {
return Boolean(high.getLanguage(aliasOrName))
}
}
/** @type {Emitter} */
class HastEmitter {
/**
* @param {Readonly<HljsOptions>} options
* Configuration.
* @returns
* Instance.
*/
constructor(options) {
/** @type {HljsOptions} */
this.options = options
/** @type {Root} */
this.root = {
type: 'root',
children: [],
data: {language: undefined, relevance: 0}
}
/** @type {[Root, ...Array<Element>]} */
this.stack = [this.root]
}
/**
* @param {string} value
* Text to add.
* @returns {undefined}
* Nothing.
*
*/
addText(value) {
if (value === '') return
const current = this.stack[this.stack.length - 1]
const tail = current.children[current.children.length - 1]
if (tail && tail.type === 'text') {
tail.value += value
} else {
current.children.push({type: 'text', value})
}
}
/**
*
* @param {unknown} rawName
* Name to add.
* @returns {undefined}
* Nothing.
*/
startScope(rawName) {
this.openNode(String(rawName))
}
/**
* @returns {undefined}
* Nothing.
*/
endScope() {
this.closeNode()
}
/**
* @param {HastEmitter} other
* Other emitter.
* @param {string} name
* Name of the sublanguage.
* @returns {undefined}
* Nothing.
*/
__addSublanguage(other, name) {
const current = this.stack[this.stack.length - 1]
// Assume only element content.
const results = /** @type {Array<ElementContent>} */ (other.root.children)
if (name) {
current.children.push({
type: 'element',
tagName: 'span',
properties: {className: [name]},
children: results
})
} else {
current.children.push(...results)
}
}
/**
* @param {string} name
* Name to add.
* @returns {undefined}
* Nothing.
*/
openNode(name) {
const self = this
// First “class” gets the prefix. Rest gets a repeated underscore suffix.
// See: <https://github.com/highlightjs/highlight.js/commit/51806aa>
// See: <https://github.com/wooorm/lowlight/issues/43>
const className = name.split('.').map(function (d, i) {
return i ? d + '_'.repeat(i) : self.options.classPrefix + d
})
const current = this.stack[this.stack.length - 1]
/** @type {Element} */
const child = {
type: 'element',
tagName: 'span',
properties: {className},
children: []
}
current.children.push(child)
this.stack.push(child)
}
/**
* @returns {undefined}
* Nothing.
*/
closeNode() {
this.stack.pop()
}
/**
* @returns {undefined}
* Nothing.
*/
finalize() {}
/**
* @returns {string}
* Nothing.
*/
toHTML() {
return ''
}
}

22
node_modules/lowlight/license generated vendored Normal file
View File

@@ -0,0 +1,22 @@
(The MIT License)
Copyright (c) Titus Wormer <tituswormer@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

114
node_modules/lowlight/package.json generated vendored Normal file
View File

@@ -0,0 +1,114 @@
{
"name": "lowlight",
"version": "3.3.0",
"description": "Virtual syntax highlighting for virtual DOMs and non-HTML things",
"license": "MIT",
"keywords": [
"syntax",
"code",
"ast",
"virtual",
"dom",
"highlight",
"highlighting"
],
"repository": "wooorm/lowlight",
"bugs": "https://github.com/wooorm/lowlight/issues",
"funding": {
"type": "github",
"url": "https://github.com/sponsors/wooorm"
},
"author": "Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)",
"contributors": [
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)",
"Ezra Lalonde <ezra@usefuliftrue.com>",
"Shu Uesugi <shu@chibicode.com>"
],
"sideEffects": false,
"type": "module",
"exports": "./index.js",
"files": [
"lib/",
"index.d.ts",
"index.js"
],
"dependencies": {
"@types/hast": "^3.0.0",
"devlop": "^1.0.0",
"highlight.js": "~11.11.0"
},
"devDependencies": {
"@types/mdast": "^4.0.0",
"@types/node": "^22.0.0",
"@types/unist": "^3.0.0",
"c8": "^10.0.0",
"chalk": "^5.0.0",
"estree-util-is-identifier-name": "^3.0.0",
"hast-util-to-html": "^9.0.0",
"mdast-zone": "^6.0.0",
"prettier": "^3.0.0",
"remark-cli": "^12.0.0",
"remark-preset-wooorm": "^10.0.0",
"type-coverage": "^2.0.0",
"typescript": "^5.0.0",
"unified": "^11.0.0",
"xo": "^0.60.0"
},
"scripts": {
"build": "tsc --build --clean && tsc --build && type-coverage",
"format": "remark . --frail --output --quiet && prettier . --log-level warn --write && xo --fix",
"generate": "node --conditions development script/build-registry.js",
"prepack": "npm run generate && npm run build && npm run format",
"test": "npm run generate && npm run build && npm run format && npm run test-coverage",
"test-api": "node --conditions development test/index.js",
"test-coverage": "c8 --100 --check-coverage --reporter lcov npm run test-api"
},
"prettier": {
"bracketSpacing": false,
"singleQuote": true,
"semi": false,
"tabWidth": 2,
"trailingComma": "none",
"useTabs": false
},
"remarkConfig": {
"plugins": [
"remark-preset-wooorm",
"./script/support.js"
]
},
"typeCoverage": {
"atLeast": 100,
"detail": true,
"ignoreCatch": true,
"strict": true
},
"xo": {
"overrides": [
{
"files": [
"**/*.ts"
],
"rules": {
"@typescript-eslint/consistent-type-definitions": "off"
}
},
{
"files": [
"script/**/*.js",
"test/**/*.js"
],
"rules": {
"no-await-in-loop": "off"
}
}
],
"prettier": true,
"rules": {
"n/file-extension-in-import": "off",
"unicorn/no-this-assignment": "off",
"unicorn/prefer-at": "off",
"unicorn/prefer-type-error": "off"
}
}
}

786
node_modules/lowlight/readme.md generated vendored Normal file
View File

@@ -0,0 +1,786 @@
<!--lint disable no-html-->
# lowlight
[![Build][build-badge]][build]
[![Coverage][coverage-badge]][coverage]
[![Downloads][downloads-badge]][downloads]
[![Size][size-badge]][size]
Virtual syntax highlighting for virtual DOMs and non-HTML things based on
[`highlight.js`][highlight-js].
## Contents
* [What is this?](#what-is-this)
* [When should I use this?](#when-should-i-use-this)
* [Install](#install)
* [Use](#use)
* [API](#api)
* [`all`](#all)
* [`common`](#common)
* [`createLowlight([grammars])`](#createlowlightgrammars)
* [`lowlight.highlight(language, value[, options])`](#lowlighthighlightlanguage-value-options)
* [`lowlight.highlightAuto(value[, options])`](#lowlighthighlightautovalue-options)
* [`lowlight.listLanguages()`](#lowlightlistlanguages)
* [`lowlight.register(grammars)`](#lowlightregistergrammars)
* [`lowlight.registerAlias(aliases)`](#lowlightregisteraliasaliases)
* [`lowlight.registered(aliasOrlanguage)`](#lowlightregisteredaliasorlanguage)
* [`AutoOptions`](#autooptions)
* [`LanguageFn`](#languagefn)
* [`Options`](#options)
* [Examples](#examples)
* [Example: serializing hast as html](#example-serializing-hast-as-html)
* [Example: turning hast into preact, react, etc](#example-turning-hast-into-preact-react-etc)
* [Types](#types)
* [Data](#data)
* [CSS](#css)
* [Compatibility](#compatibility)
* [Security](#security)
* [Related](#related)
* [Projects](#projects)
* [Contribute](#contribute)
* [License](#license)
## What is this?
This package uses [`highlight.js`][highlight-js] for syntax highlighting and
outputs objects (ASTs) instead of a string of HTML.
It can support 190+ programming languages.
## When should I use this?
This package is useful when you want to perform syntax highlighting in a place
where serialized HTML wouldnt work or wouldnt work well.
For example, you can use lowlight when you want to show code in a CLI by
rendering to ANSI sequences, when youre using virtual DOM frameworks (such as
React or Preact) so that diffing can be performant, or when youre working with
ASTs (rehype).
You can use the similar [`refractor`][refractor] if you want to use [Prism][]
grammars instead.
If youre looking for a *really good* (but rather heavy) alternative, use
[`starry-night`][starry-night].
## Install
This package is [ESM only][esm].
In Node.js (version 16+), install with [npm][]:
```sh
npm install lowlight
```
In Deno with [`esm.sh`][esmsh]:
```js
import {all, common, createLowlight} from 'https://esm.sh/lowlight@3'
```
In browsers with [`esm.sh`][esmsh]:
```html
<script type="module">
import {all, common, createLowlight} from 'https://esm.sh/lowlight@3?bundle'
</script>
```
## Use
```js
import {common, createLowlight} from 'lowlight'
const lowlight = createLowlight(common)
const tree = lowlight.highlight('js', '"use strict";')
console.dir(tree, {depth: undefined})
```
Yields:
```js
{
type: 'root',
children: [
{
type: 'element',
tagName: 'span',
properties: {className: ['hljs-meta']},
children: [{type: 'text', value: '"use strict"'}]
},
{type: 'text', value: ';'}
],
data: {language: 'js', relevance: 10}
}
```
## API
This package exports the identifiers [`all`][api-all],
[`common`][api-common], and
[`createLowlight`][api-create-lowlight].
There is no default export.
### `all`
Map of all (±190) grammars ([`Record<string, LanguageFn>`][api-language-fn]).
### `common`
Map of common (37) grammars ([`Record<string, LanguageFn>`][api-language-fn]).
### `createLowlight([grammars])`
Create a `lowlight` instance.
###### Parameters
* `grammars` ([`Record<string, LanguageFn>`][api-language-fn], optional)
— grammars to add
###### Returns
Lowlight (`Lowlight`).
### `lowlight.highlight(language, value[, options])`
Highlight `value` (code) as `language` (name).
###### Parameters
* `language` (`string`)
— programming language [name][names]
* `value` (`string`)
— code to highlight
* `options` ([`Options`][api-options], optional)
— configuration
###### Returns
Tree ([`Root`][hast-root]); with the following `data` fields: `language`
(`string`), detected programming language name; `relevance` (`number`), how
sure lowlight is that the given code is in the language.
###### Example
```js
import {common, createLowlight} from 'lowlight'
const lowlight = createLowlight(common)
console.log(lowlight.highlight('css', 'em { color: red }'))
```
Yields:
```js
{type: 'root', children: [Array], data: {language: 'css', relevance: 3}}
```
### `lowlight.highlightAuto(value[, options])`
Highlight `value` (code) and guess its programming language.
###### Parameters
* `value` (`string`)
— code to highlight
* `options` ([`AutoOptions`][api-auto-options], optional)
— configuration
###### Returns
Tree ([`Root`][hast-root]); with the following `data` fields: `language`
(`string`), detected programming language name; `relevance` (`number`), how
sure lowlight is that the given code is in the language.
###### Example
```js
import {common, createLowlight} from 'lowlight'
const lowlight = createLowlight(common)
console.log(lowlight.highlightAuto('"hello, " + name + "!"'))
```
Yields:
```js
{type: 'root', children: [Array], data: {language: 'arduino', relevance: 2}}
```
### `lowlight.listLanguages()`
List registered languages.
###### Returns
[Names][] of registered language (`Array<string>`).
###### Example
```js
import {createLowlight} from 'lowlight'
import markdown from 'highlight.js/lib/languages/markdown'
const lowlight = createLowlight()
console.log(lowlight.listLanguages()) // => []
lowlight.register({markdown})
console.log(lowlight.listLanguages()) // => ['markdown']
```
### `lowlight.register(grammars)`
Register languages.
###### Signatures
* `register(name, grammar)`
* `register(grammars)`
###### Parameters
* `name` (`string`)
— programming language [name][names]
* `grammar` ([`LanguageFn`][api-language-fn])
— grammar
* `grammars` ([`Record<string, LanguageFn>`][api-language-fn], optional)
— grammars
###### Returns
Nothing (`undefined`).
###### Example
```js
import {createLowlight} from 'lowlight'
import xml from 'highlight.js/lib/languages/xml'
const lowlight = createLowlight()
lowlight.register({xml})
// Note: `html` is an alias for `xml`.
console.log(lowlight.highlight('html', '<em>Emphasis</em>'))
```
Yields:
```js
{type: 'root', children: [Array], data: {language: 'html', relevance: 2}}
```
### `lowlight.registerAlias(aliases)`
Register aliases.
###### Signatures
* `registerAlias(aliases)`
* `registerAlias(name, alias)`
###### Parameters
* `aliases` (`Record<string, Array<string> | string>`)
— map of programming language [names][] to one or more aliases
* `name` (`string`)
— programming language [name][names]
* `alias` (`Array<string> | string`)
— one or more aliases for the programming language
###### Returns
Nothing (`undefined`).
###### Example
```js
import {createLowlight} from 'lowlight'
import markdown from 'highlight.js/lib/languages/markdown'
const lowlight = createLowlight()
lowlight.register({markdown})
// lowlight.highlight('mdown', '<em>Emphasis</em>')
// ^ would throw: Error: Unknown language: `mdown` is not registered
lowlight.registerAlias({markdown: ['mdown', 'mkdn', 'mdwn', 'ron']})
lowlight.highlight('mdown', '<em>Emphasis</em>')
// ^ Works!
```
### `lowlight.registered(aliasOrlanguage)`
Check whether an alias or name is registered.
###### Parameters
* `aliasOrlanguage` (`string`)
— [name][names] of a language or alias for one
###### Returns
Whether `aliasOrName` is registered (`boolean`).
###### Example
```js
import {createLowlight} from 'lowlight'
import javascript from 'highlight.js/lib/languages/javascript'
const lowlight = createLowlight({javascript})
console.log(lowlight.registered('funkyscript')) // => `false`
lowlight.registerAlias({javascript: 'funkyscript'})
console.log(lowlight.registered('funkyscript')) // => `true`
```
### `AutoOptions`
Configuration for `highlightAuto` (TypeScript type).
###### Fields
* `prefix` (`string`, default: `'hljs-'`)
— class prefix
* `subset` (`Array<string>`, default: all registered languages)
— list of allowed languages
### `LanguageFn`
Highlight.js grammar (TypeScript type).
###### Type
```ts
type {LanguageFn} from 'highlight.js'
```
### `Options`
Configuration for `highlight` (TypeScript type).
###### Fields
* `prefix` (`string`, default: `'hljs-'`)
— class prefix
## Examples
### Example: serializing hast as html
hast trees as returned by lowlight can be serialized with
[`hast-util-to-html`][hast-util-to-html]:
```js
import {common, createLowlight} from 'lowlight'
import {toHtml} from 'hast-util-to-html'
const lowlight = createLowlight(common)
const tree = lowlight.highlight('js', '"use strict";')
console.log(toHtml(tree))
```
Yields:
```html
<span class="hljs-meta">"use strict"</span>;
```
### Example: turning hast into preact, react, etc
hast trees as returned by lowlight can be turned into nodes of any framework
that supports JSX, such as preact, react, solid, svelte, vue, and more, with
[`hast-util-to-jsx-runtime`][hast-util-to-jsx-runtime]:
```js
import {toJsxRuntime} from 'hast-util-to-jsx-runtime'
// @ts-expect-error: react types dont type these.
import {Fragment, jsx, jsxs} from 'react/jsx-runtime'
import {common, createLowlight} from 'lowlight'
const lowlight = createLowlight(common)
const tree = lowlight.highlight('js', '"use strict";')
console.log(toJsxRuntime(tree, {Fragment, jsx, jsxs}))
```
Yields:
```js
{
$$typeof: Symbol(react.element),
type: Symbol(react.fragment),
key: null,
ref: null,
props: {children: [[Object], ';']},
_owner: null,
_store: {}
}
```
## Types
This package is fully typed with [TypeScript][].
It exports the additional types
[`AutoOptions`][api-auto-options],
[`LanguageFn`][api-language-fn], and
[`Options`][api-options].
It also registers `root.data` with `@types/hast`.
If youre working with the data fields, make sure to import this package
somewhere in your types, as that registers the new fields on the file.
```js
/**
* @import {Root} from 'hast'
* @import {} from 'lowlight'
*/
import {VFile} from 'vfile'
/** @type {Root} */
const root = {type: 'root', children: []}
console.log(root.data?.language) //=> TS now knows that this is a `string?`.
```
<!--Old name of the following section:-->
<a name="syntaxes"></a>
## Data
If youre using `createLowlight()`, no syntaxes are included yet.
You can import `all` or `common` and pass them, such as with
`createLowlight(all)`.
Checked syntaxes are included in `common`.
All syntaxes are included in `all`.
You can also manually import syntaxes from `highlight.js/lib/languages/xxx`,
where `xxx` is the name, such as `'highlight.js/lib/languages/wasm'`.
<!--support start-->
* [ ] `1c` — 1C:Enterprise
* [ ] `abnf` — Augmented Backus-Naur Form
* [ ] `accesslog` — Apache Access Log
* [ ] `actionscript` (`as`) — ActionScript
* [ ] `ada` — Ada
* [ ] `angelscript` (`asc`) — AngelScript
* [ ] `apache` (`apacheconf`) — Apache config
* [ ] `applescript` (`osascript`) — AppleScript
* [ ] `arcade` — ArcGIS Arcade
* [x] `arduino` (`ino`) — Arduino
* [ ] `armasm` (`arm`) — ARM Assembly
* [ ] `asciidoc` (`adoc`) — AsciiDoc
* [ ] `aspectj` — AspectJ
* [ ] `autohotkey` (`ahk`) — AutoHotkey
* [ ] `autoit` — AutoIt
* [ ] `avrasm` — AVR Assembly
* [ ] `awk` — Awk
* [ ] `axapta` (`x++`) — X++
* [x] `bash` (`sh`, `zsh`) — Bash
* [ ] `basic` — BASIC
* [ ] `bnf` — BackusNaur Form
* [ ] `brainfuck` (`bf`) — Brainfuck
* [x] `c` (`h`) — C
* [ ] `cal` — C/AL
* [ ] `capnproto` (`capnp`) — Capn Proto
* [ ] `ceylon` — Ceylon
* [ ] `clean` (`icl`, `dcl`) — Clean
* [ ] `clojure` (`clj`, `edn`) — Clojure
* [ ] `clojure-repl` — Clojure REPL
* [ ] `cmake` (`cmake.in`) — CMake
* [ ] `coffeescript` (`coffee`, `cson`, `iced`) — CoffeeScript
* [ ] `coq` — Coq
* [ ] `cos` (`cls`) — Caché Object Script
* [x] `cpp` (`cc`, `c++`, `h++`, `hpp`, `hh`, `hxx`, `cxx`) — C++
* [ ] `crmsh` (`crm`, `pcmk`) — crmsh
* [ ] `crystal` (`cr`) — Crystal
* [x] `csharp` (`cs`, `c#`) — C#
* [ ] `csp` — CSP
* [x] `css` — CSS
* [ ] `d` — D
* [ ] `dart` — Dart
* [ ] `delphi` (`dpr`, `dfm`, `pas`, `pascal`) — Delphi
* [x] `diff` (`patch`) — Diff
* [ ] `django` (`jinja`) — Django
* [ ] `dns` (`bind`, `zone`) — DNS Zone
* [ ] `dockerfile` (`docker`) — Dockerfile
* [ ] `dos` (`bat`, `cmd`) — Batch file (DOS)
* [ ] `dsconfig` — undefined
* [ ] `dts` — Device Tree
* [ ] `dust` (`dst`) — Dust
* [ ] `ebnf` — Extended Backus-Naur Form
* [ ] `elixir` (`ex`, `exs`) — Elixir
* [ ] `elm` — Elm
* [ ] `erb` — ERB
* [ ] `erlang` (`erl`) — Erlang
* [ ] `erlang-repl` — Erlang REPL
* [ ] `excel` (`xlsx`, `xls`) — Excel formulae
* [ ] `fix` — FIX
* [ ] `flix` — Flix
* [ ] `fortran` (`f90`, `f95`) — Fortran
* [ ] `fsharp` (`fs`, `f#`) — F#
* [ ] `gams` (`gms`) — GAMS
* [ ] `gauss` (`gss`) — GAUSS
* [ ] `gcode` (`nc`) — G-code (ISO 6983)
* [ ] `gherkin` (`feature`) — Gherkin
* [ ] `glsl` — GLSL
* [ ] `gml` — GML
* [x] `go` (`golang`) — Go
* [ ] `golo` — Golo
* [ ] `gradle` — Gradle
* [x] `graphql` (`gql`) — GraphQL
* [ ] `groovy` — Groovy
* [ ] `haml` — HAML
* [ ] `handlebars` (`hbs`, `html.hbs`, `html.handlebars`, `htmlbars`) — Handlebars
* [ ] `haskell` (`hs`) — Haskell
* [ ] `haxe` (`hx`) — Haxe
* [ ] `hsp` — HSP
* [ ] `http` (`https`) — HTTP
* [ ] `hy` (`hylang`) — Hy
* [ ] `inform7` (`i7`) — Inform 7
* [x] `ini` (`toml`) — TOML, also INI
* [ ] `irpf90` — IRPF90
* [ ] `isbl` — ISBL
* [x] `java` (`jsp`) — Java
* [x] `javascript` (`js`, `jsx`, `mjs`, `cjs`) — JavaScript
* [ ] `jboss-cli` (`wildfly-cli`) — JBoss CLI
* [x] `json` (`jsonc`) — JSON
* [ ] `julia` — Julia
* [ ] `julia-repl` (`jldoctest`) — Julia REPL
* [x] `kotlin` (`kt`, `kts`) — Kotlin
* [ ] `lasso` (`ls`, `lassoscript`) — Lasso
* [ ] `latex` (`tex`) — LaTeX
* [ ] `ldif` — LDIF
* [ ] `leaf` — Leaf
* [x] `less` — Less
* [ ] `lisp` — Lisp
* [ ] `livecodeserver` — LiveCode
* [ ] `livescript` (`ls`) — LiveScript
* [ ] `llvm` — LLVM IR
* [ ] `lsl` — LSL (Linden Scripting Language)
* [x] `lua` (`pluto`) — Lua
* [x] `makefile` (`mk`, `mak`, `make`) — Makefile
* [x] `markdown` (`md`, `mkdown`, `mkd`) — Markdown
* [ ] `mathematica` (`mma`, `wl`) — Mathematica
* [ ] `matlab` — Matlab
* [ ] `maxima` — Maxima
* [ ] `mel` — MEL
* [ ] `mercury` (`m`, `moo`) — Mercury
* [ ] `mipsasm` (`mips`) — MIPS Assembly
* [ ] `mizar` — Mizar
* [ ] `mojolicious` — Mojolicious
* [ ] `monkey` — Monkey
* [ ] `moonscript` (`moon`) — MoonScript
* [ ] `n1ql` — N1QL
* [ ] `nestedtext` (`nt`) — Nested Text
* [ ] `nginx` (`nginxconf`) — Nginx config
* [ ] `nim` — Nim
* [ ] `nix` (`nixos`) — Nix
* [ ] `node-repl` — Node REPL
* [ ] `nsis` — NSIS
* [x] `objectivec` (`mm`, `objc`, `obj-c`, `obj-c++`, `objective-c++`) — Objective-C
* [ ] `ocaml` (`ml`) — OCaml
* [ ] `openscad` (`scad`) — OpenSCAD
* [ ] `oxygene` — Oxygene
* [ ] `parser3` — Parser3
* [x] `perl` (`pl`, `pm`) — Perl
* [ ] `pf` (`pf.conf`) — Packet Filter config
* [ ] `pgsql` (`postgres`, `postgresql`) — PostgreSQL
* [x] `php` — undefined
* [x] `php-template` — PHP template
* [x] `plaintext` (`text`, `txt`) — Plain text
* [ ] `pony` — Pony
* [ ] `powershell` (`pwsh`, `ps`, `ps1`) — PowerShell
* [ ] `processing` (`pde`) — Processing
* [ ] `profile` — Python profiler
* [ ] `prolog` — Prolog
* [ ] `properties` — .properties
* [ ] `protobuf` (`proto`) — Protocol Buffers
* [ ] `puppet` (`pp`) — Puppet
* [ ] `purebasic` (`pb`, `pbi`) — PureBASIC
* [x] `python` (`py`, `gyp`, `ipython`) — Python
* [x] `python-repl` (`pycon`) — undefined
* [ ] `q` (`k`, `kdb`) — Q
* [ ] `qml` (`qt`) — QML
* [x] `r` — R
* [ ] `reasonml` (`re`) — ReasonML
* [ ] `rib` — RenderMan RIB
* [ ] `roboconf` (`graph`, `instances`) — Roboconf
* [ ] `routeros` (`mikrotik`) — MikroTik RouterOS script
* [ ] `rsl` — RenderMan RSL
* [x] `ruby` (`rb`, `gemspec`, `podspec`, `thor`, `irb`) — Ruby
* [ ] `ruleslanguage` — Oracle Rules Language
* [x] `rust` (`rs`) — Rust
* [ ] `sas` — SAS
* [ ] `scala` — Scala
* [ ] `scheme` (`scm`) — Scheme
* [ ] `scilab` (`sci`) — Scilab
* [x] `scss` — SCSS
* [x] `shell` (`console`, `shellsession`) — Shell Session
* [ ] `smali` — Smali
* [ ] `smalltalk` (`st`) — Smalltalk
* [ ] `sml` (`ml`) — SML (Standard ML)
* [ ] `sqf` — SQF
* [x] `sql` — SQL
* [ ] `stan` (`stanfuncs`) — Stan
* [ ] `stata` (`do`, `ado`) — Stata
* [ ] `step21` (`p21`, `step`, `stp`) — STEP Part 21
* [ ] `stylus` (`styl`) — Stylus
* [ ] `subunit` — SubUnit
* [x] `swift` — Swift
* [ ] `taggerscript` — Tagger Script
* [ ] `tap` — Test Anything Protocol
* [ ] `tcl` (`tk`) — Tcl
* [ ] `thrift` — Thrift
* [ ] `tp` — TP
* [ ] `twig` (`craftcms`) — Twig
* [x] `typescript` (`ts`, `tsx`, `mts`, `cts`) — TypeScript
* [ ] `vala` — Vala
* [x] `vbnet` (`vb`) — Visual Basic .NET
* [ ] `vbscript` (`vbs`) — VBScript
* [ ] `vbscript-html` — VBScript in HTML
* [ ] `verilog` (`v`, `sv`, `svh`) — Verilog
* [ ] `vhdl` — VHDL
* [ ] `vim` — Vim Script
* [x] `wasm` — WebAssembly
* [ ] `wren` — Wren
* [ ] `x86asm` — Intel x86 Assembly
* [ ] `xl` (`tao`) — XL
* [x] `xml` (`html`, `xhtml`, `rss`, `atom`, `xjb`, `xsd`, `xsl`, `plist`, `wsf`, `svg`) — HTML, XML
* [ ] `xquery` (`xpath`, `xq`, `xqm`) — XQuery
* [x] `yaml` (`yml`) — YAML
* [ ] `zephir` (`zep`) — Zephir
<!--support end-->
## CSS
`lowlight` does not inject CSS for the syntax highlighted code (because well,
lowlight doesnt have to be turned into HTML and might not run in a browser!).
If you are in a browser, you can use any `highlight.js` theme.
For example, to get GitHub Dark from cdnjs:
```html
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.11.0/styles/github-dark.min.css">
```
## Compatibility
This package is compatible with maintained versions of Node.js.
When we cut a new major release, we drop support for unmaintained versions of
Node.
This means we try to keep the current release line,
`lowlight@^3`, compatible with Node.js 16.
## Security
This package is safe.
## Related
* [`refractor`][refractor]
— the same as lowlight but with [Prism][]
* [`starry-night`][starry-night]
— similar but like GitHub and really good
## Projects
* [`emphasize`](https://github.com/wooorm/emphasize)
— syntax highlighting in ANSI (for the terminal)
* [`react-lowlight`](https://github.com/rexxars/react-lowlight)
— syntax highlighter for [React][]
* [`react-syntax-highlighter`](https://github.com/conorhastings/react-syntax-highlighter)
— [React][] component for syntax highlighting
* [`rehype-highlight`](https://github.com/rehypejs/rehype-highlight)
— [**rehype**](https://github.com/rehypejs/rehype) plugin to highlight code
blocks
* [`jstransformer-lowlight`](https://github.com/ai/jstransformer-lowlight)
— syntax highlighting for [JSTransformers](https://github.com/jstransformers)
and [Pug](https://pugjs.org/language/filters.html)
## Contribute
Yes please!
See [How to Contribute to Open Source][contribute].
## License
[MIT][license] © [Titus Wormer][author]
<!-- Definitions -->
[build-badge]: https://github.com/wooorm/lowlight/workflows/main/badge.svg
[build]: https://github.com/wooorm/lowlight/actions
[coverage-badge]: https://img.shields.io/codecov/c/github/wooorm/lowlight.svg
[coverage]: https://codecov.io/github/wooorm/lowlight
[downloads-badge]: https://img.shields.io/npm/dm/lowlight.svg
[downloads]: https://www.npmjs.com/package/lowlight
[size-badge]: https://img.shields.io/bundlephobia/minzip/lowlight.svg
[size]: https://bundlephobia.com/result?p=lowlight
[npm]: https://docs.npmjs.com/cli/install
[esmsh]: https://esm.sh
[license]: license
[author]: https://wooorm.com
[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
[typescript]: https://www.typescriptlang.org
[contribute]: https://opensource.guide/how-to-contribute/
[hast-root]: https://github.com/syntax-tree/hast#root
[highlight-js]: https://github.com/highlightjs/highlight.js
[names]: https://github.com/highlightjs/highlight.js/blob/main/SUPPORTED_LANGUAGES.md
[react]: https://facebook.github.io/react/
[prism]: https://github.com/PrismJS/prism
[refractor]: https://github.com/wooorm/refractor
[starry-night]: https://github.com/wooorm/starry-night
[hast-util-to-html]: https://github.com/syntax-tree/hast-util-to-html
[hast-util-to-jsx-runtime]: https://github.com/syntax-tree/hast-util-to-jsx-runtime
[api-all]: #all
[api-auto-options]: #autooptions
[api-common]: #common
[api-create-lowlight]: #createlowlightgrammars
[api-language-fn]: #languagefn
[api-options]: #options