Update templates/index.html
Browse files- templates/index.html +29 -32
templates/index.html
CHANGED
@@ -55,37 +55,22 @@
|
|
55 |
|
56 |
<div class="flex flex-col md:flex-row editor-container">
|
57 |
<div class="w-full md:w-1/2 p-4">
|
58 |
-
<textarea id="markdown-input" class="w-full h-full p-2 border border-gray-300 rounded-md focus:ring-2 focus:ring-blue-500 focus:border-blue-500 resize-none" placeholder="
|
59 |
|
60 |
-
##
|
|
|
61 |
|
62 |
-
|
63 |
-
-
|
64 |
-
|
65 |
-
- Lists
|
66 |
-
- Code blocks
|
67 |
-
- Tables
|
68 |
-
- And more!
|
69 |
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
```
|
74 |
|
75 |
-
##
|
76 |
-
|
77 |
-
1. Write your content in Markdown
|
78 |
-
2. Click the "Convert to DOCX" button
|
79 |
-
3. Download your professional DOCX document
|
80 |
-
|
81 |
-
| Feature | Support |
|
82 |
-
|--------------|---------|
|
83 |
-
| Headers | ✅ |
|
84 |
-
| Lists | ✅ |
|
85 |
-
| Code Blocks | ✅ |
|
86 |
-
| Tables | ✅ |
|
87 |
-
|
88 |
-
> This is a blockquote. Your converted document will preserve all formatting.</textarea>
|
89 |
</div>
|
90 |
<div id="markdown-preview" class="w-full md:w-1/2 p-4 prose max-w-none"></div>
|
91 |
</div>
|
@@ -149,8 +134,8 @@ def hello_world():
|
|
149 |
|
150 |
showStatus('Converting to DOCX...', 'info');
|
151 |
|
152 |
-
//
|
153 |
-
const response = await fetch('
|
154 |
method: 'POST',
|
155 |
headers: {
|
156 |
'Content-Type': 'application/json',
|
@@ -164,11 +149,24 @@ def hello_world():
|
|
164 |
throw new Error(`Server returned ${response.status}`);
|
165 |
}
|
166 |
|
167 |
-
const
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
168 |
const url = window.URL.createObjectURL(blob);
|
169 |
const a = document.createElement('a');
|
170 |
a.href = url;
|
171 |
-
a.download = 'document.docx';
|
172 |
document.body.appendChild(a);
|
173 |
a.click();
|
174 |
document.body.removeChild(a);
|
@@ -177,7 +175,7 @@ def hello_world():
|
|
177 |
showStatus('Document downloaded successfully!', 'success');
|
178 |
} catch (error) {
|
179 |
console.error('Conversion error:', error);
|
180 |
-
showStatus('Error converting document
|
181 |
} finally {
|
182 |
convertBtn.disabled = false;
|
183 |
convertBtn.innerHTML = `
|
@@ -210,4 +208,3 @@ def hello_world():
|
|
210 |
</script>
|
211 |
</body>
|
212 |
</html>
|
213 |
-
|
|
|
55 |
|
56 |
<div class="flex flex-col md:flex-row editor-container">
|
57 |
<div class="w-full md:w-1/2 p-4">
|
58 |
+
<textarea id="markdown-input" class="w-full h-full p-2 border border-gray-300 rounded-md focus:ring-2 focus:ring-blue-500 focus:border-blue-500 resize-none" placeholder="# Start writing your Markdown here...
|
59 |
|
60 |
+
## Headers
|
61 |
+
Use # for h1, ## for h2 etc.
|
62 |
|
63 |
+
## Lists
|
64 |
+
- Item 1
|
65 |
+
- Item 2
|
|
|
|
|
|
|
|
|
66 |
|
67 |
+
## Code
|
68 |
+
```javascript
|
69 |
+
console.log('Hello World');
|
70 |
```
|
71 |
|
72 |
+
## More formatting
|
73 |
+
**Bold**, *italic*, [links](https://example.com)"></textarea>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
</div>
|
75 |
<div id="markdown-preview" class="w-full md:w-1/2 p-4 prose max-w-none"></div>
|
76 |
</div>
|
|
|
134 |
|
135 |
showStatus('Converting to DOCX...', 'info');
|
136 |
|
137 |
+
// First send the markdown to the conversion endpoint
|
138 |
+
const response = await fetch('/api/convert', {
|
139 |
method: 'POST',
|
140 |
headers: {
|
141 |
'Content-Type': 'application/json',
|
|
|
149 |
throw new Error(`Server returned ${response.status}`);
|
150 |
}
|
151 |
|
152 |
+
const result = await response.json();
|
153 |
+
|
154 |
+
if (!result.success) {
|
155 |
+
throw new Error(result.message || 'Conversion failed');
|
156 |
+
}
|
157 |
+
|
158 |
+
// Then download the generated file
|
159 |
+
const downloadResponse = await fetch(`/api/download/${result.filename}`);
|
160 |
+
|
161 |
+
if (!downloadResponse.ok) {
|
162 |
+
throw new Error('Failed to download file');
|
163 |
+
}
|
164 |
+
|
165 |
+
const blob = await downloadResponse.blob();
|
166 |
const url = window.URL.createObjectURL(blob);
|
167 |
const a = document.createElement('a');
|
168 |
a.href = url;
|
169 |
+
a.download = result.filename || 'document.docx';
|
170 |
document.body.appendChild(a);
|
171 |
a.click();
|
172 |
document.body.removeChild(a);
|
|
|
175 |
showStatus('Document downloaded successfully!', 'success');
|
176 |
} catch (error) {
|
177 |
console.error('Conversion error:', error);
|
178 |
+
showStatus('Error converting document: ' + error.message, 'error');
|
179 |
} finally {
|
180 |
convertBtn.disabled = false;
|
181 |
convertBtn.innerHTML = `
|
|
|
208 |
</script>
|
209 |
</body>
|
210 |
</html>
|
|