-
-
Save yckart/3729385 to your computer and use it in GitHub Desktop.
previewR: Shows what you type in an input-field or in a textarea.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function( | |
a, // An input element (textarea, input) | |
b, // The element to hold the output | |
c // content-placeholder | |
) { | |
c = // Put everything in a variable for a valid returning | |
b.innerHTML = // Write in the given element | |
a.value // Get the current content from input element | |
.replace(/\n/g, '<br>'); // Replace linebreaks | |
return c; // Return the replaced content | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function(a,b,c){c=b.innerHTML=a.value.replace(/\n/g,'<br>');return c} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
Version 2, December 2004 | |
Copyright (C) 2012 Yannick Albert <http://yckart.com> | |
Everyone is permitted to copy and distribute verbatim or modified | |
copies of this license document, and changing it is allowed as long | |
as the name is changed. | |
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION | |
0. You just DO WHAT THE FUCK YOU WANT TO. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "previewR", | |
"description": "Shows what you type in an input-field or in a textarea.", | |
"keywords": [ | |
"textarea", | |
"input", | |
"preview" | |
] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<title>previewR: Shows what you type in an input-field or in a textarea.</title> | |
<div>Expected value: <b>A short line of text for a better interpretation.</b></div> | |
<div>Actual value: <b id="ret"></b></div> | |
<textarea id="textarea" cols="25" rows="5"></textarea> | |
<script> | |
var previewR=function(a,b,c){c=b.innerHTML=a.value.replace(/\n/g,'<br>');return c}; | |
document.onkeyup = function() { | |
previewR(document.getElementById('textarea'), document.getElementById('ret')) | |
}; | |
</script> |
github doesn't do so in its comments ;-) I meant you should translate < to <
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
RegExp shorthand:
function(a,b,c){c=b.innerHTML=a.value.replace(/\n/g,"<br>");return c};
I suggest you also translate < to <, because otherwise anyone could insert arbitrary html.