Created
August 1, 2022 18:09
-
-
Save mewisme/44051d22f612ee3a04b74605ec6c97c5 to your computer and use it in GitHub Desktop.
Web Text Editor using highlight.js
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
| <h1 class="wte-title">Web Text Editor</h1> | |
| <div class="wrapper"> | |
| <div class="edit-window"> | |
| <div class="window-border"> | |
| <span class="close"></span> | |
| <span class="minimize"></span> | |
| <span class="maximize"></span> | |
| <select class="language"> | |
| <option selected>JavaScript</option> | |
| <option>HTML</option> | |
| <option>CSS</option> | |
| </select> | |
| </div> | |
| <div class="input-area"> | |
| <textarea class="textarea"id="input" autofocus></textarea> | |
| <textarea id="cousor" class="cousor"></textarea> | |
| <pre> | |
| <code id="output" class="preview javascript"> | |
| </code> | |
| </pre> | |
| </div> | |
| </div> | |
| </div> |
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
| // Element | |
| var inputarea = document.getElementById("input"); | |
| var outputarea = document.getElementById("output"); | |
| var cousor = document.getElementById("cousor"); | |
| output.addEventListener("click", function (event) { | |
| inputarea.style.zIndex = 4; | |
| inputarea.style.color = "black"; | |
| }, false); | |
| inputarea.addEventListener("input", function (event) { | |
| outputarea.innerHTML = inputarea.value; | |
| inputarea.style.zIndex = 4; | |
| // | |
| refreshHighlighting(); | |
| }, false); | |
| // Refresh highlighting when blured focus from textarea. | |
| inputarea.addEventListener("blur", function (event) { | |
| refreshHighlighting(); | |
| }, false) | |
| function refreshHighlighting() { | |
| hljs.highlightBlock(outputarea); | |
| //setTimeout("refreshHighlighting()", 1000); | |
| inputarea.style.zIndex = 0; | |
| inputarea.style.color = "transparent"; | |
| } | |
| refreshHighlighting(); |
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
| @import url('https://fonts.googleapis.com/css?family=Source+Code+Pro'); | |
| @import url('https://fonts.googleapis.com/css?family=Comfortaa'); | |
| .wte-title { | |
| color: #fff; | |
| text-align: center; | |
| font-family: 'Comfortaa', cursive; | |
| font-size: 3rem; | |
| } | |
| .wrapper { | |
| position: absolute; | |
| margin: auto; | |
| left: 0; | |
| right: 0; | |
| } | |
| $edit-window-height: 400px; | |
| body { | |
| background: #EC87C0; | |
| left: 0; | |
| right: 0; | |
| } | |
| .edit-window { | |
| width: 800px; | |
| height:$edit-window-height; | |
| background: #fafbfc; | |
| border-radius: 5px; | |
| box-shadow: 0px 3px 15px rgba(0,0,0,0.2); | |
| } | |
| .window-border { | |
| display: flex; | |
| top: 0; | |
| height: 50px; | |
| border-top-left-radius: 5px; | |
| border-top-right-radius: 5px; | |
| background: #E6E9ED; | |
| .language { | |
| position: relative; | |
| top: 10px; | |
| right: -655px; | |
| -webkit-appearance: none; | |
| appearance: none; | |
| background: none; | |
| outline: none; | |
| text-align: center; | |
| height: 30px; | |
| border: none; | |
| } | |
| .close, .minimize, .maximize { | |
| top: 17px; | |
| left: 10px; | |
| } | |
| .close { | |
| position: relative; | |
| width: 15px; | |
| height: 15px; | |
| border-radius: 28px; | |
| background: #ED5565; | |
| } | |
| .minimize { | |
| position: relative; | |
| margin-left: 8px; | |
| width: 15px; | |
| height: 15px; | |
| border-radius: 28px; | |
| background: #FFCE54; | |
| } | |
| .maximize { | |
| position: relative; | |
| margin-left: 8px; | |
| width: 15px; | |
| height: 15px; | |
| border-radius: 28px; | |
| background: #48CFAD; | |
| } | |
| } | |
| .input-area { | |
| position: relative; | |
| outline: none; | |
| } | |
| .preview { | |
| position: absolute; | |
| display: inline-block; | |
| background: transparent; | |
| padding: 0; | |
| bottom: 0; | |
| top: 0; | |
| width: 100%; | |
| height: $edit-window-height; | |
| z-index: 3; | |
| } | |
| .textarea { | |
| position: absolute; | |
| display: inline-block; | |
| padding: 0; | |
| width: 100%; | |
| height: $edit-window-height; | |
| z-index: 3; | |
| // Reset | |
| margin: 0; | |
| padding: 0; | |
| background: none; | |
| border: none; | |
| border-radius: 0; | |
| outline: none; | |
| -webkit-appearance: none; | |
| -moz-appearance: none; | |
| appearance: none; | |
| } | |
| .cousor { | |
| position: absolute; | |
| display: inline-block; | |
| padding: 0; | |
| width: 100%; | |
| height: $edit-window-height; | |
| z-index: 1; | |
| // Reset | |
| margin: 0; | |
| padding: 0; | |
| background: none; | |
| border: none; | |
| border-radius: 0; | |
| outline: none; | |
| -webkit-appearance: none; | |
| -moz-appearance: none; | |
| appearance: none; | |
| } | |
| .preview, .textarea, cousor { | |
| font-size: 17px; | |
| font-weight: 200; | |
| font-family: 'Source Code Pro', monospace; | |
| } | |
| .pointer { | |
| color: #333; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment