moonbit-syntax-highlighter
v0.1.1
Published
Reusable MoonBit syntax grammar package for documentation tooling and front-end highlighters.
Maintainers
Readme
moonbit-syntax-highlighter
Reusable MoonBit syntax grammar package for front-end documentation tooling.
This package ships two layers:
- the original MIT-licensed MoonBit Sublime syntax source for reuse and attribution
- a Shiki-compatible TextMate grammar registration for documentation stacks such as VitePress
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.
What This Package Exports
moonbitGrammarPath: absolute local path to the vendoredmoonbit.sublime-syntaxmoonbitGrammar: raw grammar file contents as a stringreadMoonbitGrammar(): reads the packaged grammar from diskmoonbitTextMateGrammar: a Shiki-compatible TextMate grammar object for MoonBitmoonbitLanguage: language metadata for consumers that accept a custom language registration objectcreateMoonbitLanguageRegistration(): returns metadata plus a Shiki-compatible grammar object for tools that prefer in-memory registrationmoonbitAliases: common aliases such asmoonbit,mbt, andmbti
Install
pnpm add moonbit-syntax-highlighterBasic Usage
import {
createMoonbitLanguageRegistration,
moonbitTextMateGrammar,
} from 'moonbit-syntax-highlighter'
const language = createMoonbitLanguageRegistration()
console.log(language.scopeName)
console.log(moonbitTextMateGrammar.scopeName)import { moonbitGrammar } from 'moonbit-syntax-highlighter/content'
console.log(moonbitGrammar.slice(0, 40))import { createHighlighter } from 'shiki'
import { createMoonbitLanguageRegistration } from 'moonbit-syntax-highlighter'
const highlighter = await createHighlighter({
themes: ['github-light'],
langs: [createMoonbitLanguageRegistration()],
})
const html = highlighter.codeToHtml('pub fn main() -> Int {\n return 1\n}', {
lang: 'moonbit',
theme: 'github-light',
})
console.log(html)Intended Consumers
- Shiki-based documentation sites such as VitePress or Astro
- Markdown pipelines that can register external TextMate-style grammars
- Internal tooling that needs a stable MoonBit language metadata entry point
Source and Attribution
The vendored syntax source in syntaxes/moonbit.sublime-syntax is based on the MIT-licensed MoonBit Sublime syntax project by hyrious:
- upstream repo:
https://github.com/hyrious/moonbit-syntax-highlight - upstream file:
MoonBit.sublime-syntax
This package preserves upstream attribution in LICENSE.upstream and is intended to make the grammar easier to consume from documentation tooling.
Current Scope
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.
Local Development
pnpm run check
pnpm run dev
pnpm run pack:checkpnpm run dev uses Node watch mode to rerun the package self-check whenever files change.
pnpm run pack:check builds the tarball locally so you can inspect the exact files that would be published.
