ShayanRl commited on
Commit
a8c95a5
·
verified ·
1 Parent(s): c990a1b

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +57 -18
index.html CHANGED
@@ -1,19 +1,58 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  </html>
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>JSON to HTML Converter</title>
7
+ </head>
8
+ <body>
9
+
10
+ <h2>Paste JSON Below:</h2>
11
+ <textarea id="jsonInput" rows="10" cols="50" placeholder="Paste JSON here"></textarea>
12
+ <br><br>
13
+ <button onclick="convertJson()">Convert JSON to HTML</button>
14
+
15
+ <h2>Output:</h2>
16
+ <div id="output"></div>
17
+
18
+ <script>
19
+ // Recursive function to convert JSON to HTML
20
+ function jsonToHtml(data) {
21
+ let html = '';
22
+
23
+ if (Array.isArray(data)) {
24
+ html += '<ul>';
25
+ data.forEach(item => {
26
+ html += `<li>${jsonToHtml(item)}</li>`;
27
+ });
28
+ html += '</ul>';
29
+ } else if (typeof data === 'object' && data !== null) {
30
+ for (const key in data) {
31
+ if (Array.isArray(data[key]) || typeof data[key] === 'object') {
32
+ html += `<div aria-label="${key}">${jsonToHtml(data[key])}</div>`;
33
+ } else {
34
+ html += `<p aria-label="${key}">${data[key]}</p>`;
35
+ }
36
+ }
37
+ } else {
38
+ html += data;
39
+ }
40
+
41
+ return html;
42
+ }
43
+
44
+ // Function to handle JSON input and display HTML
45
+ function convertJson() {
46
+ const jsonInput = document.getElementById("jsonInput").value;
47
+ try {
48
+ const jsonData = JSON.parse(jsonInput); // Parse JSON input
49
+ const htmlContent = jsonToHtml(jsonData); // Convert to HTML
50
+ document.getElementById("output").innerHTML = htmlContent; // Display HTML
51
+ } catch (error) {
52
+ document.getElementById("output").innerHTML = "<p style='color: red;'>Invalid JSON. Please check the input.</p>";
53
+ }
54
+ }
55
+ </script>
56
+
57
+ </body>
58
  </html>