Coder Social home page Coder Social logo

monaco-textmate-languages's Introduction

monaco-textmate with grammars for most languages

See grammars/ for list of all the languages this package ships with

This package exposes LanguageRegistry class which has sweet lookup functions for language grammars.

You can get Grammar/Tokenizer either by language ID or file extension or even MIME type.

Not all grammars have been "registered/activated" for use due to lack of time, so PR's would be appreciated. To "register/activate" a language, every directory in grammars/ must have atleast one [lang-ext].config.json file that looks like this:

{
    "id": "typescript",
    "scopeName": "source.ts",
    "extensions": [".ts"],
    "mimeType": ["application/typescript"]
}

Usage

npm i monaco-textmate-languages

You must install all the peer dependencies yourself

import { LanguageRegistry } from 'monaco-textmate-languages'

const langRegistry = new LanguageRegistry({
    basePath: 'node_modules/monaco-textmate-languages',
    textFetcher: (uri) => (await fetch(uri)).text(),
    // `jsonFetcher` also works (you must provide either of those)
    // jsonFetcher: (uri) => (await fetch(uri)).json(),
})

langRegistry.getLanguageGrammarByExtension('.tsx')
    .then(grammar => {
        const tokens = grammar.tokenizeLine(`class App extends Component {}`)
        // ...
    })

License

MIT

monaco-textmate-languages's People

Contributors

zikaari avatar andrewsverdrup avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.