@otto-code/highlight 0.7.6 → 0.8.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/dist/detect.d.ts +2 -2
- package/dist/detect.js +9 -9
- package/dist/language-names.d.ts +1 -1
- package/dist/language-names.js +1 -1
- package/dist/markdown-headings.d.ts +2 -2
- package/dist/markdown-headings.js +2 -2
- package/dist/themes.js +3 -3
- package/package.json +1 -1
package/dist/detect.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Every extension `detectLanguage` can return.
|
|
3
3
|
*
|
|
4
|
-
* Exported so the invariant in this file's header
|
|
5
|
-
* parsers.ts's table
|
|
4
|
+
* Exported so the invariant in this file's header - that each one is a key in
|
|
5
|
+
* parsers.ts's table - can actually be tested. It stopped being true once
|
|
6
6
|
* before: the v0.2.5 merge dropped the shell and SQL rows from that table while
|
|
7
7
|
* these rules kept scoring both, so detection claimed a language the renderer
|
|
8
8
|
* could not colour.
|
package/dist/detect.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
// Lightweight, dependency-free language guesser for code fences that arrive
|
|
2
2
|
// without an info string. Agents emit bare ``` blocks constantly, so this
|
|
3
|
-
// recovers highlighting for them
|
|
3
|
+
// recovers highlighting for them - but it is deliberately conservative: when
|
|
4
4
|
// the signals are weak or two languages tie, it returns null and the caller
|
|
5
5
|
// renders plain monospace rather than confidently mis-coloring the block.
|
|
6
6
|
//
|
|
7
7
|
// Every returned extension is a key in parsers.ts's table, so the result plugs
|
|
8
8
|
// straight into highlightCode(`x.${ext}`).
|
|
9
|
-
// Only look at the head of large blocks
|
|
9
|
+
// Only look at the head of large blocks - the language is obvious well before
|
|
10
10
|
// 4k chars, and detection runs on every streamed chunk.
|
|
11
11
|
const SAMPLE_LIMIT = 4000;
|
|
12
12
|
// A guess only wins if it clears this score AND beats the runner-up by the
|
|
@@ -28,7 +28,7 @@ const RULES = [
|
|
|
28
28
|
{ ext: "sh", re: /^\s*(if|then|fi|for|do|done|while|case|esac|function)\b.*;?\s*$/m, weight: 1 },
|
|
29
29
|
{ ext: "sh", re: /\|\s*(grep|awk|sed|xargs|head|tail|sort|uniq|wc)\b/, weight: 2 },
|
|
30
30
|
{ ext: "sh", re: /^\s*export\s+\w+=/m, weight: 2 },
|
|
31
|
-
// SQL
|
|
31
|
+
// SQL - keyword-insensitive; combos are what make it unambiguous.
|
|
32
32
|
{ ext: "sql", re: /\bSELECT\b[\s\S]*\bFROM\b/i, weight: 4 },
|
|
33
33
|
{ ext: "sql", re: /\bINSERT\s+INTO\b/i, weight: 4 },
|
|
34
34
|
{ ext: "sql", re: /\bUPDATE\b[\s\S]*\bSET\b/i, weight: 4 },
|
|
@@ -45,7 +45,7 @@ const RULES = [
|
|
|
45
45
|
{ ext: "py", re: /\bprint\s*\(/, weight: 1 },
|
|
46
46
|
{ ext: "py", re: /\b(True|False|None)\b/, weight: 1 },
|
|
47
47
|
{ ext: "py", re: /^\s*@\w+/m, weight: 1 },
|
|
48
|
-
// JavaScript / TypeScript (folded to ts
|
|
48
|
+
// JavaScript / TypeScript (folded to ts - its parser handles plain JS)
|
|
49
49
|
{ ext: "ts", re: /\b(const|let)\s+\w+\s*=/, weight: 2 },
|
|
50
50
|
{ ext: "ts", re: /\bfunction\s*\*?\s*\w*\s*\(/, weight: 2 },
|
|
51
51
|
{ ext: "ts", re: /=>\s*[{([]/, weight: 2 },
|
|
@@ -110,8 +110,8 @@ function scoreRules(sample) {
|
|
|
110
110
|
/**
|
|
111
111
|
* Every extension `detectLanguage` can return.
|
|
112
112
|
*
|
|
113
|
-
* Exported so the invariant in this file's header
|
|
114
|
-
* parsers.ts's table
|
|
113
|
+
* Exported so the invariant in this file's header - that each one is a key in
|
|
114
|
+
* parsers.ts's table - can actually be tested. It stopped being true once
|
|
115
115
|
* before: the v0.2.5 merge dropped the shell and SQL rows from that table while
|
|
116
116
|
* these rules kept scoring both, so detection claimed a language the renderer
|
|
117
117
|
* could not colour.
|
|
@@ -124,7 +124,7 @@ export function detectLanguage(code) {
|
|
|
124
124
|
const trimmed = sample.trim();
|
|
125
125
|
if (trimmed.length < 3)
|
|
126
126
|
return null;
|
|
127
|
-
// Shebang
|
|
127
|
+
// Shebang - the single strongest signal, short-circuit on it.
|
|
128
128
|
if (trimmed.startsWith("#!")) {
|
|
129
129
|
const firstLine = trimmed.slice(0, trimmed.indexOf("\n") === -1 ? undefined : trimmed.indexOf("\n"));
|
|
130
130
|
if (/\b(bash|zsh|ksh|sh)\b/.test(firstLine))
|
|
@@ -134,14 +134,14 @@ export function detectLanguage(code) {
|
|
|
134
134
|
if (/\bnode\b/.test(firstLine))
|
|
135
135
|
return "ts";
|
|
136
136
|
}
|
|
137
|
-
// JSON
|
|
137
|
+
// JSON - structural and cheaply verifiable, so a successful parse is decisive.
|
|
138
138
|
if (/^[[{]/.test(trimmed) && /[\]}]$/.test(trimmed)) {
|
|
139
139
|
try {
|
|
140
140
|
JSON.parse(trimmed);
|
|
141
141
|
return "json";
|
|
142
142
|
}
|
|
143
143
|
catch {
|
|
144
|
-
// Not valid JSON
|
|
144
|
+
// Not valid JSON - likely a JS object literal or a fragment; keep scoring.
|
|
145
145
|
}
|
|
146
146
|
}
|
|
147
147
|
const scores = scoreRules(sample);
|
package/dist/language-names.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* A label for the editor status bar
|
|
2
|
+
* A label for the editor status bar - never empty. Unknown extensions fall back
|
|
3
3
|
* to the extension itself in caps ("TOML" before it was listed above), which
|
|
4
4
|
* still tells the user more than "Unknown" would.
|
|
5
5
|
*/
|
package/dist/language-names.js
CHANGED
|
@@ -115,7 +115,7 @@ const NAMES_BY_FILENAME = {
|
|
|
115
115
|
notice: "Plain Text",
|
|
116
116
|
};
|
|
117
117
|
/**
|
|
118
|
-
* A label for the editor status bar
|
|
118
|
+
* A label for the editor status bar - never empty. Unknown extensions fall back
|
|
119
119
|
* to the extension itself in caps ("TOML" before it was listed above), which
|
|
120
120
|
* still tells the user more than "Unknown" would.
|
|
121
121
|
*/
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*
|
|
5
5
|
* **This is deliberately not part of `extractSymbols`.** A heading is not a
|
|
6
6
|
* `SymbolKind`, and adding one would mean adding a value to
|
|
7
|
-
* `CodeSymbolKindSchema`
|
|
7
|
+
* `CodeSymbolKindSchema` - a `z.enum` on the wire. A six-month-old client
|
|
8
8
|
* parsing a `code.outline.response` carrying `kind: "heading"` would reject the
|
|
9
9
|
* whole message, which the protocol contract forbids. Headings therefore stay
|
|
10
10
|
* **client-side**: the client already holds the document it wants an outline of,
|
|
@@ -30,7 +30,7 @@ export interface MarkdownHeading {
|
|
|
30
30
|
* Extract the headings of a markdown document, in document order.
|
|
31
31
|
*
|
|
32
32
|
* This parses rather than scanning for `#` because only a parse knows that a
|
|
33
|
-
* `#` opening a line inside a fenced code block is a comment, not a heading
|
|
33
|
+
* `#` opening a line inside a fenced code block is a comment, not a heading -
|
|
34
34
|
* the single most common way a regex-based outline goes wrong on a README.
|
|
35
35
|
*/
|
|
36
36
|
export declare function extractMarkdownHeadings(code: string): MarkdownHeading[];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { parser as markdownParser } from "@lezer/markdown";
|
|
2
2
|
const HEADING_NODE = /^(?:ATX|Setext)Heading([1-6])$/;
|
|
3
|
-
// `## Title ##`
|
|
3
|
+
// `## Title ##` - the leading run, and the optional closing run ATX allows.
|
|
4
4
|
// The closing run must be preceded by whitespace, per CommonMark, which is what
|
|
5
5
|
// keeps `# C#` from becoming "C".
|
|
6
6
|
const ATX_LEADING = /^[ \t]*#{1,6}[ \t]*/;
|
|
@@ -33,7 +33,7 @@ function lineIndexForOffset(lineStarts, offset) {
|
|
|
33
33
|
* Extract the headings of a markdown document, in document order.
|
|
34
34
|
*
|
|
35
35
|
* This parses rather than scanning for `#` because only a parse knows that a
|
|
36
|
-
* `#` opening a line inside a fenced code block is a comment, not a heading
|
|
36
|
+
* `#` opening a line inside a fenced code block is a comment, not a heading -
|
|
37
37
|
* the single most common way a regex-based outline goes wrong on a README.
|
|
38
38
|
*/
|
|
39
39
|
export function extractMarkdownHeadings(code) {
|
package/dist/themes.js
CHANGED
|
@@ -55,7 +55,7 @@ function expandRolePalette(r) {
|
|
|
55
55
|
diffRemovedEmphasis: withAlpha(r.diffRemoved, 0.35),
|
|
56
56
|
};
|
|
57
57
|
}
|
|
58
|
-
// --- Default (high-contrast primary hues
|
|
58
|
+
// --- Default (high-contrast primary hues - the CGA-basic baseline) -------
|
|
59
59
|
const defaultLight = {
|
|
60
60
|
base: "#000000",
|
|
61
61
|
keyword: "#0000aa",
|
|
@@ -171,7 +171,7 @@ const monokaiDark = {
|
|
|
171
171
|
diffAdded: "rgba(166, 226, 46, 0.18)",
|
|
172
172
|
diffRemoved: "rgba(248, 53, 53, 0.18)",
|
|
173
173
|
};
|
|
174
|
-
// --- Nightshade (Light / Dark
|
|
174
|
+
// --- Nightshade (Light / Dark - gothic pink/purple/cyan, formerly "Dracula";
|
|
175
175
|
// renamed once it grew a light variant the original theme never had) --------
|
|
176
176
|
const nightshadeLight = {
|
|
177
177
|
base: "#282a36",
|
|
@@ -201,7 +201,7 @@ const nightshadeDark = {
|
|
|
201
201
|
diffAdded: "rgba(80, 250, 123, 0.18)",
|
|
202
202
|
diffRemoved: "rgba(255, 85, 85, 0.18)",
|
|
203
203
|
};
|
|
204
|
-
// --- Neotokyo (Light / Dark
|
|
204
|
+
// --- Neotokyo (Light / Dark - cyber yellow, hot pink, neon cyan) ----------
|
|
205
205
|
const neotokyoLight = {
|
|
206
206
|
base: "#1a1025",
|
|
207
207
|
keyword: "#c2188f",
|