No description
Find a file
Remco Haszing ec4de1f50c
Convert from yarn to npm
Npm 7 also supports workspaces, but doesn’t require the workspace root to be
private. This means the examples can be workspaces within the project, so the
entire project can be handled as one mono repository with a single lock file and
`node_modules` directory.

Also the readme has been updated with usage instructions.
2021-04-28 17:47:00 +02:00
.github/workflows Convert from yarn to npm 2021-04-28 17:47:00 +02:00
.husky Convert from yarn to npm 2021-04-28 17:47:00 +02:00
.vscode Remove unused dependencies 2021-03-25 17:40:16 +01:00
examples Convert from yarn to npm 2021-04-28 17:47:00 +02:00
scripts Use monaco-editor/esm/vs/editor/editor.api 2021-04-22 20:00:34 +02:00
src Use monaco-editor/esm/vs/editor/editor.api 2021-04-22 20:00:34 +02:00
.editorconfig build: migrate latest json language service implementation 2018-11-23 10:04:33 +08:00
.gitignore Gitignore built packages 2021-03-25 18:01:10 +01:00
.prettierignore Apply prettier on all committed files 2021-03-25 17:59:58 +01:00
LICENSE.md Apply prettier on all committed files 2021-03-25 17:59:58 +01:00
package-lock.json Convert from yarn to npm 2021-04-28 17:47:00 +02:00
package.json Convert from yarn to npm 2021-04-28 17:47:00 +02:00
README.md Convert from yarn to npm 2021-04-28 17:47:00 +02:00
test-demo.png chore: align with pengx17/master branch 2018-10-25 10:12:07 +08:00
tsconfig.esm.json Convert from yarn to npm 2021-04-28 17:47:00 +02:00
tsconfig.json Convert from yarn to npm 2021-04-28 17:47:00 +02:00

Monaco YAML

YAML language plugin for the Monaco Editor. It provides the following features when editing YAML files:

  • Code completion, based on JSON schemas or by looking at similar objects in the same file
  • Hovers, based on JSON schemas
  • Validation: Syntax errors and schema validation
  • Formatting
  • Document Symbols
  • Syntax highlighting
  • Automatically load remote schema files (by enabling DiagnosticsOptions.enableSchemaRequest)

Schemas can also be provided by configuration. See here for the API that the JSON plugin offers to configure the JSON language support.

Installation

npm install monaco-yaml

Usage

Import monaco-yaml and configure it before an editor instance is created.

import { editor, languages, Uri } from 'monaco-editor';
import 'monaco-yaml';

// The uri is used for the schema file match.
const modelUri = Uri.parse('a://b/foo.yaml');

languages.yaml.yamlDefaults.setDiagnosticsOptions({
  enableSchemaRequest: true,
  hover: true,
  completion: true,
  validate: true,
  format: true,
  schemas: [
    {
      uri: 'http://myserver/foo-schema.json', // id of the first schema
      fileMatch: [modelUri.toString()], // associate with our model
      schema: {
        type: 'object',
        properties: {
          p1: {
            enum: ['v1', 'v2'],
          },
          p2: {
            $ref: 'http://myserver/bar-schema.json', // reference the second schema
          },
        },
      },
    },
    {
      uri: 'http://myserver/bar-schema.json', // id of the first schema
      schema: {
        type: 'object',
        properties: {
          q1: {
            enum: ['x1', 'x2'],
          },
        },
      },
    },
  ],
});

editor.create(document.createElement('editor'), {
  // monaco-yaml features should just work if the editor language is set to 'yaml'.
  language: 'yaml',
  model: editor.createModel('p1: \n', 'yaml', modelUri),
});

Also make sure to register the service worker. See the examples directory for full fledged examples.

Development

  • git clone https://github.com/pengx17/monaco-yaml
  • cd monaco-yaml
  • npm ci

A running example: demo-image

Credits

License

MIT