Skip to content

b-goodman/code-edit

Repository files navigation

code-edit

A custom element encapsulating a CodeMirror instance.

Install

npm install @bgoodman/code-edit

yarn add @bgoodman/code-edit

Usage

    <script type="module" src="./dist/index.js"></script>

    <code-edit></code-edit>

Attributes

mode

Specify code type using a language mode. Options include:

  • "htmlmixed" - default (html/css/js)
  • "javascript"
  • "typescript"
  • "markdown"

storage-key

If set, allows the editors value to persist accross sessions using window.localStorage. Data is stored as key ${window.location.href}-${this.storageKey}. If unset, the editor's value will reset each time the component loads.

Methods

Get the current editor content. You can pass it an optional argument to specify the string to be used to separate lines (defaults to "\n").

getValue(seperator?: string): Promise<string>

Set the editor content.

setValue(code: string): Promise<void>

About

A custom element encapsulating a CodeMirror instance.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published