@celestia-island/hikari 0.55.381 → 0.55.383

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@celestia-island/hikari",
3
- "version": "0.55.381",
3
+ "version": "0.55.383",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Hikari UI library, Vue 3 runtime — one design system for Vue 3 and Rust/WASM applications",
@@ -0,0 +1,48 @@
1
+ import { describe, expect, it } from "vitest";
2
+
3
+ import { languageForPath } from "./useHighlight";
4
+
5
+ /**
6
+ * The wasm-highlight rewrite (#1313) replaced languageForPath with a
7
+ * bare extension lookup and dropped PATH_FILENAME_LANG + EXT_TABLE —
8
+ * extensionless files triaged as a bogus basename language ("readme"),
9
+ * dotfiles/build files lost their mapping (chest FileBrowser preview
10
+ * caught it downstream, 0.55.381 pickup). These pins hold the restored
11
+ * surface: bare-name build files, dialect stems, dotfiles, and the
12
+ * extensionless → "" (plaintext) contract.
13
+ */
14
+ describe("languageForPath", () => {
15
+ it("extensionless files are plaintext (no language)", () => {
16
+ expect(languageForPath("README")).toBe("");
17
+ expect(languageForPath("LICENSE")).toBe("");
18
+ expect(languageForPath("dir/notes")).toBe("");
19
+ });
20
+
21
+ it("whole-filename build scripts keep their dialect", () => {
22
+ expect(languageForPath("Dockerfile")).toBe("dockerfile");
23
+ expect(languageForPath("dockerfile.prod")).toBe("dockerfile");
24
+ expect(languageForPath("Makefile")).toBe("makefile");
25
+ expect(languageForPath("Jenkinsfile")).toBe("groovy");
26
+ expect(languageForPath("CMakeLists.txt")).toBe("cmake");
27
+ });
28
+
29
+ it("dotfiles map to ini/bash", () => {
30
+ expect(languageForPath(".env")).toBe("ini");
31
+ expect(languageForPath(".gitignore")).toBe("ini");
32
+ expect(languageForPath(".bashrc")).toBe("bash");
33
+ });
34
+
35
+ it("extension mapping stays canonical", () => {
36
+ expect(languageForPath("main.rs")).toBe("rust");
37
+ expect(languageForPath("app.tsx")).toBe("typescript");
38
+ expect(languageForPath("notes.txt")).toBe("plaintext");
39
+ expect(languageForPath("run.log")).toBe("plaintext");
40
+ expect(languageForPath("spec/api.yaml")).toBe("yaml");
41
+ expect(languageForPath("page.vue")).toBe("xml");
42
+ });
43
+
44
+ it("the basename is lowercased before any lookup", () => {
45
+ expect(languageForPath("DOCKERFILE")).toBe("dockerfile");
46
+ expect(languageForPath("README.MD")).toBe("markdown");
47
+ });
48
+ });
@@ -81,12 +81,126 @@ export function highlight(code: string, lang?: string): string {
81
81
  return escapeHtml(code);
82
82
  }
83
83
 
