💡 Do you just want to get a quick editor working? We suggest the Indent and Prism Line Numbers plugins.
Lots of plugins are very customisable - please see the JavaScript files for parameters and if you want more features let us know via GitHub Issues.
Display a popup under the caret using the text in the code-input element. This works well with autocomplete suggestions.
Files: autocomplete.js / autocomplete.css
Autodetect the language live and change the lang attribute using the syntax highlighter's autodetect capabilities. Works with highlight.js.
Files: autodetect.js
Debounce the update and highlighting function (What is Debouncing?)
Files: debounce-update.js
Adds indentation using the Tab key, and auto-indents after a newline, as well as making it possible to indent/unindent multiple lines using Tab/Shift+Tab. Supports tab characters and custom numbers of spaces as indentation.
Files: indent.js
Allows code-input elements to be used with the Prism.js line-numbers plugin, as long as the code-input element or a parent element of it has the CSS class line-numbers. Prism.js Plugin Docs
Files: prism-line-numbers.css (NO JS FILE)
Render special characters and control characters as a symbol with their hex code.
Files: special-chars.js / special-chars.css
Plugins allow you to add extra features to a template, like automatic indentation or support for highlight.js's language autodetection. To use them, just:
- Import the plugins' JS/CSS files (there may only be one of these; import all of the files that exist) after you have imported
code-inputand before registering the template. - If a JavaScript file is present, Place an instance of each plugin in the array of plugins argument when registering, like this:
<script src="code-input.js"></script>
<!--...-->
<script src="plugins/autodetect.js"></script>
<script src="plugins/indent.js"></script>
<!--...-->
<script>
codeInput.registerTemplate("syntax-highlighted",
codeInput.templates.hljs(
hljs,
[
new codeInput.plugins.Autodetect(),
new codeInput.plugins.Indent(true, 2) // 2 spaces indentation
]
)
);
</script>