nzisaacnz

Syntax Highlighting

Apr 1st, 2013
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.19 KB | None | 0 0
  1. <!--
  2. Syntax Highlighting
  3. s1 = script
  4. s2 = inputs
  5. s3 = div
  6.  
  7. -->
  8. <style>
  9. s1
  10. {
  11.     background-color:#FAA;
  12. }
  13. #highlight
  14. {
  15.     position:absolute;
  16.     left:3px;
  17.     right:0px;
  18.     top:3px;
  19.     bottom:0px;
  20.     font-size:14px;
  21.     font-family:Courier;
  22.     overflow:hidden;
  23. }
  24. #code
  25. {
  26.     position:absolute;
  27.     left:0px;
  28.     top:0px;
  29.     height:100%;
  30.     width:100%;
  31.     background-color:rgba(255,255,255,0);
  32.     font-size:14px;
  33.     font-family:Courier;
  34. }
  35. </style>
  36. <script>
  37. var tags = ["script","input"
  38. function updateCode(area)
  39. {
  40.     var highlight = document.getElementById("highlight");
  41.     highlight.innerText = area.value+"\n\n";
  42.     updateScroll(area);
  43.     regST = new RegExp("\&lt;"+tags[i]+"\&gt;");
  44.     regST.global = true;
  45.     regET = new RegExp("\&lt;\/"+tags[i]+"\&gt;");
  46.     regET.global = true;
  47.     highlight.innerHTML = highlight.innerHTML.replace(regST,"<s1>&lt;script&gt;");
  48.     highlight.innerHTML = highlight.innerHTML.replace(/\&lt;\/script\&gt;/g,"&lt;/script&gt;</s1>");
  49. }
  50. function updateScroll(area)
  51. {
  52.     var highlight = document.getElementById("highlight");
  53.     highlight.scrollTop = area.scrollTop;
  54. }
  55. </script>
  56. <div id="highlight"></div>
  57. <textarea id="code" oninput="updateCode(this)" onscroll="updateScroll(this)">
  58. </textarea>
Advertisement
Add Comment
Please, Sign In to add comment