Skip to content

Commit b94ab1c

Browse files
committed
Add example setup
1 parent 22e0ae5 commit b94ab1c

7 files changed

Lines changed: 180 additions & 6 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
node_modules
22
dist
3+
example/bundle.js*

example/index.html

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<title>CodeMirror MAML</title>
6+
<style>
7+
body {
8+
margin: 0;
9+
font-family: system-ui, sans-serif;
10+
background: #f5f5f5;
11+
}
12+
header {
13+
padding: 12px 20px;
14+
background: #1a1a2e;
15+
color: #fff;
16+
font-size: 14px;
17+
}
18+
header span {
19+
opacity: 0.5;
20+
}
21+
.cm-editor {
22+
height: calc(100vh - 44px);
23+
font-size: 14px;
24+
}
25+
</style>
26+
</head>
27+
<body>
28+
<header>MAML <span>— CodeMirror 6</span></header>
29+
<div id="editor"></div>
30+
<script src="bundle.js"></script>
31+
</body>
32+
</html>

example/main.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import {EditorView, basicSetup} from "codemirror"
2+
import {maml} from "../src/index.ts"
3+
4+
const doc = `# MAML example
5+
{
6+
project: "MAML"
7+
version: 1
8+
active: true
9+
legacy: null
10+
11+
tags: [
12+
"minimal"
13+
"readable"
14+
"fast"
15+
]
16+
17+
author: {
18+
name: "Anton Medvedev"
19+
url: "https://medv.io"
20+
}
21+
22+
# Nested objects in array
23+
examples: [
24+
{
25+
name: "hello"
26+
score: 3.14
27+
negative: -42
28+
exponent: 1e10
29+
}
30+
{
31+
name: "world"
32+
score: 2.718
33+
}
34+
]
35+
36+
description: """
37+
This is a raw multiline string.
38+
It preserves "quotes" and \\escapes as-is.
39+
No special handling needed.
40+
"""
41+
42+
"quoted key": "value with \\"escapes\\" and \\n newlines"
43+
44+
# Trailing commas are fine
45+
colors: [
46+
"red",
47+
"green",
48+
"blue",
49+
]
50+
}
51+
`
52+
53+
new EditorView({
54+
doc,
55+
extensions: [basicSetup, maml()],
56+
parent: document.getElementById("editor"),
57+
})

package-lock.json

Lines changed: 67 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
],
1919
"scripts": {
2020
"build": "rollup -c",
21+
"example": "rollup -c rollup.example.js && open example/index.html",
2122
"test": "vitest run"
2223
},
2324
"dependencies": {
@@ -30,6 +31,7 @@
3031
"@lezer/generator": "^1.7.0",
3132
"@rollup/plugin-node-resolve": "^15.0.0",
3233
"@rollup/plugin-typescript": "^12.0.0",
34+
"codemirror": "^6.0.2",
3335
"rollup": "^4.0.0",
3436
"tslib": "^2.8.1",
3537
"typescript": "^5.0.0",

rollup.example.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import {lezer} from "@lezer/generator/rollup"
2+
import {nodeResolve} from "@rollup/plugin-node-resolve"
3+
import typescript from "@rollup/plugin-typescript"
4+
5+
export default {
6+
input: "example/main.js",
7+
output: {
8+
file: "example/bundle.js",
9+
format: "iife",
10+
sourcemap: true,
11+
},
12+
plugins: [
13+
nodeResolve(),
14+
lezer(),
15+
typescript({
16+
declaration: false,
17+
declarationDir: undefined,
18+
outDir: "example",
19+
}),
20+
]
21+
}

vitest.config.ts

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)