@otto-code/highlight 0.6.4 → 0.6.5
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/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/language-names.d.ts +7 -0
- package/dist/language-names.js +141 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export type { HighlightStyle, HighlightToken } from "./types.js";
|
|
2
2
|
export { getParserForFile, isLanguageSupported, getSupportedExtensions } from "./parsers.js";
|
|
3
|
+
export { getLanguageDisplayName } from "./language-names.js";
|
|
3
4
|
export { highlightCode, highlightLine } from "./highlighter.js";
|
|
4
5
|
export { detectLanguage } from "./detect.js";
|
|
5
6
|
export { extractSymbols } from "./symbols.js";
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { getParserForFile, isLanguageSupported, getSupportedExtensions } from "./parsers.js";
|
|
2
|
+
export { getLanguageDisplayName } from "./language-names.js";
|
|
2
3
|
export { highlightCode, highlightLine } from "./highlighter.js";
|
|
3
4
|
export { detectLanguage } from "./detect.js";
|
|
4
5
|
export { extractSymbols } from "./symbols.js";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A label for the editor status bar — never empty. Unknown extensions fall back
|
|
3
|
+
* to the extension itself in caps ("TOML" before it was listed above), which
|
|
4
|
+
* still tells the user more than "Unknown" would.
|
|
5
|
+
*/
|
|
6
|
+
export declare function getLanguageDisplayName(filename: string): string;
|
|
7
|
+
//# sourceMappingURL=language-names.d.ts.map
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
// Human-readable language labels for UI chrome (the editor status bar).
|
|
2
|
+
//
|
|
3
|
+
// Deliberately NOT derived from `parsersByExtension`: the editor opens any text
|
|
4
|
+
// file, so this has to name plenty of formats we have no grammar for (TOML,
|
|
5
|
+
// INI, CSV…). A missing grammar means no syntax colors, not "unknown file".
|
|
6
|
+
const NAMES_BY_EXTENSION = {
|
|
7
|
+
// JavaScript/TypeScript
|
|
8
|
+
js: "JavaScript",
|
|
9
|
+
jsx: "JavaScript JSX",
|
|
10
|
+
mjs: "JavaScript",
|
|
11
|
+
cjs: "JavaScript",
|
|
12
|
+
ts: "TypeScript",
|
|
13
|
+
tsx: "TypeScript JSX",
|
|
14
|
+
mts: "TypeScript",
|
|
15
|
+
cts: "TypeScript",
|
|
16
|
+
// C family
|
|
17
|
+
c: "C",
|
|
18
|
+
h: "C Header",
|
|
19
|
+
cc: "C++",
|
|
20
|
+
cpp: "C++",
|
|
21
|
+
cxx: "C++",
|
|
22
|
+
hpp: "C++ Header",
|
|
23
|
+
hxx: "C++ Header",
|
|
24
|
+
m: "Objective-C",
|
|
25
|
+
mm: "Objective-C++",
|
|
26
|
+
cs: "C#",
|
|
27
|
+
// Web
|
|
28
|
+
html: "HTML",
|
|
29
|
+
htm: "HTML",
|
|
30
|
+
css: "CSS",
|
|
31
|
+
scss: "Sass",
|
|
32
|
+
sass: "Sass",
|
|
33
|
+
less: "Less",
|
|
34
|
+
vue: "Vue",
|
|
35
|
+
svelte: "Svelte",
|
|
36
|
+
// Data / config
|
|
37
|
+
json: "JSON",
|
|
38
|
+
jsonc: "JSON with Comments",
|
|
39
|
+
xml: "XML",
|
|
40
|
+
yaml: "YAML",
|
|
41
|
+
yml: "YAML",
|
|
42
|
+
toml: "TOML",
|
|
43
|
+
ini: "INI",
|
|
44
|
+
cfg: "INI",
|
|
45
|
+
conf: "Config",
|
|
46
|
+
env: "Environment",
|
|
47
|
+
properties: "Properties",
|
|
48
|
+
csv: "CSV",
|
|
49
|
+
tsv: "TSV",
|
|
50
|
+
// Other languages
|
|
51
|
+
java: "Java",
|
|
52
|
+
kt: "Kotlin",
|
|
53
|
+
kts: "Kotlin",
|
|
54
|
+
py: "Python",
|
|
55
|
+
pyi: "Python Stub",
|
|
56
|
+
go: "Go",
|
|
57
|
+
php: "PHP",
|
|
58
|
+
rb: "Ruby",
|
|
59
|
+
rs: "Rust",
|
|
60
|
+
swift: "Swift",
|
|
61
|
+
dart: "Dart",
|
|
62
|
+
ex: "Elixir",
|
|
63
|
+
exs: "Elixir",
|
|
64
|
+
erl: "Erlang",
|
|
65
|
+
hs: "Haskell",
|
|
66
|
+
lua: "Lua",
|
|
67
|
+
pl: "Perl",
|
|
68
|
+
r: "R",
|
|
69
|
+
scala: "Scala",
|
|
70
|
+
clj: "Clojure",
|
|
71
|
+
zig: "Zig",
|
|
72
|
+
// Shell
|
|
73
|
+
sh: "Shell",
|
|
74
|
+
bash: "Shell",
|
|
75
|
+
zsh: "Shell",
|
|
76
|
+
fish: "Shell",
|
|
77
|
+
shell: "Shell",
|
|
78
|
+
ps1: "PowerShell",
|
|
79
|
+
psm1: "PowerShell",
|
|
80
|
+
bat: "Batch",
|
|
81
|
+
cmd: "Batch",
|
|
82
|
+
// Query / markup / docs
|
|
83
|
+
sql: "SQL",
|
|
84
|
+
graphql: "GraphQL",
|
|
85
|
+
gql: "GraphQL",
|
|
86
|
+
proto: "Protocol Buffers",
|
|
87
|
+
md: "Markdown",
|
|
88
|
+
mdx: "MDX",
|
|
89
|
+
markdown: "Markdown",
|
|
90
|
+
rst: "reStructuredText",
|
|
91
|
+
adoc: "AsciiDoc",
|
|
92
|
+
asciidoc: "AsciiDoc",
|
|
93
|
+
tex: "LaTeX",
|
|
94
|
+
txt: "Plain Text",
|
|
95
|
+
log: "Log",
|
|
96
|
+
// Version control / tooling
|
|
97
|
+
gitignore: "Git Ignore",
|
|
98
|
+
gitattributes: "Git Attributes",
|
|
99
|
+
dockerignore: "Docker Ignore",
|
|
100
|
+
editorconfig: "EditorConfig",
|
|
101
|
+
lock: "Lock File",
|
|
102
|
+
patch: "Patch",
|
|
103
|
+
diff: "Diff",
|
|
104
|
+
};
|
|
105
|
+
// Files whose whole name carries the type, with no extension to read.
|
|
106
|
+
const NAMES_BY_FILENAME = {
|
|
107
|
+
dockerfile: "Dockerfile",
|
|
108
|
+
makefile: "Makefile",
|
|
109
|
+
gnumakefile: "Makefile",
|
|
110
|
+
rakefile: "Ruby",
|
|
111
|
+
gemfile: "Ruby",
|
|
112
|
+
procfile: "Procfile",
|
|
113
|
+
license: "License",
|
|
114
|
+
readme: "Plain Text",
|
|
115
|
+
notice: "Plain Text",
|
|
116
|
+
};
|
|
117
|
+
/**
|
|
118
|
+
* A label for the editor status bar — never empty. Unknown extensions fall back
|
|
119
|
+
* to the extension itself in caps ("TOML" before it was listed above), which
|
|
120
|
+
* still tells the user more than "Unknown" would.
|
|
121
|
+
*/
|
|
122
|
+
export function getLanguageDisplayName(filename) {
|
|
123
|
+
const basename = filename.split(/[/\\]/).pop()?.toLowerCase() ?? "";
|
|
124
|
+
if (!basename) {
|
|
125
|
+
return "Plain Text";
|
|
126
|
+
}
|
|
127
|
+
const byFilename = NAMES_BY_FILENAME[basename];
|
|
128
|
+
if (byFilename) {
|
|
129
|
+
return byFilename;
|
|
130
|
+
}
|
|
131
|
+
// A leading dot is part of the name, not an extension separator: ".gitignore"
|
|
132
|
+
// has to read as "gitignore", not as an empty extension.
|
|
133
|
+
const withoutLeadingDot = basename.startsWith(".") ? basename.slice(1) : basename;
|
|
134
|
+
const dot = withoutLeadingDot.lastIndexOf(".");
|
|
135
|
+
const extension = dot === -1 ? withoutLeadingDot : withoutLeadingDot.slice(dot + 1);
|
|
136
|
+
if (!extension) {
|
|
137
|
+
return "Plain Text";
|
|
138
|
+
}
|
|
139
|
+
return NAMES_BY_EXTENSION[extension] ?? extension.toUpperCase();
|
|
140
|
+
}
|
|
141
|
+
//# sourceMappingURL=language-names.js.map
|