{"id":21977353,"url":"https://github.com/zmitry/light-code-editor","last_synced_at":"2025-04-28T16:42:23.006Z","repository":{"id":110953750,"uuid":"156610682","full_name":"zmitry/light-code-editor","owner":"zmitry","description":"superlight 1kb code editor with syntax highlight","archived":false,"fork":false,"pushed_at":"2018-11-07T22:08:36.000Z","size":632,"stargazers_count":9,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-11-24T17:02:54.384Z","etag":null,"topics":["editor","html","wisywyg"],"latest_commit_sha":null,"homepage":"https://zmitry.github.io/light-code-editor","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zmitry.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-11-07T21:31:03.000Z","updated_at":"2024-08-01T04:00:47.000Z","dependencies_parsed_at":null,"dependency_job_id":"6fe847c7-3624-4ca7-9dd5-d0e75228ca89","html_url":"https://github.com/zmitry/light-code-editor","commit_stats":null,"previous_names":["zhdmitry/light-code-editor"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zmitry%2Flight-code-editor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zmitry%2Flight-code-editor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zmitry%2Flight-code-editor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zmitry%2Flight-code-editor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zmitry","download_url":"https://codeload.github.com/zmitry/light-code-editor/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227163414,"owners_count":17740336,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["editor","html","wisywyg"],"created_at":"2024-11-29T16:14:24.949Z","updated_at":"2024-11-29T16:14:25.550Z","avatar_url":"https://github.com/zmitry.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Lightweight Decorator for Textareas\n\n```\nyarn add light-code-editor\n# or\nnpm install light-code-editor\n```\n\n# How to use [codesandbox](https://codesandbox.io/s/k91x8593w3)\n\n1. include styles \"light-code-editor/styles.css\"\n2. create parser\n\n```js\nconst genericParser = new Parser({\n  whitespace: /\\s+/,\n  comment: /\\/\\*([^\\*]|\\*[^\\/])*(\\*\\/?)?|(\\/\\/|#)[^\\r\\n]*/,\n  string: /\"(\\\\.|[^\"\\r\\n])*\"?|'(\\\\.|[^'\\r\\n])*'?/,\n  number: /0x[\\dA-Fa-f]+|-?(\\d+\\.?\\d*|\\.\\d+)/,\n  keyword: /(and|as|case|catch|class|const|def|delete|die|do|else|elseif|esac|exit|extends|false|fi|finally|for|foreach|function|global|if|new|null|or|private|protected|public|published|resource|return|self|static|struct|switch|then|this|throw|true|try|var|void|while|xor)(?!\\w|=)/,\n  variable: /[\\$\\%\\@](\\-\u003e|\\w)+(?!\\w)|\\${\\w*}?/,\n  define: /[$A-Z_a-z0-9]+/,\n  op: /[\\+\\-\\*\\/=\u003c\u003e!]=?|[\\(\\)\\{\\}\\[\\]\\.\\|]/,\n  other: /\\S+/\n});\n```\n\n3. style your items\n\n```css\n.ltd .comment {\n  color: red;\n}\n\n.ltd .keyword {\n  color: black;\n}\n```\n\n```js\nvar textarea = $(\"codeArea\");\ntextarea.value = \"\u003c!DOCTYPE html\u003e\\n\u003chtml\u003e\\n\\t\" + \"\\n\u003c/html\u003e\";\ndecorator = new TextareaDecorator(textarea, parser);\n```\n\n```js\nvar textarea = $(\"codeArea\");\ntextarea.value = \"\u003c!DOCTYPE html\u003e\\n\u003chtml\u003e\\n\\t\" + \"\\n\u003c/html\u003e\";\ndecorator = new TextareaDecorator(textarea, parser);\nbindKey(textarea, {\n  \"Ctrl-1\": e =\u003e {\n    insertAtCursor(\"your  superb text\", el);\n    decorator.update();\n  },\n  \"Shift-Ctrl-2\": e =\u003e {\n    alert(\"hello\");\n  }\n});\n```\n\nsee detailed examples in stories\n\n## In browser live syntax highlighting\n\n\u003cpre\u003e\n\u0026lt;!-- normal textarea fall-back, add an id to access it from javascript --\u0026gt;\n\u0026lt;textarea id='codeArea' class='ldt'\u0026gt;\u0026lt;/textarea\u0026gt;\n\u0026lt;noscript\u0026gt;Please enable JavaScript to allow syntax highlighting.\u0026lt;/noscript\u0026gt;\n\u003c/pre\u003e\n\n### JS\n\n\u003cpre\u003e\n// create a parser with a mapping of css classes to regular expressions\n// everything must be matched, so 'whitespace' and 'other' are commonly included\nvar parser = new Parser(\n  { whitespace: /\\s+/,\n    comment: /\\/\\/[^\\r\\n]*/,\n    other: /\\S+/ } );\n// get the textarea with $ (document.getElementById)\n// pass the textarea element and parser to LDT\nvar ldt = new TextareaDecorator( $('codeArea'), parser );\n\u003c/pre\u003e\n\n### CSS\n\n\u003cpre\u003e\n/* editor styles */\n.ldt {\n\twidth: 400px;\n\theight: 300px;\n\tborder: 1px solid black;\n}\n/* styles applied to comment tokens */\n.ldt .comment {\n    color: silver;\n}\n\u003c/pre\u003e\n\n## API\n\n### TextareaDecorator\n\n- `new TextareaDecorator( textarea, parser )` Converts a HTML `textarea` element into an auto highlighting TextareaDecorator. `parser` is used to determine how to subdivide and style the content. `parser` can be any object which defines the `tokenize` and `identify` methods as described in the Parser API below.\n- `.input` The input layer of the LDT, a `textarea` element.\n- `.output` The output layer of the LDT, a `pre` element.\n- `.update()` Updates the highlighting of the LDT. It is automatically called on user input. You shouldn't need to call this unless you programmatically changed the contents of the `textarea`.\n\n### Parser\n\n- `new Parser( [rules], [i] )` Creates a parser. `rules` is an object whose keys are CSS classes and values are the regular expressions which match each token. `i` is a boolean which determines if the matching is case insensitive, it defaults to `false`.\n- `.add( rules )` Adds a mapping of CSS class names to regular expressions.\n- `.tokenize( string )` Splits `string` into an array of tokens as defined by `.rules`.\n- `.identify( string )` Finds the CSS class name associated with the token `string`.\n\n### Keybinder\n\nThis is a singleton, you do not need to instantiate this object.\n\n- `.bindKey( element, [keymap] )` Adds Keybinder methods to `element`, optionally setting the element's `keymap`.\n\n### SelectHelper\n\nThis is a singleton, you do not need to instantiate this object.\n\n- `.add( element )` Adds SelectHelper methods to `element`.\n- `element.insertAtCursor( string )` Inserts `string` into the `element` before the current cursor position.\n\n### Contributions\nOpened to contributions, it would be nice to have some predefined parsers and intergrations for react, vue, etc\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzmitry%2Flight-code-editor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzmitry%2Flight-code-editor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzmitry%2Flight-code-editor/lists"}