1- <a href =" https://webpod.dev/?from=codejar " ><img src =" https://webpod.dev/img/banner.png " alt =" Webpod - deploy JavaScript apps " width =" 190 " align =" right " ></a >
2-
31<p align =" center " ><a href =" https://medv.io/codejar/ " ><img src =" https://medv.io/assets/codejar.svg " width =" 72 " ></a ></p >
42<h3 align =" center " >CodeJar – an embeddable code editor for the browser</h3 >
53<p align =" center " ><a href =" https://medv.io/codejar/ " ><img src =" https://medv.io/assets/codejar/screenshot.png " width =" 709 " ></a ></p >
97
108## Features
119
12- * Lightweight (** 2 kB** only)
10+ * Lightweight (** 3 kB** only)
1311* Preserves indentation on a new line
1412* Adds closing brackets, quotes
1513* Indents line with the ** Tab** key
@@ -23,33 +21,25 @@ Install CodeJar 🍯 via npm:
2321npm i codejar
2422```
2523
26- CodeJar 🍯   ; can be used via modules:
27-
28- ``` html
29- <script type =" module" >
30- import {CodeJar } from ' https://medv.io/codejar/codejar.js'
31- </script >
32- ```
33-
3424Create an element and init the CodeJar 🍯:
3525
3626``` html
3727<div class =" editor" ></div >
3828<script >
39- let jar = CodeJar (document .querySelector (' .editor' ), hljs . highlightElement )
29+ let jar = CodeJar (document .querySelector (' .editor' ), highlight )
4030 </script >
4131```
4232
43- Second argument to ` CodeJar ` is a highlighting function (in this example [ highlight.js] ( https://highlightjs.org ) ), but any function may be used :
33+ Second argument to ` CodeJar ` is a highlighting function (like Prism.js, highlight.js) :
4434
4535``` ts
4636const highlight = (editor : HTMLElement ) => {
4737 const code = editor .textContent
48- // Do something with code and set html.
38+ code = code . replace ( ' foo ' , ' <span style="color: red">foo</span> ' )
4939 editor .innerHTML = code
5040}
5141
52- let jar = CodeJar (editor , highlight )
42+ const jar = CodeJar (editor , highlight )
5343```
5444
5545Third argument to ` CodeJar ` is options:
@@ -66,29 +56,12 @@ Third argument to `CodeJar` is options:
6656
6757
6858``` js
69- let options = {
59+ const options = {
7060 tab: ' ' .repeat (4 ), // default is '\t'
7161 indentOn: / [(\[ ] $ / , // default is /{$/
7262}
7363
74- let jar = CodeJar (editor, highlight, options)
75- ```
76-
77- Some styles may be applied to our editor to make it better looking:
78-
79- ``` css
80- .editor {
81- border-radius : 6px ;
82- box-shadow : 0 2px 2px 0 rgba (0 , 0 , 0 , 0.14 ), 0 1px 5px 0 rgba (0 , 0 , 0 , 0.12 ), 0 3px 1px -2px rgba (0 , 0 , 0 , 0.2 );
83- font-family : ' Source Code Pro' , monospace ;
84- font-size : 14px ;
85- font-weight : 400 ;
86- height : 340px ;
87- letter-spacing : normal ;
88- line-height : 20px ;
89- padding : 10px ;
90- tab-size : 4 ;
91- }
64+ const jar = CodeJar (editor, highlight, options)
9265```
9366
9467## API
@@ -154,8 +127,8 @@ Removes event listeners from editor.
154127
155128## Related
156129
157- * [ react-codejar] ( https://github.com/guilhermelimak/react-codejar ) - a react wrapper for CodeJar.
158- * [ ngx-codejar] ( https://github.com/julianpoemp/ngx-codejar ) - an angular wrapper for CodeJar.
130+ * [ react-codejar] ( https://github.com/guilhermelimak/react-codejar ) - a React wrapper for CodeJar.
131+ * [ ngx-codejar] ( https://github.com/julianpoemp/ngx-codejar ) - an Angular wrapper for CodeJar.
159132
160133## License
161134
0 commit comments