Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork119
An embeddable code editor for the browser 🍯
License
NotificationsYou must be signed in to change notification settings
antonmedv/codejar
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
- Lightweight (2.45 kB only)
- No dependencies
- Preserves indentation on a new line
- Adds closing brackets, quotes
- Indents line with theTab key
- Supportsundo/redo
Install CodeJar 🍯 via npm:
npm i codejar
Create an element and init the CodeJar 🍯:
<divclass="editor"></div><script>letjar=CodeJar(document.querySelector('.editor'),highlight)</script>
Second argument toCodeJar
is a highlighting function (like Prism.js, highlight.js):
consthighlight=(editor:HTMLElement)=>{constcode=editor.textContentcode=code.replace('foo','<span>foo</span>')editor.innerHTML=code}constjar=CodeJar(editor,highlight)
Third argument toCodeJar
is options:
tab: string
replaces "tabs" with given string. Default:\t
.- Note: use css rule
tab-size
to customize size.
- Note: use css rule
indentOn: RegExp
allows auto indent rule to be customized. Default/[({\[]$/
.moveToNewLine: RegExp
checks in extra newline character need to be added. Default/^[)}\]]/
.spellcheck: boolean
enables spellchecking on the editor. Defaultfalse
.catchTab: boolean
catches Tab keypress events and replaces it withtab
string. Default:true
.preserveIdent: boolean
keeps indent levels on new line. Defaulttrue
.addClosing: boolean
automatically adds closing brackets, quotes. Defaulttrue
.history
records history. Defaulttrue
.window
window object. Default:window
.autoclose
objectopen string
characters that triggers the autoclose functionclose string
characters that correspond to the opening ones and close the object.
constoptions={tab:' '.repeat(4),// default is '\t'indentOn:/[(\[]$/,// default is /{$/autoclose:{open:`([{*`,// default is `([{'"`close:`)]}*`// default is `)]}'"`}}constjar=CodeJar(editor,highlight,options)
Updates the code.
jar.updateCode(`let foo = bar`)
Updates the options.
jar.updateOptions({tab:'\t'})
Calls callback on code updates.
jar.onUpdate(code=>{console.log(code)})
Return current code.
letcode=jar.toString()
Saves current cursor position.
letpos=jar.save()
Restore cursor position.
jar.restore(pos)
Saves current editor state to history.
Removes event listeners from editor.
- react-codejar - a React wrapper for CodeJar.
- ngx-codejar - an Angular wrapper for CodeJar.
- codejar-linenumbers - an JS library for line numbers.
About
An embeddable code editor for the browser 🍯
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Sponsor this project
Uh oh!
There was an error while loading.Please reload this page.
Packages0
No packages published