e-chan1007 / nuxt-monaco-editor

Integrate monaco-editor with Nuxt
https://e-chan1007.github.io/nuxt-monaco-editor
MIT License
114 stars 15 forks source link

Add custom language #36

Closed buksy90 closed 10 months ago

buksy90 commented 10 months ago

Hi, I have defined custom language syntax using https://microsoft.github.io/monaco-editor/monarch.html

How do I configure my monaco to use it please?

buksy90 commented 10 months ago

I found it, here is what I've done

function setupMyLang() {
  // Make sure to use this `useMonaco` over `import * as Monaco from 'monaco-editor';`
  const monaco = useMonaco();
  if(!monaco) return;

  monaco.languages.register({
        id: 'myLang',
    });

  monaco.languages.setMonarchTokensProvider('myLang', {
    defaultToken: 'invalid',
    tokenizer: { ... },
  });
}

// Call this on clientSide once before creating editor
setupMyLang();

// Last thing to do is to use language when creating monaco editor
<MonacoEditor v-model="codeInternal" lang="myLang" />