lite-hl 0.1.0 → 0.1.1

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/README.md CHANGED
@@ -28,8 +28,9 @@ To maintain its ultra-light footprint, `lite-hl` makes specific engineering trad
28
28
 
29
29
  * **Ultra-Lightweight**: At under 10KB, it is a fraction of the size of `highlight.js`.
30
30
  * **Zero-Config Coverage**: Supports every programming language automatically. There is no need to "register" or import language definitions.
31
+ * **Deep Shell Script Support**: Robust parsing of Bash/Shell conventions, recognizing 60+ common utilities (`grep`, `awk`, `docker`, etc.) and dynamic variables (`$VAR`, `${VAR}`).
31
32
  * **High Performance**: Tokenization happens in a single regex pass. It is optimized for large-scale documentation generators and real-time previews.
32
- * **Legacy Compatibility**: natively supports a `mimicHljs` mode, allowing you to use existing `highlight.js` CSS themes (like GitHub, Atom, or Monokai) as a drop-in replacement.
33
+ * **Legacy Compatibility**: natively supports a `mimicHljs` mode, allowing you to use existing `highlight.js` CSS themes (like GitHub, Atom, or Monokai) exactly as they are without modification.
33
34
  * **Runtime Agnostic**: Works perfectly in Node.js, the browser, and Edge environments.
34
35
 
35
36
  ## Installation
package/dist/index.js CHANGED
@@ -19,7 +19,8 @@ const COMMON_KEYWORDS = [
19
19
  'void', 'null', 'undefined', 'true', 'false', 'def', 'pass', 'None', 'True', 'False',
20
20
  'match', 'with', 'as', 'struct', 'func', 'go', 'chan', 'defer', 'select', 'fallthrough',
21
21
  'namespace', 'using', 'pkg', 'mod', 'require', 'fn', 'pub', 'mut', 'impl', 'loop', 'unsafe',
22
- 'trait', 'where', 'macro_rules', 'use', 'int', 'float', 'double', 'char', 'bool'
22
+ 'trait', 'where', 'macro_rules', 'use', 'int', 'float', 'double', 'char', 'bool',
23
+ 'bash', 'sh', 'sudo', 'grep', 'sed', 'awk', 'ls', 'cd', 'cp', 'mv', 'rm', 'mkdir', 'chmod', 'chown', 'git', 'pnpm', 'npm', 'yarn', 'node', 'curl', 'wget', 'echo', 'printf', 'cat', 'grep', 'find', 'xargs', 'alias', 'export', 'set', 'unset', 'read', 'source', 'type', 'which', 'whoami', 'id', 'groups', 'ps', 'top', 'kill', 'df', 'du', 'free', 'uname', 'hostname', 'ip', 'ping', 'ssh', 'scp', 'rsync', 'tar', 'gzip', 'gunzip', 'zip', 'unzip', 'sudo', 'systemctl', 'journalctl', 'docker', 'kubectl', 'apt', 'yum', 'brew', 'cargo'
23
24
  ].join('|');
24
25
  // We use named capture groups so we can easily map matches back to their token types.
25
26
  // Order is critical: comments first, then strings, then numbers, then keywords, etc.
@@ -27,6 +28,7 @@ const UNIVERSAL_REGEX = new RegExp(`(?<comment>\\/\\/[^\\n]*|\\/\\*[\\s\\S]*?\\*
27
28
  `|(?<string>"(?:\\\\.|[^"\\\\])*"|'(?:\\\\.|[^'\\\\])*'|\`(?:\\\\.|[^\`\\\\])*\`)` +
28
29
  `|(?<number>\\b\\d+(?:\\.\\d+)?(?:[eE][+-]?\\d+)?\\b|\\b0x[a-fA-F0-9]+\\b)` +
29
30
  `|(?<keyword>\\b(?:${COMMON_KEYWORDS})\\b)` +
31
+ `|(?<variable>\\$[a-zA-Z0-9_$]+|\\$\\{[a-zA-Z0-9_$]+\\})` +
30
32
  `|(?<function>[a-zA-Z_$][a-zA-Z0-9_$]*(?=\\s*\\())` +
31
33
  `|(?<property>(?<=\\.)[a-zA-Z_$][a-zA-Z0-9_$]*)` +
32
34
  `|(?<operator>[=+\\-*\\/%&|<>!^~?:]+)`, 'g');
@@ -54,8 +56,16 @@ export function highlight(code, options = {}) {
54
56
  // Process Token Class
55
57
  let className = tokenType;
56
58
  if (isHljs) {
59
+ // Remap token types to match highlight.js CSS class names
57
60
  if (tokenType === 'function')
58
61
  className = 'title function_';
62
+ else if (tokenType === 'property')
63
+ className = 'attr';
64
+ else if (tokenType === 'operator')
65
+ className = 'punctuation';
66
+ else if (tokenType === 'variable')
67
+ className = 'variable';
68
+ // 'comment', 'string', 'number', 'keyword' stay as-is (already match hljs names)
59
69
  className = `hljs-${className}`;
60
70
  }
61
71
  result += `<span class="${className}">${escapeHtml(text)}</span>`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lite-hl",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "A universal, zero-config, heuristic code tokenizer and highlighter.",
5
5
  "type": "module",
6
6
  "files": [