You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+10-15Lines changed: 10 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,21 +16,17 @@ Unlike other front-end code-editor projects, the simplicity of how `code-input`
16
16
17
17
The `<code-input>` element works like a `<textarea>` and therefore **works in HTML5 forms and supports using the `value` and `placeholder` attributes, as well as the `onchange` event.**
18
18
19
-
<details>
20
-
<summary>
21
-
22
-
## Getting Started With `code-input`
23
-
</summary>
19
+
## 🚀 Getting Started With `code-input` (in 4 simple steps)
24
20
25
21
`code-input` is designed to be **both easy to use and customisable**. Here's how to use it to create syntax-highlighted textareas:
26
22
27
-
### Import `code-input`
23
+
### 1. Import `code-input`
28
24
-**First, import your favourite syntax-highlighter's JS and CSS theme files** to turn editable.
29
25
- Then, import the CSS and JS files of `code-input` from a downloaded release or a CDN. The non-minified files are useful for using during development.
The next step is to set up a `template` to link `code-input` to your syntax-highlighter. If you're using Prism.js or highlight.js, you can use the built-in template, or you can create your own otherwise. In these examples, I am registering the template as `"syntax-highlighted"`, but you can use any template name as long as you are consistent.
56
52
57
53
-*Highlight.js:*
@@ -71,13 +67,13 @@ The next step is to set up a `template` to link `code-input` to your syntax-high
71
67
/* Highlight code in result_element - code is already escaped so it doesn't become HTML */
72
68
},
73
69
true, /* Optional - Is the `pre` element styled as well as the `code` element? Changing this to false uses the code element as the scrollable one rather than the pre element */
74
-
true, /* Optional - This is used for editing code - setting this to true overrides the Tab key and uses it for indentation*/
70
+
true, /* Optional - This is used for editing code - setting this to true sets the `code` element's class to `language-<the code-input's lang attribute>`*/
75
71
false/* Optional - Setting this to true passes the `<code-input>` element as a second argument to the highlight function to be used for getting data- attribute values and using the DOM for the code-input */,
76
72
[] // Array of plugins (see below)
77
73
));
78
74
```
79
75
80
-
### Adding plugins
76
+
### 3. Adding plugins
81
77
[Plugins](./plugins/) allow you to add extra features to a template, like [automatic indentation](plugins/indent.js) or [support for highlight.js's language autodetection](plugins/autodetect.js). To use them, just:
82
78
- Import the plugins' JS files after you have imported `code-input` and before registering the template.
83
79
- Place instances of the plugins in the array of plugins argument when registering, like this:
@@ -102,7 +98,7 @@ The next step is to set up a `template` to link `code-input` to your syntax-high
102
98
103
99
To see a full list of plugins and their functions, please see [plugins/README.md](./plugins/README.md).
104
100
105
-
### Using the component
101
+
### 4. Using the component
106
102
Now that you have registered a template, you can use the custom `<code-input>` element in HTML. If you have more than one template registered, you need to add the template name as the `template` attribute. With the element, using the `lang` attribute will add a `language-{value}` class to the `pre code` block. You can now use HTML attributes and events to make your element as simple or interactive as you like!
107
103
```HTML
108
104
<code-inputlang="HTML"></code-input>
@@ -111,7 +107,6 @@ Now that you have registered a template, you can use the custom `<code-input>` e
If you have any features you would like to add to `code-input`, or have found any bugs, please [open an issue](https://github.com/WebCoder49/code-input/issues) or [fork and submit a pull request](https://github.com/WebCoder49/code-input/fork)! All contributions to this open-source project would be greatly appreciated.
0 commit comments