Skip to content

How to add customized language? #89

Open
@yjl9903

Description

@yjl9903

I want to add my customized language, and I use the demo in Monaco Editor Playground. I bind the event editorWillMount, and use the monaco object to add customized language, but its highlight does not work.

And I also see this issue, he add languages in editorDidMount. I tried it, but it does not work either.

<template>
  <MonacoEditor class="editor" v-model="code" language="mySpecialLanguage" @editorWillMount="editorWillMount" />
</template>

<script>
import MonacoEditor from 'vue-monaco'

export default {
  components: {
    MonacoEditor
  },

  data() {
    return {
      code: '[Sun Mar 7 16:02:00 2004] [notice] Apache/1.3.29 (Unix) configured -- resuming normal operations'
    }
  },

  methods: {
    editorWillMount(monaco) {
      // Register a new language
      monaco.languages.register({ id: 'mySpecialLanguage' });

      // Register a tokens provider for the language
      monaco.languages.setMonarchTokensProvider('mySpecialLanguage', {
        tokenizer: {
          root: [
            [/\[error.*/, "custom-error"],
            [/\[notice.*/, "custom-notice"],
            [/\[info.*/, "custom-info"],
            [/\[[a-zA-Z 0-9:]+\]/, "custom-date"],
          ]
        }
      });
    }
  }
}
</script>

<style>
.editor {
  width: 600px;
  height: 800px;
}
</style>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions