moonbit-syntax-highlighter 0.1.0 → 0.1.1

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/README.md CHANGED
@@ -2,7 +2,10 @@
2
2
 
3
3
  Reusable MoonBit syntax grammar package for front-end documentation tooling.
4
4
 
5
- This package vendors a MoonBit TextMate-style syntax definition and exposes stable Node-side entry points that documentation tools can consume.
5
+ This package ships two layers:
6
+
7
+ - the original MIT-licensed MoonBit Sublime syntax source for reuse and attribution
8
+ - a Shiki-compatible TextMate grammar registration for documentation stacks such as VitePress
6
9
 
7
10
  It is framework-agnostic by design: the package ships raw grammar access, metadata, and a small registration helper instead of binding itself to a single docs stack.
8
11
 
@@ -11,8 +14,9 @@ It is framework-agnostic by design: the package ships raw grammar access, metada
11
14
  - `moonbitGrammarPath`: absolute local path to the vendored `moonbit.sublime-syntax`
12
15
  - `moonbitGrammar`: raw grammar file contents as a string
13
16
  - `readMoonbitGrammar()`: reads the packaged grammar from disk
17
+ - `moonbitTextMateGrammar`: a Shiki-compatible TextMate grammar object for MoonBit
14
18
  - `moonbitLanguage`: language metadata for consumers that accept a custom language registration object
15
- - `createMoonbitLanguageRegistration()`: returns metadata plus inline grammar content for tools that prefer in-memory registration
19
+ - `createMoonbitLanguageRegistration()`: returns metadata plus a Shiki-compatible grammar object for tools that prefer in-memory registration
16
20
  - `moonbitAliases`: common aliases such as `moonbit`, `mbt`, and `mbti`
17
21
 
18
22
  ## Install
@@ -26,13 +30,13 @@ pnpm add moonbit-syntax-highlighter
26
30
  ```js
27
31
  import {
28
32
  createMoonbitLanguageRegistration,
29
- moonbitGrammarPath,
33
+ moonbitTextMateGrammar,
30
34
  } from 'moonbit-syntax-highlighter'
31
35
 
32
36
  const language = createMoonbitLanguageRegistration()
33
37
 
34
38
  console.log(language.scopeName)
35
- console.log(moonbitGrammarPath)
39
+ console.log(moonbitTextMateGrammar.scopeName)
36
40
  ```
37
41
 
38
42
  ```js
@@ -41,6 +45,23 @@ import { moonbitGrammar } from 'moonbit-syntax-highlighter/content'
41
45
  console.log(moonbitGrammar.slice(0, 40))
42
46
  ```
43
47
 
48
+ ```js
49
+ import { createHighlighter } from 'shiki'
50
+ import { createMoonbitLanguageRegistration } from 'moonbit-syntax-highlighter'
51
+
52
+ const highlighter = await createHighlighter({
53
+ themes: ['github-light'],
54
+ langs: [createMoonbitLanguageRegistration()],
55
+ })
56
+
57
+ const html = highlighter.codeToHtml('pub fn main() -> Int {\n return 1\n}', {
58
+ lang: 'moonbit',
59
+ theme: 'github-light',
60
+ })
61
+
62
+ console.log(html)
63
+ ```
64
+
44
65
  ## Intended Consumers
45
66
 
46
67
  - Shiki-based documentation sites such as VitePress or Astro
@@ -58,7 +79,7 @@ This package preserves upstream attribution in `LICENSE.upstream` and is intende
58
79
 
59
80
  ## Current Scope
60
81
 
61
- This first version focuses on packaging and reuse. It does not yet add framework-specific adapters, snapshot tests, or MoonBit-specific semantic highlighting.
82
+ This package currently focuses on practical static highlighting for docs and examples. It does not yet provide semantic highlighting, Markdown injection grammars, or editor-specific extension packaging.
62
83
 
63
84
  ## Local Development
64
85
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "moonbit-syntax-highlighter",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Reusable MoonBit syntax grammar package for documentation tooling and front-end highlighters.",
5
5
  "author": "Nanaloveyuki",
6
6
  "license": "MIT",
@@ -35,6 +35,9 @@
35
35
  "check": "node scripts/check.js",
36
36
  "pack:check": "pnpm pack --pack-destination .pack"
37
37
  },
38
+ "dependencies": {
39
+ "shiki": "^4.2.0"
40
+ },
38
41
  "types": "./src/index.d.ts",
39
42
  "exports": {
40
43
  ".": {
@@ -53,6 +56,10 @@
53
56
  "types": "./src/shiki.d.ts",
54
57
  "default": "./src/shiki.js"
55
58
  },
59
+ "./textmate": {
60
+ "types": "./src/textmate.d.ts",
61
+ "default": "./src/textmate.js"
62
+ },
56
63
  "./syntaxes/moonbit.sublime-syntax": "./syntaxes/moonbit.sublime-syntax",
57
64
  "./package.json": "./package.json"
58
65
  },
package/src/index.d.ts CHANGED
@@ -3,5 +3,6 @@ export { moonbitGrammar, readMoonbitGrammar } from './content.js'
3
3
  export {
4
4
  createMoonbitLanguageRegistration,
5
5
  moonbitLanguage,
6
+ moonbitTextMateGrammar,
6
7
  } from './shiki.js'
7
8
  export type { MoonbitLanguageRegistration } from './shiki.js'
package/src/index.js CHANGED
@@ -1,3 +1,3 @@
1
1
  export { moonbitAliases, moonbitGrammarPath, moonbitScopeName } from './grammar.js'
2
2
  export { moonbitGrammar, readMoonbitGrammar } from './content.js'
3
- export { moonbitLanguage, createMoonbitLanguageRegistration } from './shiki.js'
3
+ export { moonbitLanguage, createMoonbitLanguageRegistration, moonbitTextMateGrammar } from './shiki.js'
package/src/shiki.d.ts CHANGED
@@ -1,14 +1,19 @@
1
1
  import type { moonbitAliases, moonbitGrammarPath, moonbitScopeName } from './grammar.js'
2
+ import type { MoonbitTextMateGrammar } from './textmate.js'
2
3
 
3
4
  export interface MoonbitLanguageRegistration {
4
5
  id: 'moonbit'
5
- name: 'MoonBit'
6
+ name: 'moonbit'
7
+ displayName: 'MoonBit'
6
8
  scopeName: typeof moonbitScopeName
7
- aliases: typeof moonbitAliases
9
+ aliases: readonly ['mbt', 'mbti']
8
10
  path: typeof moonbitGrammarPath
9
- grammar: string
11
+ patterns: MoonbitTextMateGrammar['patterns']
12
+ repository: MoonbitTextMateGrammar['repository']
10
13
  }
11
14
 
12
15
  export declare const moonbitLanguage: Omit<MoonbitLanguageRegistration, 'grammar'>
13
16
 
14
17
  export declare function createMoonbitLanguageRegistration(): MoonbitLanguageRegistration
18
+
19
+ export declare const moonbitTextMateGrammar: MoonbitTextMateGrammar
package/src/shiki.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { moonbitGrammarPath, moonbitScopeName, moonbitAliases } from './grammar.js'
2
2
  import { moonbitGrammar } from './content.js'
3
+ import { moonbitTextMateGrammar } from './textmate.js'
3
4
 
