Skip to content

Commit 54ba932

Browse files
authored
Merge pull request #170 from IL-Internet/master
HTML-Viewer
2 parents 82c987c + efc6f80 commit 54ba932

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

entries/HTML-Viewer

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<title>HTML Viewer</title>
6+
<meta name="description" content="HTML Viewer. Preview your code with option to download it">
7+
<meta name="author" content="IL-Internet">
8+
<meta name="github" content="IL-Internet">
9+
<style>
10+
body {
11+
font-family: Arial, sans-serif;
12+
}
13+
.container {
14+
display: flex;
15+
gap: 20px;
16+
}
17+
textarea,
18+
iframe {
19+
flex: 1;
20+
height: 400px;
21+
overflow: auto;
22+
border: 1px solid #ccc;
23+
padding: 10px;
24+
box-sizing: border-box;
25+
resize: none;
26+
}
27+
iframe {
28+
padding: 0;
29+
}
30+
</style>
31+
</head>
32+
<body>
33+
<h3>HTML Viewer</h3>
34+
<button onclick="render()">Render</button>
35+
<button onclick="download()">Download</button>
36+
<div class="container">
37+
<textarea id="htmlInput" wrap="off" placeholder="Paste HTML here"></textarea>
38+
<iframe id="preview" sandbox="allow-scripts"></iframe>
39+
</div>
40+
<script>
41+
let htmlContent = "";
42+
function render() {
43+
htmlContent = document.getElementById("htmlInput").value.trim();
44+
if (!htmlContent) return;
45+
const iframe = document.getElementById("preview");
46+
iframe.srcdoc = htmlContent;
47+
}
48+
function download() {
49+
htmlContent = document.getElementById("htmlInput").value.trim();
50+
if (!htmlContent) return;
51+
const parser = new DOMParser();
52+
const doc = parser.parseFromString(htmlContent, "text/html");
53+
const title = doc.querySelector("title")?.textContent.trim() || "untitled";
54+
const blob = new Blob([htmlContent], { type: "text/html" });
55+
const url = URL.createObjectURL(blob);
56+
const a = document.createElement("a");
57+
a.href = url;
58+
a.download = `${title}.html`;
59+
a.click();
60+
URL.revokeObjectURL(url);
61+
}
62+
</script>
63+
</body>
64+
</html>

0 commit comments

Comments
 (0)