Spaces:
Running
Running
File size: 8,447 Bytes
fa03d38 ed84d3d fa03d38 ed84d3d fa03d38 ed84d3d fa03d38 ed84d3d fa03d38 ed84d3d fa03d38 ed84d3d fa03d38 ed84d3d fa03d38 ed84d3d fa03d38 ed84d3d fa03d38 ed84d3d fa03d38 ed84d3d fa03d38 ed84d3d fa03d38 ed84d3d fa03d38 ed84d3d fa03d38 ed84d3d fa03d38 ed84d3d fa03d38 ed84d3d fa03d38 ed84d3d fa03d38 ed84d3d fa03d38 ed84d3d fa03d38 ed84d3d fa03d38 ed84d3d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 |
<!DOCTYPE html>
<html>
<head>
<title>Repo & Files to Markdown</title>
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500&display=swap" rel="stylesheet">
<style>
body {
font-family: 'Roboto', sans-serif;
background: linear-gradient(to bottom right, #f0f4f8, #d9e2ec);
margin: 0;
padding: 0;
}
.container {
max-width: 1200px;
margin: 20px auto;
padding: 20px;
}
.input-section, .markdown-section, .preview-section {
background: white;
border-radius: 10px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
padding: 20px;
margin-bottom: 20px;
}
input[type="text"], input[type="file"] {
width: 100%;
padding: 10px;
margin: 10px 0;
border: 1px solid #ccc;
border-radius: 5px;
box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.1);
transition: border-color 0.3s;
}
input[type="text"]:focus, input[type="file"]:focus {
border-color: #4CAF50;
outline: none;
}
button {
padding: 10px 20px;
background: linear-gradient(to right, #4CAF50, #45a049);
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
margin: 5px;
transition: background 0.3s, transform 0.1s;
}
button:hover {
background: linear-gradient(to right, #45a049, #4CAF50);
}
button:active {
transform: scale(0.98);
}
#downloadBtn {
background: linear-gradient(to right, #3498db, #2980b9);
}
#downloadBtn:hover {
background: linear-gradient(to right, #2980b9, #3498db);
}
.spinner {
display: none;
border: 4px solid #f3f3f3;
border-top: 4px solid #3498db;
border-radius: 50%;
width: 30px;
height: 30px;
animation: spin 1s linear infinite;
margin: 20px auto;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
.output-container {
display: flex;
flex-wrap: wrap;
gap: 20px;
}
.markdown-section, .preview-section {
flex: 1;
min-width: 300px;
}
textarea {
width: 100%;
height: 400px;
margin-top: 10px;
padding: 10px;
border: 1px solid #ccc;
border-radius: 5px;
box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.1);
font-family: monospace;
resize: vertical;
}
#output {
margin-top: 10px;
padding: 10px;
max-height: 600px;
overflow-y: auto;
}
#output h1, #output h2, #output h3 {
color: #333;
}
#output code {
background: #f4f4f4;
padding: 2px 4px;
border-radius: 3px;
}
#output pre {
background: #f4f4f4;
padding: 10px;
border-radius: 5px;
overflow-x: auto;
}
.fade-in {
animation: fadeIn 0.5s ease-in;
}
@keyframes fadeIn {
from { opacity: 0; }
to { opacity: 1; }
}
</style>
</head>
<body>
<div class="container">
<div class="input-section">
<h1>Repository & Files to Markdown Converter</h1>
<p>Enter a GitHub/Hugging Face Space URL (e.g., https://huggingface.co/spaces/username/space)</p>
<input type="text" id="repoUrl" placeholder="Enter GitHub or Hugging Face Space URL">
<p>OR upload files (select multiple files or a folder - folder upload supported in Chrome)</p>
<input type="file" id="fileInput" multiple webkitdirectory>
<br>
<button onclick="processRepo()">Convert URL</button>
<button onclick="processFiles()">Convert Files</button>
<button id="downloadBtn" style="display: none;" onclick="downloadMarkdown()">Download .md</button>
<div id="spinner" class="spinner"></div>
</div>
<div class="output-container">
<div class="markdown-section">
<h2>Markdown Output:</h2>
<textarea id="markdownOutput" readonly></textarea>
</div>
<div class="preview-section">
<h2>Preview:</h2>
<div id="output"></div>
</div>
</div>
</div>
<script>
let currentMarkdown = '';
let currentFilename = '';
async function processRepo() {
const repoUrl = document.getElementById('repoUrl').value;
await processContent('/process', { repo_url: repoUrl });
}
async function processFiles() {
const files = document.getElementById('fileInput').files;
if (files.length === 0) {
alert('Please select at least one file or folder');
return;
}
const formData = new FormData();
for (let file of files) {
formData.append('files[]', file);
}
await processContent('/process', formData, false);
}
async function processContent(url, data, isJson = true) {
const spinner = document.getElementById('spinner');
const buttons = document.querySelectorAll('button');
spinner.style.display = 'block';
buttons.forEach(btn => btn.disabled = true);
try {
const options = {
method: 'POST',
...(isJson ? {
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(data)
} : { body: data })
};
const response = await fetch(url, options);
const result = await response.json();
if (result.error) {
alert(result.error);
return;
}
currentMarkdown = result.markdown;
currentFilename = result.filename;
document.getElementById('markdownOutput').value = result.markdown;
document.getElementById('output').innerHTML = result.html;
document.getElementById('downloadBtn').style.display = 'inline-block';
const markdownOutput = document.getElementById('markdownOutput');
const output = document.getElementById('output');
markdownOutput.classList.add('fade-in');
output.classList.add('fade-in');
setTimeout(() => {
markdownOutput.classList.remove('fade-in');
output.classList.remove('fade-in');
}, 500);
} catch (error) {
alert('An error occurred: ' + error.message);
} finally {
spinner.style.display = 'none';
buttons.forEach(btn => btn.disabled = false);
}
}
async function downloadMarkdown() {
try {
const response = await fetch('/download', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
markdown: currentMarkdown,
filename: currentFilename
})
});
const blob = await response.blob();
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = currentFilename;
document.body.appendChild(a);
a.click();
a.remove();
window.URL.revokeObjectURL(url);
} catch (error) {
alert('Error downloading file: ' + error.message);
}
}
</script>
</body>
</html> |