Spaces:
Running
Running
Update index.html
Browse files- index.html +86 -43
index.html
CHANGED
@@ -3,19 +3,39 @@
|
|
3 |
<head>
|
4 |
<meta charset="UTF-8">
|
5 |
<title>Int茅rprete de C贸digo</title>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
<style>
|
7 |
body, html { margin: 0; padding: 0; height: 100%; font-family: sans-serif; background-color: #f7f7f7; }
|
8 |
.header { padding: 10px 20px; background-color: #fff; border-bottom: 1px solid #ddd; }
|
9 |
.header h1 { margin: 0; font-size: 1.5em; }
|
10 |
.container { display: flex; height: calc(100vh - 55px); }
|
11 |
-
.pane { width: 50%; padding: 10px; box-sizing: border-box; display: flex; flex-direction: column; }
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
width: 100%;
|
14 |
height: 100%;
|
15 |
border: 1px solid #ccc;
|
16 |
border-radius: 4px;
|
17 |
box-shadow: inset 0 1px 3px rgba(0,0,0,0.1);
|
18 |
}
|
|
|
19 |
#runButton {
|
20 |
display: block;
|
21 |
width: 100%;
|
@@ -30,14 +50,41 @@
|
|
30 |
transition: background-color 0.2s;
|
31 |
}
|
32 |
#runButton:hover { background-color: #0056b3; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
</style>
|
34 |
</head>
|
35 |
<body>
|
36 |
<div class="header">
|
37 |
-
<h1>Int茅rprete de C贸digo
|
38 |
</div>
|
39 |
<div class="container">
|
40 |
<div class="pane">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
<textarea id="editor" placeholder="Pega tu c贸digo HTML completo aqu铆..."></textarea>
|
42 |
<button id="runButton">鈻讹笍 Ejecutar</button>
|
43 |
</div>
|
@@ -46,24 +93,46 @@
|
|
46 |
</div>
|
47 |
</div>
|
48 |
<script>
|
49 |
-
|
50 |
const previewFrame = document.getElementById('preview');
|
51 |
const runButton = document.getElementById('runButton');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
|
53 |
function updatePreview() {
|
54 |
-
|
55 |
-
|
56 |
-
// Esto es m谩s robusto que usar srcdoc para casos complejos.
|
57 |
const previewDoc = previewFrame.contentDocument || previewFrame.contentWindow.document;
|
58 |
previewDoc.open();
|
59 |
previewDoc.write(code);
|
60 |
previewDoc.close();
|
61 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
|
63 |
runButton.addEventListener('click', updatePreview);
|
|
|
64 |
|
65 |
-
//
|
66 |
-
|
67 |
<!DOCTYPE html>
|
68 |
<html lang="es">
|
69 |
<head>
|
@@ -71,40 +140,11 @@
|
|
71 |
<meta charset="UTF-8">
|
72 |
<style>
|
73 |
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;700&display=swap');
|
74 |
-
body, html {
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
display: flex;
|
80 |
-
justify-content: center;
|
81 |
-
align-items: center;
|
82 |
-
font-family: 'Inter', sans-serif;
|
83 |
-
background-color: #f8f9fa;
|
84 |
-
color: #495057;
|
85 |
-
}
|
86 |
-
.welcome-container {
|
87 |
-
text-align: center;
|
88 |
-
padding: 40px;
|
89 |
-
}
|
90 |
-
.icon {
|
91 |
-
width: 80px;
|
92 |
-
height: 80px;
|
93 |
-
margin-bottom: 20px;
|
94 |
-
color: #007bff;
|
95 |
-
}
|
96 |
-
h1 {
|
97 |
-
font-size: 2em;
|
98 |
-
font-weight: 700;
|
99 |
-
color: #343a40;
|
100 |
-
margin: 0 0 10px 0;
|
101 |
-
}
|
102 |
-
p {
|
103 |
-
font-size: 1.1em;
|
104 |
-
font-weight: 400;
|
105 |
-
color: #6c757d;
|
106 |
-
max-width: 450px;
|
107 |
-
}
|
108 |
</style>
|
109 |
</head>
|
110 |
<body>
|
@@ -117,6 +157,9 @@
|
|
117 |
</div>
|
118 |
</body>
|
119 |
</html>`;
|
|
|
|
|
|
|
120 |
updatePreview();
|
121 |
</script>
|
122 |
</body>
|
|
|
3 |
<head>
|
4 |
<meta charset="UTF-8">
|
5 |
<title>Int茅rprete de C贸digo</title>
|
6 |
+
|
7 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.15/codemirror.min.js"></script>
|
8 |
+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.15/codemirror.min.css">
|
9 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.15/mode/xml/xml.min.js"></script>
|
10 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.15/mode/javascript/javascript.min.js"></script>
|
11 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.15/mode/css/css.min.js"></script>
|
12 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.15/mode/htmlmixed/htmlmixed.min.js"></script>
|
13 |
+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.15/theme/material-darker.min.css">
|
14 |
+
|
15 |
+
|
16 |
<style>
|
17 |
body, html { margin: 0; padding: 0; height: 100%; font-family: sans-serif; background-color: #f7f7f7; }
|
18 |
.header { padding: 10px 20px; background-color: #fff; border-bottom: 1px solid #ddd; }
|
19 |
.header h1 { margin: 0; font-size: 1.5em; }
|
20 |
.container { display: flex; height: calc(100vh - 55px); }
|
21 |
+
.pane { width: 50%; padding: 10px; box-sizing: border-box; display: flex; flex-direction: column; position: relative; }
|
22 |
+
|
23 |
+
/* Estilos para el editor CodeMirror */
|
24 |
+
.CodeMirror {
|
25 |
+
width: 100%;
|
26 |
+
height: 100%;
|
27 |
+
border: 1px solid #ccc;
|
28 |
+
border-radius: 4px;
|
29 |
+
}
|
30 |
+
|
31 |
+
.pane iframe {
|
32 |
width: 100%;
|
33 |
height: 100%;
|
34 |
border: 1px solid #ccc;
|
35 |
border-radius: 4px;
|
36 |
box-shadow: inset 0 1px 3px rgba(0,0,0,0.1);
|
37 |
}
|
38 |
+
|
39 |
#runButton {
|
40 |
display: block;
|
41 |
width: 100%;
|
|
|
50 |
transition: background-color 0.2s;
|
51 |
}
|
52 |
#runButton:hover { background-color: #0056b3; }
|
53 |
+
|
54 |
+
/* 2. ESTILOS PARA EL NUEVO BOT脫N DE DESCARGA */
|
55 |
+
.editor-buttons {
|
56 |
+
position: absolute;
|
57 |
+
top: 18px;
|
58 |
+
right: 18px;
|
59 |
+
z-index: 10;
|
60 |
+
}
|
61 |
+
.icon-button {
|
62 |
+
background: #555;
|
63 |
+
border: none;
|
64 |
+
padding: 5px;
|
65 |
+
border-radius: 4px;
|
66 |
+
cursor: pointer;
|
67 |
+
opacity: 0.7;
|
68 |
+
transition: opacity 0.2s;
|
69 |
+
}
|
70 |
+
.icon-button:hover { opacity: 1; }
|
71 |
+
.icon-button svg { width: 20px; height: 20px; color: white; display: block; }
|
72 |
+
|
73 |
</style>
|
74 |
</head>
|
75 |
<body>
|
76 |
<div class="header">
|
77 |
+
<h1>Int茅rprete de C贸digo (Docker/FastAPI)</h1>
|
78 |
</div>
|
79 |
<div class="container">
|
80 |
<div class="pane">
|
81 |
+
<div class="editor-buttons">
|
82 |
+
<button id="downloadButton" class="icon-button" title="Descargar c贸digo como .txt">
|
83 |
+
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor">
|
84 |
+
<path stroke-linecap="round" stroke-linejoin="round" d="M3 16.5v2.25A2.25 2.25 0 005.25 21h13.5A2.25 2.25 0 0021 18.75V16.5M16.5 12L12 16.5m0 0L7.5 12m4.5 4.5V3" />
|
85 |
+
</svg>
|
86 |
+
</button>
|
87 |
+
</div>
|
88 |
<textarea id="editor" placeholder="Pega tu c贸digo HTML completo aqu铆..."></textarea>
|
89 |
<button id="runButton">鈻讹笍 Ejecutar</button>
|
90 |
</div>
|
|
|
93 |
</div>
|
94 |
</div>
|
95 |
<script>
|
96 |
+
// 4. INICIALIZACI脫N DE CODEMIRROR Y NUEVA L脫GICA
|
97 |
const previewFrame = document.getElementById('preview');
|
98 |
const runButton = document.getElementById('runButton');
|
99 |
+
const downloadButton = document.getElementById('downloadButton');
|
100 |
+
|
101 |
+
// Inicializamos CodeMirror en nuestro textarea
|
102 |
+
const editor = CodeMirror.fromTextArea(document.getElementById('editor'), {
|
103 |
+
lineNumbers: true, // 隆Aqu铆 est谩 la magia de los n煤meros de l铆nea!
|
104 |
+
mode: 'htmlmixed', // Habilita resaltado de HTML, CSS y JS
|
105 |
+
theme: 'material-darker', // Tema de colores oscuro
|
106 |
+
lineWrapping: true // Ajuste de l铆nea autom谩tico
|
107 |
+
});
|
108 |
|
109 |
function updatePreview() {
|
110 |
+
// Para obtener el c贸digo, ahora usamos el m茅todo de CodeMirror
|
111 |
+
const code = editor.getValue();
|
|
|
112 |
const previewDoc = previewFrame.contentDocument || previewFrame.contentWindow.document;
|
113 |
previewDoc.open();
|
114 |
previewDoc.write(code);
|
115 |
previewDoc.close();
|
116 |
}
|
117 |
+
|
118 |
+
function downloadCode() {
|
119 |
+
const code = editor.getValue();
|
120 |
+
const blob = new Blob([code], { type: 'text/plain' });
|
121 |
+
const url = URL.createObjectURL(blob);
|
122 |
+
const a = document.createElement('a');
|
123 |
+
a.href = url;
|
124 |
+
a.download = 'codigo.txt';
|
125 |
+
document.body.appendChild(a);
|
126 |
+
a.click();
|
127 |
+
document.body.removeChild(a);
|
128 |
+
URL.revokeObjectURL(url);
|
129 |
+
}
|
130 |
|
131 |
runButton.addEventListener('click', updatePreview);
|
132 |
+
downloadButton.addEventListener('click', downloadCode);
|
133 |
|
134 |
+
// C贸digo de bienvenida mejorado
|
135 |
+
const welcomeCode = `
|
136 |
<!DOCTYPE html>
|
137 |
<html lang="es">
|
138 |
<head>
|
|
|
140 |
<meta charset="UTF-8">
|
141 |
<style>
|
142 |
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;700&display=swap');
|
143 |
+
body, html { margin: 0; padding: 0; width: 100%; height: 100%; display: flex; justify-content: center; align-items: center; font-family: 'Inter', sans-serif; background-color: #f8f9fa; color: #495057; }
|
144 |
+
.welcome-container { text-align: center; padding: 40px; }
|
145 |
+
.icon { width: 80px; height: 80px; margin-bottom: 20px; color: #007bff; }
|
146 |
+
h1 { font-size: 2em; font-weight: 700; color: #343a40; margin: 0 0 10px 0; }
|
147 |
+
p { font-size: 1.1em; font-weight: 400; color: #6c757d; max-width: 450px; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
148 |
</style>
|
149 |
</head>
|
150 |
<body>
|
|
|
157 |
</div>
|
158 |
</body>
|
159 |
</html>`;
|
160 |
+
|
161 |
+
// Para establecer el c贸digo, ahora usamos el m茅todo de CodeMirror
|
162 |
+
editor.setValue(welcomeCode);
|
163 |
updatePreview();
|
164 |
</script>
|
165 |
</body>
|