GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - antonmedv/codejar: An embeddable code editor for the browser 🍯

BranchesTags
Open more actions menu

Latest commit

 

History

131 Commits
131 Commits

Folders and files

NameName
Last commit message
Last commit date
.github/workflows
.github/workflows
 
 
demo
demo
 
 
src
src
 
 
test
test
 
 
.gitignore
.gitignore
 
 
.oxfmtrc.json
.oxfmtrc.json
 
 
.oxlintrc.json
.oxlintrc.json
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
RELEASE.md
RELEASE.md
 
 
package-lock.json
package-lock.json
 
 
package.json
package.json
 
 
tsconfig.build.json
tsconfig.build.json
 
 
tsconfig.json
tsconfig.json
 
 
vite.config.ts
vite.config.ts
 
 
vitest.config.ts
vitest.config.ts
 
 

Repository files navigation

CodeJar

CodeJar – an embeddable code editor for the browser

Demo

A tiny (~3 kB) editor with no dependencies. Instead of a hidden <textarea> over highlighted code, CodeJar makes the highlighted element itself contenteditable, so you type directly into it. Bring your own highlighter.

npm i codejar
import { CodeJar } from 'codejar'
import Prism from 'prismjs'

const jar = CodeJar(document.querySelector('.editor'), (editor) => {
  editor.innerHTML = Prism.highlight(
    editor.textContent,
    Prism.languages.js,
    'js',
  )
})

Options

Passed as the third argument:

  • tab — string inserted on Tab. Default '\t'.
  • indentOn — indent the new line if the text before the caret matches. Default /[({[]$/.
  • moveToNewLine — move the text after the caret to its own line if it matches. Default /^[)}\]]/.
  • spellcheck — default false.
  • catchTab — handle Tab and Shift+Tab. Default true.
  • preserveIdent — keep indentation on a new line. Default true.
  • addClosing — auto-close brackets and quotes. Default true.
  • autoclose — { open, close } pairs to auto-close. Default { open: `([{'"`, close: `)]}'"` }.
  • history — undo/redo. Default true.
  • window — window to use, e.g. for iframes.

API

  • updateCode(code, callOnUpdate = true) — set the code.
  • updateOptions(options) — change options.
  • onUpdate(callback) — called with the code on every change.
  • toString() — get the code.
  • save() / restore(pos) — save and restore the caret or selection.
  • recordHistory() — push the current state onto the undo stack.
  • destroy() — remove event listeners.

License

MIT

About

An embeddable code editor for the browser 🍯

antonmedv.github.io/codejar/

Topics

code-editor

Resources

Readme
MIT license
Activity

Stars

2.0k stars

Watchers

17 watching

Forks

126 forks
Report repository

Releases

Sponsor this project

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.