Skip to content

Commit 42bd0c7

Browse files
committed
Create initial complete docs; remove old param fom d.ts
1 parent 5c29801 commit 42bd0c7

File tree

20 files changed

+385
-195
lines changed

20 files changed

+385
-195
lines changed

code-input.d.ts

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -301,11 +301,10 @@ export class Template {
301301
* @param {boolean} preElementStyled - is the `<pre>` element CSS-styled (if so set to true), or the `<code>` element (false)?
302302
* @param {boolean} isCode - is this for writing code? If true, the code-input's lang HTML attribute can be used, and the `<code>` element will be given the class name 'language-[lang attribute's value]'.
303303
* @param {false} includeCodeInputInHighlightFunc - Setting this to true passes the `<code-input>` element as a second argument to the highlight function.
304-
* @param {boolean} autoDisableDuplicateSearching - Leaving this as true uses code-input's default fix for preventing duplicate results in Ctrl+F searching from the input and result elements, and setting this to false indicates your highlighting function implements its own fix. The default fix works by moving text content from elements to CSS `::before` pseudo-elements after highlighting.
305304
* @param {codeInput.Plugin[]} plugins - An array of plugin objects to add extra features - see `codeInput.Plugin`
306305
* @returns template object
307306
*/
308-
constructor(highlight?: (codeElement: HTMLElement) => void, preElementStyled?: boolean, isCode?: boolean, includeCodeInputInHighlightFunc?: false, autoDisableDuplicateSearching?: boolean, plugins?: Plugin[])
307+
constructor(highlight?: (codeElement: HTMLElement) => void, preElementStyled?: boolean, isCode?: boolean, includeCodeInputInHighlightFunc?: false, plugins?: Plugin[])
309308
/**
310309
* **When `includeCodeInputInHighlightFunc` is `true`, `highlight` takes two parameters: the `<pre><code>` element, and the `<code-input>` element.**
311310
*
@@ -315,25 +314,15 @@ export class Template {
315314
* @param {boolean} preElementStyled - is the `<pre>` element CSS-styled (if so set to true), or the `<code>` element (false)?
316315
* @param {boolean} isCode - is this for writing code? If true, the code-input's lang HTML attribute can be used, and the `<code>` element will be given the class name 'language-[lang attribute's value]'.
317316
* @param {true} includeCodeInputInHighlightFunc - Setting this to true passes the `<code-input>` element as a second argument to the highlight function.
318-
* @param {boolean} autoDisableDuplicateSearching - Leaving this as true uses code-input's default fix for preventing duplicate results in Ctrl+F searching from the input and result elements, and setting this to false indicates your highlighting function implements its own fix. The default fix works by moving text content from elements to CSS `::before` pseudo-elements after highlighting.
319317
* @param {codeInput.Plugin[]} plugins - An array of plugin objects to add extra features - see `codeInput.Plugin`
320318
* @returns template object
321319
*/
322-
constructor(highlight?: (codeElement: HTMLElement, codeInput: CodeInput) => void, preElementStyled?: boolean, isCode?: boolean, includeCodeInputInHighlightFunc?: true, autoDisableDuplicateSearching?: boolean, plugins?: Plugin[])
320+
constructor(highlight?: (codeElement: HTMLElement, codeInput: CodeInput) => void, preElementStyled?: boolean, isCode?: boolean, includeCodeInputInHighlightFunc?: true, plugins?: Plugin[])
323321
highlight: Function
324322
preElementStyled: boolean
325323
isCode: boolean
326324
includeCodeInputInHighlightFunc: boolean
327-
autoDisableDuplicateSearching: boolean
328-
plugins: Plugin[]
329-
/**
330-
* @deprecated Please give a value for the `autoDisableDuplicateSearching` parameter.
331-
*/
332-
constructor(highlight?: (code: HTMLElement) => void, preElementStyled?: boolean, isCode?: boolean, includeCodeInputInHighlightFunc?: false, plugins?: Plugin[])
333-
/**
334-
* @deprecated Please give a value for the `autoDisableDuplicateSearching` parameter.
335-
*/
336-
constructor(highlight?: (code: HTMLElement, codeInput: CodeInput) => void, preElementStyled?: boolean, isCode?: boolean, includeCodeInputInHighlightFunc?: true, plugins?: Plugin[])
325+
plugins: Plugin[]
337326
}
338327

339328
// ESM-SUPPORT-START-NAMESPACE-2 Do not (re)move this - it's needed for ESM generation

docs/_index.md

Lines changed: 66 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ title = 'Flexible Syntax Highlighted Editable Textareas'
77
Aiming to be [more <mark>flexible</mark>, <mark>lightweight</mark>,
88
<mark>modular</mark>, <mark>progressively enhanced</mark> and
99
<mark>standards-based</mark></a> than the alternatives](#features), we support
10-
HTML forms, the `<textarea>` JavaScript interface, more languages and
10+
[HTML forms](interface/forms), the [`<textarea>` JavaScript interface](interface/js), more languages and
1111
more use cases.
1212

1313
## Get Started with a Demo
@@ -16,7 +16,7 @@ more use cases.
1616

1717
### Demos
1818

19-
#### Basic Prism.js Code Editor {#demo-preset-basic}
19+
#### Basic Prism.js Code Editor {#playground-preset-basic}
2020

2121
```
2222
<!DOCTYPE html>
@@ -47,7 +47,7 @@ console.log("Hello, World!");</textarea></code-input>
4747

4848
### Tutorials by Example
4949

50-
#### Prism.js Code Editor (use **with vanilla HTML here** or [with ECMAScript Modules/Vue/Nuxt](/frameworks/prism)) {#demo-preset-prism}
50+
#### Prism.js Code Editor (use **with vanilla HTML here** or [with ECMAScript Modules/Vue/Nuxt](frameworks/prism)) {#playground-preset-prism}
5151

5252
```
5353
<!DOCTYPE html>
@@ -103,7 +103,7 @@ console.log("Hello, World!");</textarea></code-input>
103103
</html>
104104
```
105105

106-
#### highlight.js Code Editor (use **with vanilla HTML here** or [with ECMAScript Modules/Vue/Nuxt](frameworks/hljs)) {#demo-preset-hljs}
106+
#### highlight.js Code Editor (use **with vanilla HTML here** or [with ECMAScript Modules/Vue/Nuxt](frameworks/hljs)) {#playground-preset-hljs}
107107

108108
```
109109
<!DOCTYPE html>
@@ -160,14 +160,71 @@ console.log("Hello, World!");</textarea></code-input>
160160
</html>
161161
```
162162

163-
#### Editor with Custom Highlighting Algorithm (use **with vanilla HTML here** or [with ECMAScript Modules/Vue/Nuxt](frameworks/custom)) {#demo-preset-custom}
163+
#### Editor with Custom Highlighting Algorithm (use **with vanilla HTML here** or [with ECMAScript Modules/Vue/Nuxt](frameworks/custom)) {#playground-preset-custom}
164164

165165
```
166-
<!--custom: TODO-->
166+
<!DOCTYPE html>
167+
<html>
168+
<head>
169+
<title>code-input: Editor with Custom Highlighting Algorithm</title>
170+
<!--For convenience, this demo uses files from JSDelivr CDN; for more privacy and security download and host them yourself.-->
171+
172+
<!--Import code-input-->
173+
<!--The same goes for downloaded versions.-->
174+
<script src="https://cdn.jsdelivr.net/gh/WebCoder49/code-input@2.6/code-input.min.js"></script>
175+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/WebCoder49/code-input@2.6/code-input.min.css">
176+
177+
<!--Import some code-input plugins-->
178+
<!--The same goes for downloaded versions.-->
179+
<!--Plugin files are here: https://code-input-js.org/plugins.-->
180+
<script src="https://cdn.jsdelivr.net/gh/WebCoder49/code-input@2.6/plugins/indent.min.js"></script>
181+
182+
<!--Register code-input template-->
183+
<script>
184+
codeInput.registerTemplate("syntax-highlighted",
185+
new codeInput.Template(
186+
function(result_element) { /* Highlight function - with `pre code` code element */
187+
/* Highlight code in result_element - code is already escaped so it doesn't become HTML */
188+
// TODO
189+
// Example highlights question marks red
190+
result_element.innerHTML = result_element.innerHTML.replace(/\?/g, "<strong style='color: red;'>?</strong>");
191+
},
192+
193+
true, /* Optional - Is the `pre` element styled as well as the `code` element?
194+
* Changing this to false uses the code element as the scrollable one rather
195+
* than the pre element */
196+
197+
true, /* Optional - This is used for editing code - setting this to true sets the `code`
198+
* element's class to `language-<the code-input's lang attribute>` */
199+
200+
false /* Optional - Setting this to true passes the `<code-input>` element as a second
201+
* argument to the highlight function to be used for getting data- attribute values
202+
* and using the DOM for the code-input */,
203+
204+
[
205+
// You can add or remove plugins in this list from https://code-input-js.org/plugins.
206+
// All plugins used must be imported above.
207+
new codeInput.plugins.Indent()
208+
]
209+
)
210+
);
211+
// Register templates with different names here, if needed.
212+
</script>
213+
</head>
214+
<body>
215+
<code-input template="syntax-highlighted"><textarea code-input-fallback>What will you create?
216+
Code or something else?</textarea></code-input>
217+
218+
<!--Additional usage details are here: https://code-input-js.org/#pages-->
219+
<!--A list of plugins are here: https://code-input-js.org/plugins-->
220+
</body>
221+
</html>
167222
```
168223

169224
{{< /playground >}}
170225

226+
Next, you can [style your `code-input`](interface/css) and use it in [JavaScript](interface/js) or [HTML5 Forms](interface/forms).
227+
171228
## Features
172229

173230
<dl>
@@ -178,7 +235,7 @@ Choose Any Highlighter
178235
</dt>
179236
<dd>
180237

181-
Use the built in templates for [Prism.js](#demo-preset-prism) or [highlight.js](#demo-preset-hljs), or [pass in any function to highlight a normal HTML element](#demo-preset-custom), and `code-input.js` will do the editability for you. What will you create?
238+
Use the built in templates for [Prism.js](#playground-preset-prism) or [highlight.js](#playground-preset-hljs), or [pass in any function to highlight a normal HTML element](#playground-preset-custom), and `code-input.js` will do the editability for you. What will you create?
182239

183240
</dd>
184241

@@ -239,3 +296,5 @@ something like [CodeMirror](https://codemirror.net/),
239296
[Ace](https://ace.c9.io/) or
240297
[Monaco](https://microsoft.github.io/monaco-editor/).
241298

299+
## Read Enough?
300+
**If you don't need web framework integration, get started with the commented tutorials by example on this page, for [Prism.js](#playground-preset-prism), [highlight.js](#playground-preset-hljs), or [another highlighter](#playground-preset-custom). If you're using a web framework, start [here](frameworks).**

docs/frameworks/_index.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
+++
2+
title = 'Using `code-input.js` with Module Systems and Web Frameworks'
3+
+++

docs/frameworks/custom/_index.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
+++
2+
title = 'Using code-input.js with custom highlighting algorihms in projects which use modules or frameworks'
3+
+++
4+
5+
# Using code-input.js with custom highlighting algorithms in projects which use modules or frameworks
6+
7+
> Contributors: 2025 Oliver Geer
8+
9+
We plan to get documentation for this soon (contributions via a pull request are welcome!), but for now please use [the corresponding article for highlight.js](../hljs) and [the demo frameworkless code for code-input and custom highlighting algorithms](../../#playground-preset-custom).

docs/frameworks/custom/index.md

Lines changed: 0 additions & 7 deletions
This file was deleted.

docs/frameworks/hljs/_index.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
+++
2+
title = 'Using code-input.js with highlight.js in projects which use modules or frameworks'
3+
+++
4+
# Using code-input.js with highlight.js in projects which use modules or frameworks
5+
6+
> Contributors: 2025 Oliver Geer
7+
8+
## Quickstart
9+
* [Vue](vue)
10+
* [Nuxt](nuxt)
11+
12+
## ESM: Technical Details
13+
Since v2.6.0 `code-input.js` exposes ECMAScript modules in the `esm` directory, which allows importing the core functions from the module root or `code-input.mjs`, plugins from `plugins/name.mjs` as default exports and templates from `templates/name.mjs` as default exports. This allows easier integration with larger, more modular projects, including those that use front-end frameworks. See the `.d.mts` files in that directory for more details.
14+
<!--TODO: Page on ESM API-->

0 commit comments

Comments
 (0)