Skip to content

Commit 53bff41

Browse files
author
WebCoder49
committed
Fix final bug
1 parent c4371d2 commit 53bff41

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

README.md

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
## What are the advantages of using code-input, and what can it be used for?
2020
Unlike other front-end code-editor projects, the simplicity of how `code-input` works means it is **highly customisable**. As it is not a full-featured editor, you can **choose what features you want it to include, and use your favourite syntax-highlighting algorithms and themes**.
2121

22-
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.**
22+
The `<code-input>` element works like a `<textarea>` and therefore **works in HTML5 forms and supports using the `name`, `value` and `placeholder` attributes, events like `onchange`, form resets, to name a few...**
2323

2424
## 🚀 Getting Started With `code-input` (in 4 simple steps)
2525

@@ -115,12 +115,5 @@ Now that you have registered a template, you can use the custom `<code-input>` e
115115
<code-input lang="HTML" placeholder="Type code here" template="syntax-highlighted" onchange="console.log('Your code is', this.value)"><a href='https://github.com/WebCoder49/code-input'>code-input</a></code-input>
116116
```
117117

118-
### *Next:* What Else Can `code-input` do?
119-
*The two sides to the library:*
120-
121-
1. **Our aim is to make `code-input` work from the start like an ordinary `<textarea>` element, with `name` attribute support, form reset functions, and accessible `aria-` attribute support, etc. leading to HTML form compatibility.**
122-
123-
2. Thanks to many contributions, suggestions and bug identifications from the open-source community, `code-input`'s capabilities are constantly growing. With customisable plugins, you can also turn `code-input` into whatever you want.
124-
125118
## Contributing
126119
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.

code-input.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,15 @@ var codeInput = {
519519
return text.replace(new RegExp("&", "g"), "&amp;").replace(new RegExp("<", "g"), "&lt;"); /* Global RegExp */
520520
}
521521

522+
/**
523+
* HTML-unescape an arbitrary string.
524+
* @param {string} text - The original, HTML-escaped text
525+
* @returns {string} - The new, unescaped text
526+
*/
527+
unescapeHtml(text) {
528+
return text.replace(new RegExp("&amp;", "g"), "&").replace(new RegExp("&lt;", "g"), "<").replace(new RegExp("&gt;", "g"), ">"); /* Global RegExp */
529+
}
530+
522531
/**
523532
* Get the template object this code-input element is using.
524533
* @returns {Object} - Template object
@@ -556,9 +565,11 @@ var codeInput = {
556565
// First-time attribute sync
557566
let lang = this.getAttribute("lang");
558567
let placeholder = this.getAttribute("placeholder") || this.getAttribute("lang") || "";
559-
let value = this.innerHTML || this.getAttribute("value") || "";
568+
let value = this.unescapeHtml(this.innerHTML) || this.getAttribute("value") || "";
560569
// Value attribute deprecated, but included for compatibility
561570

571+
this.initialValue = value; // For form reset
572+
562573
// Create textarea
563574
let textarea = document.createElement("textarea");
564575
textarea.placeholder = placeholder;
@@ -935,8 +946,7 @@ var codeInput = {
935946
* Update value on form reset
936947
*/
937948
formResetCallback() {
938-
this.update(this.textareaElement.innerHTML || this.getAttribute("value"));
939-
// Value attribute deprecated, but included for compatibility reasons.
949+
this.update(this.initialValue);
940950
};
941951
},
942952

0 commit comments

Comments
 (0)