84
- /** Path-based language detection (file extension → language id). */
84
+ /** Whole filenames (lowercased) that carry no useful extension, or whose
85
+ * dialect is decided by the name: `Dockerfile.dev`, `CMakeLists.txt`. */
86
+ const PATH_FILENAME_LANG: Record<string, string> = {
87
+ dockerfile: "dockerfile",
88
+ makefile: "makefile",
89
+ gnumakefile: "makefile",
90
+ "cmakelists.txt": "cmake",
91
+ jenkinsfile: "groovy",
92
+ nginx: "nginx",
93
+ "cargo.lock": "toml",
94
+ ".env": "ini",
95
+ ".gitignore": "ini",
96
+ ".gitattributes": "ini",
97
+ ".gitmodules": "ini",
98
+ ".editorconfig": "ini",
99
+ ".bashrc": "bash",
100
+ ".zshrc": "bash",
101
+ ".profile": "bash",
102
+ };
103
+
104
+ /** Extension (lowercased) → canonical highlight.js language id. Only ids
105
+ * that exist in LANGUAGE_LOADERS: anything else would render plaintext
106
+ * anyway, just with a misleading promise attached. */
107
+ const EXT_TABLE: Record<string, string> = {
108
+ rs: "rust",
109
+ ts: "typescript", tsx: "typescript", mts: "typescript", cts: "typescript",
110
+ js: "javascript", jsx: "javascript", mjs: "javascript", cjs: "javascript",
111
+ json: "json", jsonc: "json",
112
+ py: "python", pyi: "python", pyw: "python",
113
+ rb: "ruby",
114
+ go: "go",
115
+ java: "java",
116
+ kt: "kotlin", kts: "kotlin",
117
+ scala: "scala", sc: "scala",
118
+ groovy: "groovy", gradle: "groovy",
119
+ c: "c", h: "c",
120
+ cpp: "cpp", cc: "cpp", cxx: "cpp", hpp: "cpp", hh: "cpp", hxx: "cpp",
121
+ cs: "csharp",
122
+ fs: "fsharp", fsx: "fsharp",
123
+ php: "php",
124
+ swift: "swift",
125
+ m: "objectivec", mm: "objectivec",
126
+ dart: "dart",
127
+ ex: "elixir", exs: "elixir",
128
+ erl: "erlang", hrl: "erlang",
129
+ hs: "haskell", lhs: "haskell",
130
+ elm: "elm",
131
+ lua: "lua",
132
+ pl: "perl", pm: "perl",
133
+ r: "r",
134
+ jl: "julia",
135
+ nim: "nim",
136
+ cr: "crystal",
137
+ ml: "ocaml", mli: "ocaml", mll: "ocaml", mly: "ocaml",
138
+ vb: "vbnet",
139
+ pas: "delphi", dpr: "delphi",
140
+ bas: "basic",
141
+ f: "fortran", f90: "fortran", f95: "fortran", f03: "fortran", for: "fortran",
142
+ coffee: "coffeescript",
143
+ ls: "livescript",
144
+ clj: "clojure", cljs: "clojure", cljc: "clojure", edn: "clojure",
145
+ scm: "scheme", ss: "scheme", el: "lisp", lisp: "lisp",
146
+ xml: "xml", html: "xml", htm: "xml", svg: "xml", vue: "xml", xhtml: "xml",
147
+ cshtml: "xml", jsp: "xml", erb: "erb", ejs: "xml",
148
+ hbs: "handlebars", handlebars: "handlebars",
149
+ twig: "twig",
150
+ haml: "haml",
151
+ dust: "dust",
152
+ css: "css", scss: "scss", less: "less",
153
+ yml: "yaml", yaml: "yaml",
154
+ toml: "toml",
155
+ ini: "ini", cfg: "ini", conf: "ini", properties: "properties", env: "ini",
156
+ md: "markdown", markdown: "markdown",
157
+ graphql: "graphql", gql: "graphql",
158
+ http: "http",
159
+ sh: "bash", bash: "bash", zsh: "bash", shell: "bash", fish: "bash",
160
+ ps1: "powershell", psm1: "powershell",
161
+ bat: "dos", cmd: "dos",
162
+ mk: "makefile",
163
+ cmake: "cmake",
164
+ dockerfile: "dockerfile",
165
+ nginx: "nginx",
166
+ awk: "awk",
167
+ tcl: "tcl",
168
+ vim: "vim",
169
+ sql: "sql", psql: "pgsql",
170
+ proto: "protobuf",
171
+ thrift: "thrift",
172
+ glsl: "glsl", vert: "glsl", frag: "glsl", geom: "glsl",
173
+ wasm: "wasm",
174
+ asm: "x86asm",
175
+ v: "verilog", sv: "verilog",
176
+ vhd: "vhdl", vhdl: "vhdl",
177
+ tex: "latex", sty: "latex",
178
+ diff: "diff", patch: "diff",
179
+ txt: "plaintext", text: "plaintext", log: "plaintext",
180
+ };
181
+
182
+ /**
183
+ * A file path → the canonical highlight.js language id for it, or "" when
184
+ * nothing sensible is known (callers pass "" as "no language" and the
185
+ * block renders plaintext or auto-detects). One mapping for every code
186
+ * surface — diff panes, file browsers, markdown fences — so the same
187
+ * path always highlights the same way; aliases are resolved by
188
+ * `normalize()` at highlight time, so the table lists canonical ids.
189
+ */
85
190
  export function languageForPath(path: string): string {
86
- const ext = path.split(".").pop()?.toLowerCase() ?? "";
87
- return ALIASES[ext] ?? ext;
191
+ const name = path.split("/").pop()?.trim().toLowerCase() ?? "";
192
+ if (!name) return "";
193
+ // Extensionless build scripts: `Dockerfile`, `Jenkinsfile`, `Makefile`.
194
+ const bare = PATH_FILENAME_LANG[name];
195
+ if (bare) return bare;
196
+ // `Dockerfile.dev` / `dockerfile.prod` — the dialect IS the stem.
197
+ if (name.startsWith("dockerfile")) return "dockerfile";
198
+ if (name.startsWith("makefile")) return "makefile";
199
+ const ext = name.includes(".") ? name.split(".").pop()! : "";
200
+ return EXT_TABLE[ext] ?? "";
88
201
  }
89
202
 
203
+
90
204
  export function useHighlight() {
91
205
  return { highlight, version };
92
206
  }