@otto-code/highlight 0.7.5 → 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 CHANGED
@@ -1,2 +1,12 @@
1
+ /**
2
+ * Every extension `detectLanguage` can return.
3
+ *
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
+ * before: the v0.2.5 merge dropped the shell and SQL rows from that table while
7
+ * these rules kept scoring both, so detection claimed a language the renderer
8
+ * could not colour.
9
+ */
10
+ export declare const DETECTABLE_EXTENSIONS: readonly string[];
1
11
  export declare function detectLanguage(code: string): string | null;
2
12
  //# sourceMappingURL=detect.d.ts.map
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 but it is deliberately conservative: when
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 the language is obvious well before
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 keyword-insensitive; combos are what make it unambiguous.
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 its parser handles plain JS)
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 },
@@ -107,6 +107,16 @@ function scoreRules(sample) {
107
107
  }
108
108
  return scores;
109
109
  }
110
+ /**
111
+ * Every extension `detectLanguage` can return.
112
+ *
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
+ * before: the v0.2.5 merge dropped the shell and SQL rows from that table while
116
+ * these rules kept scoring both, so detection claimed a language the renderer
117
+ * could not colour.
118
+ */
119
+ export const DETECTABLE_EXTENSIONS = [...new Set(RULES.map((rule) => rule.ext))];
110
120
  // Best-effort guess of the language extension for a code block, or null when
111
121
  // there isn't enough signal to be confident.
112
122
  export function detectLanguage(code) {
@@ -114,7 +124,7 @@ export function detectLanguage(code) {
114
124
  const trimmed = sample.trim();
115
125
  if (trimmed.length < 3)
116
126
  return null;
117
- // Shebang the single strongest signal, short-circuit on it.
127
+ // Shebang - the single strongest signal, short-circuit on it.
118
128
  if (trimmed.startsWith("#!")) {
119
129
  const firstLine = trimmed.slice(0, trimmed.indexOf("\n") === -1 ? undefined : trimmed.indexOf("\n"));
120
130
  if (/\b(bash|zsh|ksh|sh)\b/.test(firstLine))
@@ -124,14 +134,14 @@ export function detectLanguage(code) {
124
134
  if (/\bnode\b/.test(firstLine))
125
135
  return "ts";
126
136
  }
127
- // JSON structural and cheaply verifiable, so a successful parse is decisive.
137
+ // JSON - structural and cheaply verifiable, so a successful parse is decisive.
128
138
  if (/^[[{]/.test(trimmed) && /[\]}]$/.test(trimmed)) {
129
139
  try {
130
140
  JSON.parse(trimmed);
131
141
  return "json";
132
142
  }
133
143
  catch {
134
- // Not valid JSON likely a JS object literal or a fragment; keep scoring.
144
+ // Not valid JSON - likely a JS object literal or a fragment; keep scoring.
135
145
  }
136
146
  }
137
147
  const scores = scoreRules(sample);
@@ -1,48 +1,6 @@
1
- import { highlightTree, tagHighlighter, tags } from "@lezer/highlight";
1
+ import { highlightTree } from "@lezer/highlight";
2
2
  import { getParserForFile } from "./parsers.js";
3
- const highlighter = tagHighlighter([
4
- { tag: tags.keyword, class: "keyword" },
5
- { tag: tags.controlKeyword, class: "keyword" },
6
- { tag: tags.operatorKeyword, class: "keyword" },
7
- { tag: tags.definitionKeyword, class: "keyword" },
8
- { tag: tags.moduleKeyword, class: "keyword" },
9
- { tag: tags.comment, class: "comment" },
10
- { tag: tags.lineComment, class: "comment" },
11
- { tag: tags.blockComment, class: "comment" },
12
- { tag: tags.docComment, class: "comment" },
13
- { tag: tags.string, class: "string" },
14
- { tag: tags.special(tags.string), class: "string" },
15
- { tag: tags.number, class: "number" },
16
- { tag: tags.integer, class: "number" },
17
- { tag: tags.float, class: "number" },
18
- { tag: tags.bool, class: "literal" },
19
- { tag: tags.null, class: "literal" },
20
- { tag: tags.function(tags.variableName), class: "function" },
21
- { tag: tags.function(tags.propertyName), class: "function" },
22
- { tag: tags.definition(tags.variableName), class: "definition" },
23
- { tag: tags.definition(tags.propertyName), class: "definition" },
24
- { tag: tags.definition(tags.function(tags.variableName)), class: "definition" },
25
- { tag: tags.className, class: "class" },
26
- { tag: tags.definition(tags.className), class: "class" },
27
- { tag: tags.typeName, class: "type" },
28
- { tag: tags.tagName, class: "tag" },
29
- { tag: tags.attributeName, class: "attribute" },
30
- { tag: tags.attributeValue, class: "string" },
31
- { tag: tags.propertyName, class: "property" },
32
- { tag: tags.variableName, class: "variable" },
33
- { tag: tags.local(tags.variableName), class: "variable" },
34
- { tag: tags.special(tags.variableName), class: "variable" },
35
- { tag: tags.operator, class: "operator" },
36
- { tag: tags.punctuation, class: "punctuation" },
37
- { tag: tags.bracket, class: "punctuation" },
38
- { tag: tags.separator, class: "punctuation" },
39
- { tag: tags.regexp, class: "regexp" },
40
- { tag: tags.escape, class: "escape" },
41
- { tag: tags.meta, class: "meta" },
42
- { tag: tags.heading, class: "heading" },
43
- { tag: tags.link, class: "link" },
44
- { tag: tags.url, class: "link" },
45
- ]);
3
+ import { staticSyntaxHighlighter } from "./syntax-roles.js";
46
4
  export function highlightCode(code, filename) {
47
5
  const parser = getParserForFile(filename);
48
6
  if (!parser) {
@@ -56,7 +14,7 @@ export function highlightCode(code, filename) {
56
14
  }
57
15
  // Build a map of character positions to styles
58
16
  const styleMap = Array.from({ length: code.length }, () => null);
59
- highlightTree(tree, highlighter, (from, to, classes) => {
17
+ highlightTree(tree, staticSyntaxHighlighter, (from, to, classes) => {
60
18
  for (let i = from; i < to && i < styleMap.length; i++) {
61
19
  styleMap[i] = classes;
62
20
  }
package/dist/index.d.ts CHANGED
@@ -1,10 +1,13 @@
1
1
  export type { HighlightStyle, HighlightToken } from "./types.js";
2
- export { getParserForFile, isLanguageSupported, getSupportedExtensions } from "./parsers.js";
2
+ export { getLanguageForFile, getParserForFile, isLanguageSupported, getSupportedExtensions, } from "./parsers.js";
3
+ export { createCodeMirrorHighlightStyle } from "./syntax-roles.js";
3
4
  export { getLanguageDisplayName } from "./language-names.js";
4
5
  export { highlightCode, highlightLine } from "./highlighter.js";
5
6
  export { detectLanguage } from "./detect.js";
6
7
  export { extractSymbols } from "./symbols.js";
7
8
  export type { CodeSymbol, SymbolKind } from "./symbols.js";
9
+ export { extractMarkdownHeadings } from "./markdown-headings.js";
10
+ export type { MarkdownHeading } from "./markdown-headings.js";
8
11
  export { darkHighlightColors, lightHighlightColors } from "./colors.js";
9
12
  export type { SyntaxThemeId, SyntaxThemeOption, SyntaxColors } from "./themes.js";
10
13
  export { SYNTAX_THEME_IDS, SYNTAX_THEME_OPTIONS, isSyntaxThemeId, resolveSyntaxColors, } from "./themes.js";
package/dist/index.js CHANGED
@@ -1,8 +1,10 @@
1
- export { getParserForFile, isLanguageSupported, getSupportedExtensions } from "./parsers.js";
1
+ export { getLanguageForFile, getParserForFile, isLanguageSupported, getSupportedExtensions, } from "./parsers.js";
2
+ export { createCodeMirrorHighlightStyle } from "./syntax-roles.js";
2
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";
7
+ export { extractMarkdownHeadings } from "./markdown-headings.js";
6
8
  export { darkHighlightColors, lightHighlightColors } from "./colors.js";
7
9
  export { SYNTAX_THEME_IDS, SYNTAX_THEME_OPTIONS, isSyntaxThemeId, resolveSyntaxColors, } from "./themes.js";
8
10
  //# sourceMappingURL=index.js.map
@@ -1,5 +1,5 @@
1
1
  /**
2
- * A label for the editor status bar never empty. Unknown extensions fall back
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
  */
@@ -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 never empty. Unknown extensions fall back
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
  */
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Markdown headings, for the document outline and for link autocompletion
3
+ * against a document's own anchors.
4
+ *
5
+ * **This is deliberately not part of `extractSymbols`.** A heading is not a
6
+ * `SymbolKind`, and adding one would mean adding a value to
7
+ * `CodeSymbolKindSchema` - a `z.enum` on the wire. A six-month-old client
8
+ * parsing a `code.outline.response` carrying `kind: "heading"` would reject the
9
+ * whole message, which the protocol contract forbids. Headings therefore stay
10
+ * **client-side**: the client already holds the document it wants an outline of,
11
+ * so there is nothing to ask the daemon for. That also lets a heading carry its
12
+ * level, which the flat symbol shape cannot express and a real table of contents
13
+ * needs.
14
+ */
15
+ export interface MarkdownHeading {
16
+ /** 1 through 6, from the marker count (ATX) or the underline character (Setext). */
17
+ level: number;
18
+ /**
19
+ * The heading text with its markers removed. Inline markup is left exactly as
20
+ * written: an outline row showing `**Setup**` is honest about the source, and
21
+ * stripping emphasis here would mean a second, partial markdown parser.
22
+ */
23
+ text: string;
24
+ /** 1-based line the heading starts on. */
25
+ line: number;
26
+ /** 0-based offset of the heading node, for scrolling straight to it. */
27
+ from: number;
28
+ }
29
+ /**
30
+ * Extract the headings of a markdown document, in document order.
31
+ *
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 -
34
+ * the single most common way a regex-based outline goes wrong on a README.
35
+ */
36
+ export declare function extractMarkdownHeadings(code: string): MarkdownHeading[];
37
+ //# sourceMappingURL=markdown-headings.d.ts.map
@@ -0,0 +1,64 @@
1
+ import { parser as markdownParser } from "@lezer/markdown";
2
+ const HEADING_NODE = /^(?:ATX|Setext)Heading([1-6])$/;
3
+ // `## Title ##` - the leading run, and the optional closing run ATX allows.
4
+ // The closing run must be preceded by whitespace, per CommonMark, which is what
5
+ // keeps `# C#` from becoming "C".
6
+ const ATX_LEADING = /^[ \t]*#{1,6}[ \t]*/;
7
+ const ATX_TRAILING = /\s#+[ \t]*$/;
8
+ function buildLineStarts(code) {
9
+ const starts = [0];
10
+ for (let index = 0; index < code.length; index += 1) {
11
+ if (code.charCodeAt(index) === 10) {
12
+ starts.push(index + 1);
13
+ }
14
+ }
15
+ return starts;
16
+ }
17
+ // Binary search for the 0-based line index whose start is <= offset.
18
+ function lineIndexForOffset(lineStarts, offset) {
19
+ let low = 0;
20
+ let high = lineStarts.length - 1;
21
+ while (low < high) {
22
+ const mid = (low + high + 1) >> 1;
23
+ if (lineStarts[mid] <= offset) {
24
+ low = mid;
25
+ }
26
+ else {
27
+ high = mid - 1;
28
+ }
29
+ }
30
+ return low;
31
+ }
32
+ /**
33
+ * Extract the headings of a markdown document, in document order.
34
+ *
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 -
37
+ * the single most common way a regex-based outline goes wrong on a README.
38
+ */
39
+ export function extractMarkdownHeadings(code) {
40
+ const tree = markdownParser.parse(code);
41
+ const lineStarts = buildLineStarts(code);
42
+ const headings = [];
43
+ const cursor = tree.cursor();
44
+ do {
45
+ const match = HEADING_NODE.exec(cursor.name);
46
+ if (!match) {
47
+ continue;
48
+ }
49
+ const level = Number(match[1]);
50
+ const raw = code.slice(cursor.from, cursor.to);
51
+ // A Setext heading spans its text line and its underline; the underline is
52
+ // the marker, so only the first line is the text.
53
+ const firstLine = raw.split("\n", 1)[0] ?? "";
54
+ const text = firstLine.replace(ATX_LEADING, "").replace(ATX_TRAILING, "").trim();
55
+ headings.push({
56
+ level,
57
+ text,
58
+ line: lineIndexForOffset(lineStarts, cursor.from) + 1,
59
+ from: cursor.from,
60
+ });
61
+ } while (cursor.next());
62
+ return headings;
63
+ }
64
+ //# sourceMappingURL=markdown-headings.js.map
package/dist/parsers.d.ts CHANGED
@@ -1,4 +1,6 @@
1
+ import { Language } from "@codemirror/language";
1
2
  import type { Parser } from "@lezer/common";
3
+ export declare function getLanguageForFile(filename: string): Language | null;
2
4
  export declare function getParserForFile(filename: string): Parser | null;
3
5
  export declare function isLanguageSupported(filename: string): boolean;
4
6
  export declare function getSupportedExtensions(): string[];
package/dist/parsers.js CHANGED
@@ -1,8 +1,8 @@
1
- import { StreamLanguage } from "@codemirror/language";
1
+ import { defineLanguageFacet, Language, StreamLanguage } from "@codemirror/language";
2
2
  import { dart } from "@codemirror/legacy-modes/mode/clike";
3
- import { swift } from "@codemirror/legacy-modes/mode/swift";
4
3
  import { shell } from "@codemirror/legacy-modes/mode/shell";
5
4
  import { standardSQL } from "@codemirror/legacy-modes/mode/sql";
5
+ import { swift } from "@codemirror/legacy-modes/mode/swift";
6
6
  import { parser as jsParser } from "@lezer/javascript";
7
7
  import { parser as jsonParser } from "@lezer/json";
8
8
  import { parser as cssParser } from "@lezer/css";
@@ -18,79 +18,90 @@ import { parser as xmlParser } from "@lezer/xml";
18
18
  import { parser as yamlParser } from "@lezer/yaml";
19
19
  import { csharpLanguage } from "@replit/codemirror-lang-csharp";
20
20
  import { parser as elixirParser } from "lezer-elixir";
21
+ function language(parser) {
22
+ return new Language(defineLanguageFacet(), parser);
23
+ }
21
24
  // Shared instance so the four shell fence aliases don't each build a grammar.
22
- const shellParser = StreamLanguage.define(shell).parser;
23
- const parsersByExtension = {
25
+ const shellLanguage = StreamLanguage.define(shell);
26
+ const languagesByExtension = {
24
27
  // JavaScript/TypeScript
25
- js: jsParser,
26
- jsx: jsParser.configure({ dialect: "jsx" }),
27
- ts: jsParser.configure({ dialect: "ts" }),
28
- tsx: jsParser.configure({ dialect: "ts jsx" }),
29
- mjs: jsParser,
30
- cjs: jsParser,
28
+ js: language(jsParser),
29
+ jsx: language(jsParser.configure({ dialect: "jsx" })),
30
+ ts: language(jsParser.configure({ dialect: "ts" })),
31
+ tsx: language(jsParser.configure({ dialect: "ts jsx" })),
32
+ mjs: language(jsParser),
33
+ cjs: language(jsParser),
31
34
  // C / C++ / Objective-C
32
- c: cppParser,
33
- h: cppParser,
34
- cc: cppParser,
35
- cpp: cppParser,
36
- cxx: cppParser,
37
- hpp: cppParser,
38
- hxx: cppParser,
39
- m: cppParser,
40
- mm: cppParser,
35
+ c: language(cppParser),
36
+ h: language(cppParser),
37
+ cc: language(cppParser),
38
+ cpp: language(cppParser),
39
+ cxx: language(cppParser),
40
+ hpp: language(cppParser),
41
+ hxx: language(cppParser),
42
+ m: language(cppParser),
43
+ mm: language(cppParser),
41
44
  // JSON
42
- json: jsonParser,
45
+ json: language(jsonParser),
43
46
  // CSS
44
- css: cssParser,
45
- scss: cssParser,
47
+ css: language(cssParser),
48
+ scss: language(cssParser),
46
49
  // HTML
47
- html: htmlParser,
48
- htm: htmlParser,
50
+ html: language(htmlParser),
51
+ htm: language(htmlParser),
49
52
  // XML
50
- xml: xmlParser,
53
+ xml: language(xmlParser),
51
54
  // Java
52
- java: javaParser,
55
+ java: language(javaParser),
53
56
  // Python
54
- py: pythonParser,
57
+ py: language(pythonParser),
55
58
  // Go
56
- go: goParser,
59
+ go: language(goParser),
57
60
  // PHP
58
- php: phpParser,
61
+ php: language(phpParser),
59
62
  // YAML
60
- yaml: yamlParser,
61
- yml: yamlParser,
63
+ yaml: language(yamlParser),
64
+ yml: language(yamlParser),
62
65
  // Rust
63
- rs: rustParser,
66
+ rs: language(rustParser),
64
67
  // Swift
65
- swift: StreamLanguage.define(swift).parser,
68
+ swift: StreamLanguage.define(swift),
66
69
  // Dart
67
- dart: StreamLanguage.define(dart).parser,
68
- // Shell (fence tags bash/sh/zsh/shell all map here)
69
- sh: shellParser,
70
- bash: shellParser,
71
- zsh: shellParser,
72
- shell: shellParser,
73
- // SQL
74
- sql: StreamLanguage.define(standardSQL).parser,
70
+ dart: StreamLanguage.define(dart),
75
71
  // C#
76
- cs: csharpLanguage.parser,
72
+ cs: csharpLanguage,
77
73
  // Elixir
78
- ex: elixirParser,
79
- exs: elixirParser,
74
+ ex: language(elixirParser),
75
+ exs: language(elixirParser),
80
76
  // Markdown
81
- md: markdownParser,
82
- mdx: markdownParser,
77
+ md: language(markdownParser),
78
+ mdx: language(markdownParser),
79
+ // Shell. `detect.ts` has scored shell since it was written and can return
80
+ // "sh", so without these rows we classified a snippet as shell and then had
81
+ // nothing to colour it with. Lost in the Paseo v0.2.5 merge when this table
82
+ // took upstream's shape; see projects/paseo-v025-merge/audit-findings.md.
83
+ // All four fence tags (sh/bash/zsh/shell) map here.
84
+ sh: shellLanguage,
85
+ bash: shellLanguage,
86
+ zsh: shellLanguage,
87
+ shell: shellLanguage,
88
+ // SQL. Same story: "sql" is a detect.ts verdict. `standardSQL` is the dialect
89
+ // -neutral mode, which is the right default for snippets of unknown origin.
90
+ sql: StreamLanguage.define(standardSQL),
83
91
  };
84
- export function getParserForFile(filename) {
92
+ export function getLanguageForFile(filename) {
85
93
  const ext = filename.split(".").pop()?.toLowerCase();
86
94
  if (!ext)
87
95
  return null;
88
- return parsersByExtension[ext] ?? null;
96
+ return languagesByExtension[ext] ?? null;
97
+ }
98
+ export function getParserForFile(filename) {
99
+ return getLanguageForFile(filename)?.parser ?? null;
89
100
  }
90
101
  export function isLanguageSupported(filename) {
91
102
  return getParserForFile(filename) !== null;
92
103
  }
93
104
  export function getSupportedExtensions() {
94
- return Object.keys(parsersByExtension);
105
+ return Object.keys(languagesByExtension);
95
106
  }
96
107
  //# sourceMappingURL=parsers.js.map
@@ -0,0 +1,10 @@
1
+ import { HighlightStyle as CodeMirrorHighlightStyle } from "@codemirror/language";
2
+ import { type Tag } from "@lezer/highlight";
3
+ import type { HighlightStyle } from "./types.js";
4
+ export declare const syntaxRoleTags: ReadonlyArray<{
5
+ tag: Tag;
6
+ role: HighlightStyle;
7
+ }>;
8
+ export declare const staticSyntaxHighlighter: import("@lezer/highlight").Highlighter;
9
+ export declare function createCodeMirrorHighlightStyle(colors: Record<HighlightStyle, string>): CodeMirrorHighlightStyle;
10
+ //# sourceMappingURL=syntax-roles.d.ts.map
@@ -0,0 +1,50 @@
1
+ import { HighlightStyle as CodeMirrorHighlightStyle } from "@codemirror/language";
2
+ import { tagHighlighter, tags } from "@lezer/highlight";
3
+ export const syntaxRoleTags = [
4
+ { tag: tags.keyword, role: "keyword" },
5
+ { tag: tags.controlKeyword, role: "keyword" },
6
+ { tag: tags.operatorKeyword, role: "keyword" },
7
+ { tag: tags.definitionKeyword, role: "keyword" },
8
+ { tag: tags.moduleKeyword, role: "keyword" },
9
+ { tag: tags.comment, role: "comment" },
10
+ { tag: tags.lineComment, role: "comment" },
11
+ { tag: tags.blockComment, role: "comment" },
12
+ { tag: tags.docComment, role: "comment" },
13
+ { tag: tags.string, role: "string" },
14
+ { tag: tags.special(tags.string), role: "string" },
15
+ { tag: tags.number, role: "number" },
16
+ { tag: tags.integer, role: "number" },
17
+ { tag: tags.float, role: "number" },
18
+ { tag: tags.bool, role: "literal" },
19
+ { tag: tags.null, role: "literal" },
20
+ { tag: tags.function(tags.variableName), role: "function" },
21
+ { tag: tags.function(tags.propertyName), role: "function" },
22
+ { tag: tags.definition(tags.variableName), role: "definition" },
23
+ { tag: tags.definition(tags.propertyName), role: "definition" },
24
+ { tag: tags.definition(tags.function(tags.variableName)), role: "definition" },
25
+ { tag: tags.className, role: "class" },
26
+ { tag: tags.definition(tags.className), role: "class" },
27
+ { tag: tags.typeName, role: "type" },
28
+ { tag: tags.tagName, role: "tag" },
29
+ { tag: tags.attributeName, role: "attribute" },
30
+ { tag: tags.attributeValue, role: "string" },
31
+ { tag: tags.propertyName, role: "property" },
32
+ { tag: tags.variableName, role: "variable" },
33
+ { tag: tags.local(tags.variableName), role: "variable" },
34
+ { tag: tags.special(tags.variableName), role: "variable" },
35
+ { tag: tags.operator, role: "operator" },
36
+ { tag: tags.punctuation, role: "punctuation" },
37
+ { tag: tags.bracket, role: "punctuation" },
38
+ { tag: tags.separator, role: "punctuation" },
39
+ { tag: tags.regexp, role: "regexp" },
40
+ { tag: tags.escape, role: "escape" },
41
+ { tag: tags.meta, role: "meta" },
42
+ { tag: tags.heading, role: "heading" },
43
+ { tag: tags.link, role: "link" },
44
+ { tag: tags.url, role: "link" },
45
+ ];
46
+ export const staticSyntaxHighlighter = tagHighlighter(syntaxRoleTags.map(({ tag, role }) => ({ tag, class: role })));
47
+ export function createCodeMirrorHighlightStyle(colors) {
48
+ return CodeMirrorHighlightStyle.define(syntaxRoleTags.map(({ tag, role }) => ({ tag, color: colors[role] })));
49
+ }
50
+ //# sourceMappingURL=syntax-roles.js.map
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 the CGA-basic baseline) -------
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 gothic pink/purple/cyan, formerly "Dracula";
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 cyber yellow, hot pink, neon cyan) ----------
204
+ // --- Neotokyo (Light / Dark - cyber yellow, hot pink, neon cyan) ----------
205
205
  const neotokyoLight = {
206
206
  base: "#1a1025",
207
207
  keyword: "#c2188f",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@otto-code/highlight",
3
- "version": "0.7.5",
3
+ "version": "0.8.0",
4
4
  "license": "AGPL-3.0-or-later",
5
5
  "files": [
6
6
  "dist",
@@ -28,7 +28,7 @@
28
28
  "typecheck": "tsgo --noEmit"
29
29
  },
30
30
  "dependencies": {
31
- "@codemirror/language": "^6.12.3",
31
+ "@codemirror/language": "6.12.4",
32
32
  "@codemirror/legacy-modes": "^6.5.3",
33
33
  "@lezer/common": "^1.5.0",
34
34
  "@lezer/cpp": "^1.1.5",