sanjay7178 commited on
Commit
92913f2
·
1 Parent(s): 2398853

feat: add Copy as Markdown Table button and JS to export output as a Markdown table

Browse files
Files changed (1) hide show
  1. templates/index.html +45 -0
templates/index.html CHANGED
@@ -74,6 +74,12 @@
74
  .copy-btn:hover {
75
  background-color: #0b7dda;
76
  }
 
 
 
 
 
 
77
  .instructions {
78
  background-color: #f9f9f9;
79
  padding: 15px;
@@ -139,6 +145,7 @@
139
  <button type="submit">Process</button>
140
  <button type="button" class="clear-btn" onclick="clearTextareas()">Clear All</button>
141
  <button type="button" class="copy-btn" onclick="copyToClipboard()">Copy Output</button>
 
142
  </div>
143
  </div>
144
  </form>
@@ -163,6 +170,44 @@
163
  document.execCommand('copy');
164
  alert('Output copied to clipboard!');
165
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
166
  </script>
167
  </body>
168
  </html>
 
74
  .copy-btn:hover {
75
  background-color: #0b7dda;
76
  }
77
+ .markdown-btn {
78
+ background-color: #9C27B0;
79
+ }
80
+ .markdown-btn:hover {
81
+ background-color: #7B1FA2;
82
+ }
83
  .instructions {
84
  background-color: #f9f9f9;
85
  padding: 15px;
 
145
  <button type="submit">Process</button>
146
  <button type="button" class="clear-btn" onclick="clearTextareas()">Clear All</button>
147
  <button type="button" class="copy-btn" onclick="copyToClipboard()">Copy Output</button>
148
+ <button type="button" class="markdown-btn" onclick="copyAsMarkdownTable()">Copy as Markdown Table</button>
149
  </div>
150
  </div>
151
  </form>
 
170
  document.execCommand('copy');
171
  alert('Output copied to clipboard!');
172
  }
173
+
174
+ function copyAsMarkdownTable() {
175
+ const outputText = document.getElementById('output_text').value;
176
+ if (!outputText.trim()) {
177
+ alert('No output to copy!');
178
+ return;
179
+ }
180
+
181
+ // Create markdown table format with header and separator
182
+ const lines = outputText.split('\n').filter(line => line.trim());
183
+
184
+ // Find the maximum line length to determine padding
185
+ const maxLength = Math.max(...lines.map(line => line.length), 35);
186
+ const separator = '-'.repeat(maxLength);
187
+
188
+ // Build the table
189
+ let markdownTable = `| ${lines[0].padEnd(maxLength)} |\n`;
190
+ markdownTable += `| ${separator} |\n`;
191
+
192
+ // Add remaining lines
193
+ for (let i = 1; i < lines.length; i++) {
194
+ markdownTable += `| ${lines[i].padEnd(maxLength)} |\n`;
195
+ }
196
+
197
+ // Copy to clipboard
198
+ navigator.clipboard.writeText(markdownTable).then(() => {
199
+ alert('Output copied as Markdown table!');
200
+ }).catch(() => {
201
+ // Fallback for older browsers
202
+ const textarea = document.createElement('textarea');
203
+ textarea.value = markdownTable;
204
+ document.body.appendChild(textarea);
205
+ textarea.select();
206
+ document.execCommand('copy');
207
+ document.body.removeChild(textarea);
208
+ alert('Output copied as Markdown table!');
209
+ });
210
+ }
211
  </script>
212
  </body>
213
  </html>