Skip to content

Commit

Permalink
Merge pull request #4340 from jeclrsg/feat-codemirror-yaml
Browse files Browse the repository at this point in the history
feat: add YAML support to codemirror
  • Loading branch information
GordonSmith authored Feb 5, 2025
2 parents 4c74241 + 428447e commit 1dfa8fb
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
22 changes: 22 additions & 0 deletions packages/codemirror/src/YAMLEditor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Editor } from "./Editor.ts";

export class YAMLEditor extends Editor {
options(): any {
return {
...super.options(),
mode: "text/x-yaml",
foldGutter: true,
gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"]
};
}

yaml(): string;
yaml(_: string): this;
yaml(_?: string): string | this {
if (!arguments.length) return this.text();
this.text(_);
return this;
}

}
YAMLEditor.prototype._class += " codemirror_YAMLEditor";
1 change: 1 addition & 0 deletions packages/codemirror/src/codemirror-shim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import "codemirror/mode/htmlmixed/htmlmixed.js";
import "codemirror/mode/javascript/javascript.js";
import "codemirror/mode/xml/xml.js";
import "codemirror/mode/sql/sql.js";
import "codemirror/mode/yaml/yaml.js";
import "./mode/dot/dot.ts";
import "./mode/markdown/markdown.ts";

Expand Down
1 change: 1 addition & 0 deletions packages/codemirror/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ export * from "./MarkdownEditor.ts";
export * from "./ObservableMarkdownEditor.ts";
export * from "./XMLEditor.ts";
export * from "./SQLEditor.ts";
export * from "./YAMLEditor.ts";
3 changes: 2 additions & 1 deletion packages/codemirror/tests/codemirror.browser.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as codemirror from "@hpcc-js/codemirror";
import { CSSEditor, DOTEditor, Editor, ECLEditor, HTMLEditor, JSEditor, JSONEditor, MarkdownEditor, ObservableMarkdownEditor, SQLEditor, XMLEditor } from "@hpcc-js/codemirror";
import { CSSEditor, DOTEditor, Editor, ECLEditor, HTMLEditor, JSEditor, JSONEditor, MarkdownEditor, ObservableMarkdownEditor, SQLEditor, XMLEditor, YAMLEditor } from "@hpcc-js/codemirror";
import { Class, HTMLWidget, SVGWidget } from "@hpcc-js/common";
import { describe, it, expect } from "vitest";
import { classDef, renderMedium } from "../../common/tests/index.ts";
Expand Down Expand Up @@ -30,6 +30,7 @@ describe("@hpcc-js/codemirror", () => {
case ObservableMarkdownEditor:
case SQLEditor:
case XMLEditor:
case YAMLEditor:
case ECLEditor:
renderMedium(new item.prototype.constructor());
break;
Expand Down

0 comments on commit 1dfa8fb

Please sign in to comment.