Skip to content

Commit

Permalink
Initial add
Browse files Browse the repository at this point in the history
  • Loading branch information
marijnh committed Jan 21, 2024
0 parents commit 4dc3065
Show file tree
Hide file tree
Showing 8 changed files with 207 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/dispatch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Trigger CI
on: push

jobs:
build:
name: Dispatch to main repo
runs-on: ubuntu-latest
steps:
- name: Emit repository_dispatch
uses: mvasigh/dispatch-action@main
with:
# You should create a personal access token and store it in your repository
token: ${{ secrets.DISPATCH_AUTH }}
repo: dev
owner: codemirror
event_type: push
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/node_modules
package-lock.json
/dist
/test/*.js
/test/*.d.ts
/test/*.d.ts.map
.tern-*
6 changes: 6 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/src
/test
/node_modules
.tern-*
rollup.config.js
tsconfig.json
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (C) 2024 by Marijn Haverbeke <marijn@haverbeke.berlin> and others

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<!-- NOTE: README.md is generated from src/README.md -->

# @codemirror/lang-yaml [![NPM version](https://img.shields.io/npm/v/@codemirror/lang-yaml.svg)](https://www.npmjs.org/package/@codemirror/lang-yaml)

[ [**WEBSITE**](https://codemirror.net/) | [**ISSUES**](https://github.com/codemirror/dev/issues) | [**FORUM**](https://discuss.codemirror.net/c/next/) | [**CHANGELOG**](https://github.com/codemirror/lang-yaml/blob/main/CHANGELOG.md) ]

This package implements YAML language support for the
[CodeMirror](https://codemirror.net/) code editor.

The [project page](https://codemirror.net/) has more information, a
number of [examples](https://codemirror.net/examples/) and the
[documentation](https://codemirror.net/docs/).

This code is released under an
[MIT license](https://github.com/codemirror/lang-yaml/tree/main/LICENSE).

We aim to be an inclusive, welcoming community. To make that explicit,
we have a [code of
conduct](http://contributor-covenant.org/version/1/1/0/) that applies
to communication around the project.

## API Reference

<dl>
<dt id="user-content-yaml">
<code><strong><a href="#user-content-yaml">yaml</a></strong>() → <a href="https://codemirror.net/docs/ref#language.LanguageSupport">LanguageSupport</a></code></dt>

<dd><p>Language support for YAML.</p>
</dd>
<dt id="user-content-yamllanguage">
<code><strong><a href="#user-content-yamllanguage">yamlLanguage</a></strong>: <a href="https://codemirror.net/docs/ref#language.LRLanguage">LRLanguage</a></code></dt>

<dd><p>A language provider based on the <a href="https://github.com/lezer-parser/yaml">Lezer YAML
parser</a>, extended with
highlighting and indentation information.</p>
</dd>
</dl>
42 changes: 42 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"name": "@codemirror/lang-yaml",
"version": "6.2.1",
"description": "YAML language support for the CodeMirror code editor",
"scripts": {
"test": "cm-runtests",
"prepare": "cm-buildhelper src/yaml.ts"
},
"keywords": [
"editor",
"code"
],
"author": {
"name": "Marijn Haverbeke",
"email": "marijn@haverbeke.berlin",
"url": "http://marijnhaverbeke.nl"
},
"type": "module",
"main": "dist/index.cjs",
"exports": {
"import": "./dist/index.js",
"require": "./dist/index.cjs"
},
"types": "dist/index.d.ts",
"module": "dist/index.js",
"sideEffects": false,
"license": "MIT",
"dependencies": {
"@codemirror/autocomplete": "^6.0.0",
"@codemirror/language": "^6.0.0",
"@codemirror/state": "^6.0.0",
"@lezer/common": "^1.0.2",
"@lezer/yaml": "^1.0.0"
},
"devDependencies": {
"@codemirror/buildhelper": "^1.0.0"
},
"repository": {
"type": "git",
"url": "https://github.com/codemirror/lang-yaml.git"
}
}
26 changes: 26 additions & 0 deletions src/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!-- NOTE: README.md is generated from src/README.md -->

# @codemirror/lang-yaml [![NPM version](https://img.shields.io/npm/v/@codemirror/lang-yaml.svg)](https://www.npmjs.org/package/@codemirror/lang-yaml)

[ [**WEBSITE**](https://codemirror.net/) | [**ISSUES**](https://github.com/codemirror/dev/issues) | [**FORUM**](https://discuss.codemirror.net/c/next/) | [**CHANGELOG**](https://github.com/codemirror/lang-yaml/blob/main/CHANGELOG.md) ]

This package implements YAML language support for the
[CodeMirror](https://codemirror.net/) code editor.

The [project page](https://codemirror.net/) has more information, a
number of [examples](https://codemirror.net/examples/) and the
[documentation](https://codemirror.net/docs/).

This code is released under an
[MIT license](https://github.com/codemirror/lang-yaml/tree/main/LICENSE).

We aim to be an inclusive, welcoming community. To make that explicit,
we have a [code of
conduct](http://contributor-covenant.org/version/1/1/0/) that applies
to communication around the project.

## API Reference

@yaml

@yamlLanguage
52 changes: 52 additions & 0 deletions src/yaml.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import {parser} from "@lezer/yaml"
import {LRLanguage, delimitedIndent, indentNodeProp,
foldNodeProp, foldInside, LanguageSupport} from "@codemirror/language"
import {SyntaxNode} from "@lezer/common"

/// A language provider based on the [Lezer YAML
/// parser](https://github.com/lezer-parser/yaml), extended with
/// highlighting and indentation information.
export const yamlLanguage = LRLanguage.define({
name: "yaml",
parser: parser.configure({
props: [
indentNodeProp.add({
Stream: cx => {
for (let before = cx.node.resolve(cx.pos, -1) as SyntaxNode | null;
before && before.to >= cx.pos; before = before.parent) {
if (before.name == "BlockLiteralContent" && before.from < before.to)
return cx.baseIndentFor(before)
if (before.name == "BlockLiteral")
return cx.baseIndentFor(before) + cx.unit
if (before.name == "BlockSequence" || before.name == "BlockMapping")
return cx.column(before.from, 1)
if (before.name == "QuotedLiteral")
return null
if (before.name == "Literal") {
let col = cx.column(before.from, 1)
if (col == cx.lineIndent(before.from, 1)) return col // Start on own line
if (before.to > cx.pos) return null
}
}
return null
},
FlowMapping: delimitedIndent({closing: "}"}),
FlowSequence: delimitedIndent({closing: "]"}),
}),
foldNodeProp.add({
"FlowMapping FlowSequence": foldInside,
"BlockSequence BlockMapping BlockLiteral":
(node, state) => ({from: state.doc.lineAt(node.from).to, to: node.to})
})
]
}),
languageData: {
commentTokens: {line: "#"},
indentOnInput: /^\s*[\]\}]$/,
}
})

/// Language support for YAML.
export function yaml() {
return new LanguageSupport(yamlLanguage)
}

0 comments on commit 4dc3065

Please sign in to comment.