4
5
  export const moonbitLanguage = {
5
6
  id: 'moonbit',
@@ -11,7 +12,12 @@ export const moonbitLanguage = {
11
12
 
12
13
  export function createMoonbitLanguageRegistration() {
13
14
  return {
14
- ...moonbitLanguage,
15
- grammar: moonbitGrammar,
15
+ ...moonbitTextMateGrammar,
16
+ id: moonbitLanguage.id,
17
+ path: moonbitLanguage.path,
18
+ displayName: moonbitLanguage.name,
19
+ aliases: moonbitAliases.filter(alias => alias !== 'moonbit'),
16
20
  }
17
21
  }
22
+
23
+ export { moonbitTextMateGrammar }
@@ -0,0 +1,10 @@
1
+ export interface MoonbitTextMateGrammar {
2
+ name: 'moonbit'
3
+ scopeName: 'source.moonbit'
4
+ aliases: readonly ['mbt', 'mbti']
5
+ patterns: Array<{ include: string }>
6
+ repository: Record<string, unknown>
7
+ }
8
+
9
+ export declare const moonbitTextMateGrammar: MoonbitTextMateGrammar
10
+
@@ -0,0 +1,131 @@
1
+ export const moonbitTextMateGrammar = {
2
+ name: 'moonbit',
3
+ scopeName: 'source.moonbit',
4
+ aliases: ['mbt', 'mbti'],
5
+ patterns: [
6
+ { include: '#comments' },
7
+ { include: '#strings' },
8
+ { include: '#numbers' },
9
+ { include: '#keywords' },
10
+ { include: '#types' },
11
+ { include: '#attributes' },
12
+ { include: '#functions' },
13
+ { include: '#operators' },
14
+ ],
15
+ repository: {
16
+ comments: {
17
+ patterns: [
18
+ {
19
+ name: 'comment.line.documentation.moonbit',
20
+ match: '///.*$',
21
+ },
22
+ {
23
+ name: 'comment.line.double-slash.moonbit',
24
+ match: '//.*$',
25
+ },
26
+ ],
27
+ },
28
+ strings: {
29
+ patterns: [
30
+ {
31
+ name: 'string.quoted.double.moonbit',
32
+ begin: '"',
33
+ end: '"',
34
+ patterns: [
35
+ {
36
+ name: 'constant.character.escape.moonbit',
37
+ match:
38
+ '\\\\(?:[nrtb"\\\\]|x[0-9A-Fa-f]{2}|u\\{[0-9A-Fa-f_]{1,6}\\})',
39
+ },
40
+ ],
41
+ },
42
+ {
43
+ name: 'string.quoted.single.moonbit',
44
+ begin: "'",
45
+ end: "'",
46
+ patterns: [
47
+ {
48
+ name: 'constant.character.escape.moonbit',
49
+ match:
50
+ "\\\\(?:[nrtb'\\\\]|x[0-9A-Fa-f]{2}|u\\{[0-9A-Fa-f_]{1,6}\\})",
51
+ },
52
+ ],
53
+ },
54
+ ],
55
+ },
56
+ numbers: {
57
+ patterns: [
58
+ {
59
+ name: 'constant.numeric.float.moonbit',
60
+ match:
61
+ '\\b(?:\\d[\\d_]*\\.\\d[\\d_]*|\\d[\\d_]*[eE][+-]?\\d[\\d_]*)\\b',
62
+ },
63
+ {
64
+ name: 'constant.numeric.integer.hex.moonbit',
65
+ match: '\\b0[xX][0-9A-Fa-f_]+\\b',
66
+ },
67
+ {
68
+ name: 'constant.numeric.integer.moonbit',
69
+ match: '\\b\\d[\\d_]*\\b',
70
+ },
71
+ ],
72
+ },
73
+ keywords: {
74
+ patterns: [
75
+ {
76
+ name: 'storage.modifier.moonbit',
77
+ match: '\\b(?:pub|priv|readonly|extern|mut)\\b',
78
+ },
79
+ {
80
+ name: 'keyword.control.moonbit',
81
+ match:
82
+ '\\b(?:if|else|match|lexmatch|guard|for|while|loop|break|continue|return|try|catch|except|raise|noraise|nobreak|using|as|in|is|async|defer)\\b',
83
+ },
84
+ {
85
+ name: 'keyword.declaration.moonbit',
86
+ match:
87
+ '\\b(?:fn|fnalias|type!?|typealias|let|letrec|const|enum|extenum|struct|import|trait|traitalias|derive|test|impl|with|recur|suberror|and|where|declare)\\b',
88
+ },
89
+ ],
90
+ },
91
+ types: {
92
+ patterns: [
93
+ {
94
+ name: 'support.type.builtin.moonbit',
95
+ match:
96
+ '\\b(?:Eq|Compare|Hash|Show|Logger|Default|ToJson|FromJson|None|Some|ArrayView|Array|FixedArray|Int16|Int64|Int|UInt16|UInt64|UInt|BigInt|Option|Result|BytesView|Bytes|Bool|Unit|Char|String|Float|Double|Error|Tuple|Hasher|Iter|Iter2|IterResult|Json|Map|Set|StringBuilder|UninitializedArray)\\b',
97
+ },
98
+ {
99
+ name: 'entity.name.type.moonbit',
100
+ match: '\\b[A-Z][A-Za-z0-9_]*\\b',
101
+ },
102
+ ],
103
+ },
104
+ attributes: {
105
+ patterns: [
106
+ {
107
+ name: 'variable.annotation.moonbit',
108
+ match: '#[a-z][A-Za-z0-9_]*',
109
+ },
110
+ ],
111
+ },
112
+ functions: {
113
+ patterns: [
114
+ {
115
+ name: 'entity.name.function.moonbit',
116
+ match: '\\b[a-z][A-Za-z0-9_]*(?=\\s*\\()',
117
+ },
118
+ ],
119
+ },
120
+ operators: {
121
+ patterns: [
122
+ {
123
+ name: 'keyword.operator.moonbit',
124
+ match:
125
+ '->|=>|\\|>|==|!=|<=|>=|&&|\\|\\||[-+*/%<>=:;,.{}()\\[\\]]',
126
+ },
127
+ ],
128
+ },
129
+ },
130
+ }
131
+