@git-diff-view/lowlight
Advanced tools
| declare global { | ||
| const __DEV__: boolean; | ||
| const __VERSION__: string; | ||
| namespace NodeJS { | ||
| interface ProcessEnv { | ||
| NODE_ENV: "development" | "production" | "test"; | ||
| } | ||
| } | ||
| } | ||
| export {}; |
+156
| import { createLowlight, all } from "lowlight"; | ||
| import { processAST, type SyntaxLine } from "./processAST"; | ||
| import type { _getAST } from "./lang"; | ||
| const lowlight = createLowlight(all); | ||
| // !SEE https://github.com/highlightjs/highlightjs-vue | ||
| lowlight.register("vue", function hljsDefineVue(hljs) { | ||
| return { | ||
| subLanguage: "xml", | ||
| contains: [ | ||
| hljs.COMMENT("<!--", "-->", { | ||
| relevance: 10, | ||
| }), | ||
| { | ||
| begin: /^(\s*)(<script>)/gm, | ||
| end: /^(\s*)(<\/script>)/gm, | ||
| subLanguage: "javascript", | ||
| excludeBegin: true, | ||
| excludeEnd: true, | ||
| }, | ||
| { | ||
| begin: /^(?:\s*)(?:<script\s+lang=(["'])ts\1>)/gm, | ||
| end: /^(\s*)(<\/script>)/gm, | ||
| subLanguage: "typescript", | ||
| excludeBegin: true, | ||
| excludeEnd: true, | ||
| }, | ||
| { | ||
| begin: /^(\s*)(<style(\s+scoped)?>)/gm, | ||
| end: /^(\s*)(<\/style>)/gm, | ||
| subLanguage: "css", | ||
| excludeBegin: true, | ||
| excludeEnd: true, | ||
| }, | ||
| { | ||
| begin: /^(?:\s*)(?:<style(?:\s+scoped)?\s+lang=(["'])(?:s[ca]ss)\1(?:\s+scoped)?>)/gm, | ||
| end: /^(\s*)(<\/style>)/gm, | ||
| subLanguage: "scss", | ||
| excludeBegin: true, | ||
| excludeEnd: true, | ||
| }, | ||
| { | ||
| begin: /^(?:\s*)(?:<style(?:\s+scoped)?\s+lang=(["'])stylus\1(?:\s+scoped)?>)/gm, | ||
| end: /^(\s*)(<\/style>)/gm, | ||
| subLanguage: "stylus", | ||
| excludeBegin: true, | ||
| excludeEnd: true, | ||
| }, | ||
| ], | ||
| }; | ||
| }); | ||
| export type DiffAST = ReturnType<typeof lowlight.highlight>; | ||
| export type DiffHighlighter = { | ||
| name: string; | ||
| type: "class" | "style" | string; | ||
| maxLineToIgnoreSyntax: number; | ||
| setMaxLineToIgnoreSyntax: (v: number) => void; | ||
| ignoreSyntaxHighlightList: (string | RegExp)[]; | ||
| setIgnoreSyntaxHighlightList: (v: (string | RegExp)[]) => void; | ||
| getAST: typeof _getAST; | ||
| processAST: (ast: DiffAST) => { syntaxFileObject: Record<number, SyntaxLine>; syntaxFileLineNumber: number }; | ||
| hasRegisteredCurrentLang: (lang: string) => boolean; | ||
| getHighlighterEngine: () => typeof lowlight; | ||
| }; | ||
| const instance = { name: "lowlight" }; | ||
| let _maxLineToIgnoreSyntax = 2000; | ||
| const _ignoreSyntaxHighlightList: (string | RegExp)[] = []; | ||
| Object.defineProperty(instance, "maxLineToIgnoreSyntax", { | ||
| get: () => _maxLineToIgnoreSyntax, | ||
| }); | ||
| Object.defineProperty(instance, "setMaxLineToIgnoreSyntax", { | ||
| value: (v: number) => { | ||
| _maxLineToIgnoreSyntax = v; | ||
| }, | ||
| }); | ||
| Object.defineProperty(instance, "ignoreSyntaxHighlightList", { | ||
| get: () => _ignoreSyntaxHighlightList, | ||
| }); | ||
| Object.defineProperty(instance, "setIgnoreSyntaxHighlightList", { | ||
| value: (v: (string | RegExp)[]) => { | ||
| _ignoreSyntaxHighlightList.length = 0; | ||
| _ignoreSyntaxHighlightList.push(...v); | ||
| }, | ||
| }); | ||
| Object.defineProperty(instance, "getAST", { | ||
| value: (raw: string, fileName?: string, lang?: string) => { | ||
| let hasRegisteredLang = true; | ||
| if (!lowlight.registered(lang)) { | ||
| if (__DEV__) { | ||
| console.warn(`not support current lang: ${lang} yet`); | ||
| } | ||
| hasRegisteredLang = false; | ||
| } | ||
| if ( | ||
| fileName && | ||
| highlighter.ignoreSyntaxHighlightList.some((item) => | ||
| item instanceof RegExp ? item.test(fileName) : fileName === item | ||
| ) | ||
| ) { | ||
| if (__DEV__) { | ||
| console.warn( | ||
| `ignore syntax for current file, because the fileName is in the ignoreSyntaxHighlightList: ${fileName}` | ||
| ); | ||
| } | ||
| return; | ||
| } | ||
| if (hasRegisteredLang) { | ||
| return lowlight.highlight(lang, raw); | ||
| } else { | ||
| return lowlight.highlightAuto(raw); | ||
| } | ||
| }, | ||
| }); | ||
| Object.defineProperty(instance, "processAST", { | ||
| value: (ast: DiffAST) => { | ||
| return processAST(ast); | ||
| }, | ||
| }); | ||
| Object.defineProperty(instance, "hasRegisteredCurrentLang", { | ||
| value: (lang: string) => { | ||
| return lowlight.registered(lang); | ||
| }, | ||
| }); | ||
| Object.defineProperty(instance, "getHighlighterEngine", { | ||
| value: () => lowlight, | ||
| }); | ||
| Object.defineProperty(instance, "type", { value: "class" }); | ||
| export { processAST } from "./processAST"; | ||
| export const versions = __VERSION__; | ||
| export const highlighter: DiffHighlighter = instance as DiffHighlighter; | ||
| export * from "./lang"; |
+212
| import type { DiffAST } from "."; | ||
| export type DiffHighlighterLang = | ||
| | "arduino" | ||
| | "bash" | ||
| | "c" | ||
| | "cpp" | ||
| | "csharp" | ||
| | "css" | ||
| | "diff" | ||
| | "go" | ||
| | "graphql" | ||
| | "ini" | ||
| | "java" | ||
| | "javascript" | ||
| | "js" | ||
| | "jsx" | ||
| | "json" | ||
| | "kotlin" | ||
| | "less" | ||
| | "lua" | ||
| | "makefile" | ||
| | "markdown" | ||
| | "objectivec" | ||
| | "perl" | ||
| | "php" | ||
| | "php-template" | ||
| | "plaintext" | ||
| | "python" | ||
| | "python-repl" | ||
| | "r" | ||
| | "ruby" | ||
| | "rust" | ||
| | "scss" | ||
| | "shell" | ||
| | "sql" | ||
| | "swift" | ||
| | "typescript" | ||
| | "ts" | ||
| | "tsx" | ||
| | "vbnet" | ||
| | "wasm" | ||
| | "xml" | ||
| | "yaml" | ||
| | "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" | ||
| | "cmake" | ||
| | "coffeescript" | ||
| | "coq" | ||
| | "cos" | ||
| | "crmsh" | ||
| | "crystal" | ||
| | "csp" | ||
| | "d" | ||
| | "dart" | ||
| | "delphi" | ||
| | "django" | ||
| | "dns" | ||
| | "dockerfile" | ||
| | "dos" | ||
| | "dsconfig" | ||
| | "dts" | ||
| | "dust" | ||
| | "ebnf" | ||
| | "elixir" | ||
| | "elm" | ||
| | "erb" | ||
| | "erlang" | ||
| | "erlang-repl" | ||
| | "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" | ||
| | "julia" | ||
| | "julia-repl" | ||
| | "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" | ||
| | "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" | ||
| | "verilog" | ||
| | "vhdl" | ||
| | "vim" | ||
| | "wren" | ||
| | "x86asm" | ||
| | "xl" | ||
| | "xquery" | ||
| | "zephi" | ||
| | "vue" | ||
| | "vue-html"; | ||
| // type helper function | ||
| export function _getAST(raw: string, fileName?: string, lang?: DiffHighlighterLang, theme?: "light" | "dark"): DiffAST; | ||
| export function _getAST(raw: string, fileName?: string, lang?: string, theme?: "light" | "dark"): DiffAST; | ||
| export function _getAST( | ||
| _raw: string, | ||
| _fileName?: string, | ||
| _lang?: DiffHighlighterLang | string, | ||
| _theme?: "light" | "dark" | ||
| ) { | ||
| return {} as DiffAST; | ||
| } |
| import type { DiffAST } from "."; | ||
| export type SyntaxNode = { | ||
| type: string; | ||
| value: string; | ||
| lineNumber: number; | ||
| startIndex: number; | ||
| endIndex: number; | ||
| properties?: { className?: string[]; [key: string]: any }; | ||
| children?: SyntaxNode[]; | ||
| }; | ||
| export type SyntaxLine = { | ||
| value: string; | ||
| lineNumber: number; | ||
| valueLength: number; | ||
| nodeList: { node: SyntaxNode; wrapper?: SyntaxNode }[]; | ||
| }; | ||
| export const processAST = (ast: DiffAST) => { | ||
| let lineNumber = 1; | ||
| const syntaxObj: Record<number, SyntaxLine> = {}; | ||
| const loopAST = (nodes: SyntaxNode[], wrapper?: SyntaxNode) => { | ||
| nodes.forEach((node) => { | ||
| if (node.type === "text") { | ||
| if (node.value.indexOf("\n") === -1) { | ||
| const valueLength = node.value.length; | ||
| if (!syntaxObj[lineNumber]) { | ||
| node.startIndex = 0; | ||
| node.endIndex = valueLength - 1; | ||
| const item = { | ||
| value: node.value, | ||
| lineNumber, | ||
| valueLength, | ||
| nodeList: [{ node, wrapper }], | ||
| }; | ||
| syntaxObj[lineNumber] = item; | ||
| } else { | ||
| node.startIndex = syntaxObj[lineNumber].valueLength; | ||
| node.endIndex = node.startIndex + valueLength - 1; | ||
| syntaxObj[lineNumber].value += node.value; | ||
| syntaxObj[lineNumber].valueLength += valueLength; | ||
| syntaxObj[lineNumber].nodeList.push({ node, wrapper }); | ||
| } | ||
| node.lineNumber = lineNumber; | ||
| return; | ||
| } | ||
| const lines = node.value.split("\n"); | ||
| node.children = node.children || []; | ||
| for (let i = 0; i < lines.length; i++) { | ||
| const _value = i === lines.length - 1 ? lines[i] : lines[i] + "\n"; | ||
| const _lineNumber = i === 0 ? lineNumber : ++lineNumber; | ||
| const _valueLength = _value.length; | ||
| const _node: SyntaxNode = { | ||
| type: "text", | ||
| value: _value, | ||
| startIndex: Infinity, | ||
| endIndex: Infinity, | ||
| lineNumber: _lineNumber, | ||
| }; | ||
| if (!syntaxObj[_lineNumber]) { | ||
| _node.startIndex = 0; | ||
| _node.endIndex = _valueLength - 1; | ||
| const item = { | ||
| value: _value, | ||
| lineNumber: _lineNumber, | ||
| valueLength: _valueLength, | ||
| nodeList: [{ node: _node, wrapper }], | ||
| }; | ||
| syntaxObj[_lineNumber] = item; | ||
| } else { | ||
| _node.startIndex = syntaxObj[_lineNumber].valueLength; | ||
| _node.endIndex = _node.startIndex + _valueLength - 1; | ||
| syntaxObj[_lineNumber].value += _value; | ||
| syntaxObj[_lineNumber].valueLength += _valueLength; | ||
| syntaxObj[_lineNumber].nodeList.push({ node: _node, wrapper }); | ||
| } | ||
| node.children.push(_node); | ||
| } | ||
| node.lineNumber = lineNumber; | ||
| return; | ||
| } | ||
| if (node.children) { | ||
| loopAST(node.children, node); | ||
| node.lineNumber = lineNumber; | ||
| } | ||
| }); | ||
| }; | ||
| loopAST(ast.children as SyntaxNode[]); | ||
| return { syntaxFileObject: syntaxObj, syntaxFileLineNumber: lineNumber }; | ||
| }; |
@@ -1061,3 +1061,3 @@ 'use strict'; | ||
| Object.defineProperty(instance, "type", { value: "class" }); | ||
| const versions = "0.0.26"; | ||
| const versions = "0.0.27"; | ||
| const highlighter = instance; | ||
@@ -1064,0 +1064,0 @@ |
@@ -1055,3 +1055,3 @@ 'use strict'; | ||
| Object.defineProperty(instance, "type", { value: "class" }); | ||
| const versions = "0.0.26"; | ||
| const versions = "0.0.27"; | ||
| const highlighter = instance; | ||
@@ -1058,0 +1058,0 @@ |
@@ -187,3 +187,3 @@ import { createLowlight, all } from 'lowlight'; | ||
| Object.defineProperty(instance, "type", { value: "class" }); | ||
| const versions = "0.0.26"; | ||
| const versions = "0.0.27"; | ||
| const highlighter = instance; | ||
@@ -190,0 +190,0 @@ |
+2
-1
@@ -6,6 +6,7 @@ { | ||
| "license": "MIT", | ||
| "version": "0.0.26", | ||
| "version": "0.0.27", | ||
| "main": "index.js", | ||
| "types": "index.d.ts", | ||
| "files": [ | ||
| "src", | ||
| "dist", | ||
@@ -12,0 +13,0 @@ "index.js", |
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
178484
6.22%15
36.36%2723
19.17%