Created
December 10, 2016 19:17
-
-
Save vaaas/2b37458c149e16c3755ffd5329c345ce to your computer and use it in GitHub Desktop.
This file contains 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> | |
<!-- | |
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
Version 2, December 2004 | |
Copyright (C) 2004 Sam Hocevar <sam@hocevar.net> | |
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. | |
--> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="description" content="preview HTML documents"> | |
<meta name="author" content="Vas"> | |
<title>Sensibe Preview</title> | |
<style> | |
body { | |
height: 100%; | |
padding: 0; | |
margin: 0; | |
} | |
textarea, button { | |
display: block; | |
} | |
textarea { | |
width: 95%; | |
height: 90%; | |
} | |
button { | |
width: 90%; | |
} | |
#write { | |
position: absolute; | |
top: 0; | |
left: 0; | |
width: 50%; | |
height: inherit; | |
} | |
#preview { | |
position: absolute; | |
top: 0; | |
right: 0; | |
width: 50%; | |
height: 90%; | |
} | |
</style> | |
<script> | |
function main() { | |
"use strict" | |
function paragrapher (text) { | |
var script_regex = /<script>[^<]*?<\/script>/g // find script tags | |
var empty_regex = /^\s*$/mg | |
var para_regex = /^([^<]|<[^phuol\/]|<u>).*$/mg // find a paragraph containing something (but not header or list) | |
text = (text | |
.replace(script_regex, "") | |
.replace(empty_regex, "") | |
.replace(para_regex, "<p>$&</p>") | |
) | |
return text | |
} | |
function renderpreview (e) { | |
var textarea = document.getElementById("paste") | |
var text = paragrapher(textarea.value) | |
var preview = document.getElementById("preview") | |
var innerdoc = preview.contentDocument | |
innerdoc.open() | |
innerdoc.write(text) | |
innerdoc.close() | |
} | |
var button = document.getElementById("submit") | |
button.onclick = renderpreview | |
} | |
window.onload = main | |
</script> | |
</head> | |
<body> | |
<div id="write"> | |
<textarea id="paste" placeholder="paste text, then click preview"></textarea> | |
<button id="submit">Preview</button> | |
</div> | |
<iframe id="preview"></iframe> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment