lite-hl 0.0.1 → 0.1.0

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/package.json CHANGED
@@ -1,8 +1,11 @@
1
1
  {
2
2
  "name": "lite-hl",
3
- "version": "0.0.1",
3
+ "version": "0.1.0",
4
4
  "description": "A universal, zero-config, heuristic code tokenizer and highlighter.",
5
5
  "type": "module",
6
+ "files": [
7
+ "dist"
8
+ ],
6
9
  "main": "dist/index.js",
7
10
  "types": "dist/index.d.ts",
8
11
  "scripts": {
@@ -32,11 +35,11 @@
32
35
  },
33
36
  "repository": {
34
37
  "type": "git",
35
- "url": "git+https://github.com/docmd-io/docmd.git",
38
+ "url": "git+https://github.com/docmd-io/lite-hl.git",
36
39
  "directory": "lite-hl"
37
40
  },
38
41
  "bugs": {
39
- "url": "https://github.com/docmd-io/docmd/issues"
42
+ "url": "https://github.com/docmd-io/lite-hl/issues"
40
43
  },
41
44
  "homepage": "https://docmd.io",
42
45
  "funding": "https://github.com/sponsors/mgks",
package/.gitattributes DELETED
@@ -1,2 +0,0 @@
1
- # Auto detect text files and perform LF normalization
2
- * text=auto
@@ -1,32 +0,0 @@
1
- name: Publish to NPM
2
- on:
3
- release:
4
- types: [published]
5
- workflow_dispatch:
6
-
7
- permissions:
8
- contents: read
9
- id-token: write
10
-
11
- jobs:
12
- publish:
13
- runs-on: ubuntu-latest
14
- steps:
15
- - uses: actions/checkout@v6
16
-
17
- - name: Setup Node.js
18
- uses: actions/setup-node@v6
19
- with:
20
- node-version: '22'
21
- registry-url: 'https://registry.npmjs.org'
22
-
23
- - name: Install dependencies
24
- run: npm install
25
-
26
- - name: Build package
27
- run: npm run build
28
-
29
- - name: Publish to npm
30
- run: npm publish --access public
31
- env:
32
- NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
package/src/index.ts DELETED
@@ -1,101 +0,0 @@
1
- /**
2
- * lite-hl: Universal Heuristic Syntax Highlighter
3
- * Tokenizes generic programming code without relying on language-specific grammars.
4
- */
5
-
6
- // Escape HTML securely
7
- function escapeHtml(str: string): string {
8
- return str
9
- .replace(/&/g, '&')
10
- .replace(/</g, '&lt;')
11
- .replace(/>/g, '&gt;')
12
- .replace(/"/g, '&quot;')
13
- .replace(/'/g, '&#039;');
14
- }
15
-
16
- const COMMON_KEYWORDS = [
17
- 'return', 'if', 'else', 'while', 'for', 'do', 'break', 'continue', 'switch', 'case', 'default',
18
- 'try', 'catch', 'finally', 'throw', 'class', 'function', 'var', 'let', 'const', 'import', 'export', 'from',
19
- 'public', 'private', 'protected', 'static', 'extends', 'implements', 'new', 'this', 'super',
20
- 'typeof', 'instanceof', 'in', 'of', 'yield', 'await', 'async', 'interface', 'type', 'enum',
21
- 'void', 'null', 'undefined', 'true', 'false', 'def', 'pass', 'None', 'True', 'False',
22
- 'match', 'with', 'as', 'struct', 'func', 'go', 'chan', 'defer', 'select', 'fallthrough',
23
- 'namespace', 'using', 'pkg', 'mod', 'require', 'fn', 'pub', 'mut', 'impl', 'loop', 'unsafe',
24
- 'trait', 'where', 'macro_rules', 'use', 'int', 'float', 'double', 'char', 'bool'
25
- ].join('|');
26
-
27
- // We use named capture groups so we can easily map matches back to their token types.
28
- // Order is critical: comments first, then strings, then numbers, then keywords, etc.
29
- const UNIVERSAL_REGEX = new RegExp(
30
- `(?<comment>\\/\\/[^\\n]*|\\/\\*[\\s\\S]*?\\*\\/|#[^\\n]*|<!--[\\s\\S]*?-->)` +
31
- `|(?<string>"(?:\\\\.|[^"\\\\])*"|'(?:\\\\.|[^'\\\\])*'|\`(?:\\\\.|[^\`\\\\])*\`)` +
32
- `|(?<number>\\b\\d+(?:\\.\\d+)?(?:[eE][+-]?\\d+)?\\b|\\b0x[a-fA-F0-9]+\\b)` +
33
- `|(?<keyword>\\b(?:${COMMON_KEYWORDS})\\b)` +
34
- `|(?<function>[a-zA-Z_$][a-zA-Z0-9_$]*(?=\\s*\\())` +
35
- `|(?<property>(?<=\\.)[a-zA-Z_$][a-zA-Z0-9_$]*)` +
36
- `|(?<operator>[=+\\-*\\/%&|<>!^~?:]+)`,
37
- 'g'
38
- );
39
-
40
- export interface HighlightOptions {
41
- /**
42
- * Used strictly for class attribution, does not change the heuristic tokenization.
43
- */
44
- language?: string;
45
- /**
46
- * Mimic `highlight.js` class names to maintain compatibility with existing themes.
47
- */
48
- mimicHljs?: boolean;
49
- }
50
-
51
- export function highlight(code: string, options: HighlightOptions = {}): { value: string; language: string } {
52
- const isHljs = options.mimicHljs !== false;
53
- let result = '';
54
- let lastIndex = 0;
55
-
56
- for (const match of code.matchAll(UNIVERSAL_REGEX)) {
57
- const start = match.index!;
58
- const text = match[0];
59
- const groups = match.groups!;
60
-
61
- // Append un-matched text (escaped)
62
- if (start > lastIndex) {
63
- result += escapeHtml(code.slice(lastIndex, start));
64
- }
65
- lastIndex = start + text.length;
66
-
67
- // Identify token
68
- let tokenType = '';
69
- for (const key in groups) {
70
- if (groups[key] !== undefined) {
71
- tokenType = key;
72
- break;
73
- }
74
- }
75
-
76
- // Process Token Class
77
- let className = tokenType;
78
- if (isHljs) {
79
- if (tokenType === 'function') className = 'title function_';
80
- className = `hljs-${className}`;
81
- }
82
-
83
- result += `<span class="${className}">${escapeHtml(text)}</span>`;
84
- }
85
-
86
- // Append remaining text
87
- if (lastIndex < code.length) {
88
- result += escapeHtml(code.slice(lastIndex));
89
- }
90
-
91
- return {
92
- value: result,
93
- language: options.language || 'plaintext'
94
- };
95
- }
96
-
97
- // Ensure similar API signature to highlight.js
98
- export default {
99
- highlight,
100
- getLanguage: () => true // Assume support for all languages requested!
101
- };
package/tsconfig.json DELETED
@@ -1,14 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2022",
4
- "module": "Node16",
5
- "moduleResolution": "node16",
6
- "strict": true,
7
- "declaration": true,
8
- "outDir": "dist",
9
- "esModuleInterop": true,
10
- "forceConsistentCasingInFileNames": true,
11
- "skipLibCheck": true
12
- },
13
- "include": ["src/**/*"]
14
- }