-
-
Notifications
You must be signed in to change notification settings - Fork 153
Expand file tree
/
Copy pathjson-to-markdown-transcript.html
More file actions
304 lines (259 loc) · 7.15 KB
/
json-to-markdown-transcript.html
File metadata and controls
304 lines (259 loc) · 7.15 KB
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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>JSON to Markdown Converter</title>
<style>
* {
box-sizing: border-box;
}
body {
font-family: Helvetica, Arial, sans-serif;
margin: 0;
padding: 20px;
background-color: #f5f5f5;
line-height: 1.6;
}
.container {
max-width: 1200px;
margin: 0 auto;
background: white;
border-radius: 8px;
padding: 30px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}
h1 {
color: #333;
margin-bottom: 30px;
text-align: center;
}
.info-note {
background-color: #f8f9fa;
border: 1px solid #e9ecef;
border-radius: 6px;
padding: 20px;
margin-bottom: 30px;
}
.info-note h3 {
margin-top: 0;
margin-bottom: 12px;
color: #495057;
font-size: 18px;
}
.info-note p {
margin-bottom: 10px;
color: #6c757d;
}
.info-note code {
display: block;
background-color: #343a40;
color: #f8f9fa;
padding: 12px;
border-radius: 4px;
font-family: 'Courier New', monospace;
font-size: 14px;
line-height: 1.4;
white-space: pre-wrap;
word-break: break-all;
overflow-wrap: break-word;
}
.converter-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 30px;
margin-bottom: 20px;
}
.input-section, .output-section {
display: flex;
flex-direction: column;
}
label {
font-weight: bold;
margin-bottom: 8px;
color: #555;
}
textarea {
width: 100%;
height: 300px;
padding: 12px;
border: 2px solid #ddd;
border-radius: 6px;
font-family: 'Courier New', monospace;
font-size: 16px;
resize: vertical;
transition: border-color 0.3s ease;
}
textarea:focus {
outline: none;
border-color: #4CAF50;
}
.button-container {
display: flex;
gap: 10px;
margin-top: 20px;
justify-content: center;
}
button {
padding: 12px 24px;
border: none;
border-radius: 6px;
font-size: 16px;
font-family: Helvetica, Arial, sans-serif;
cursor: pointer;
transition: background-color 0.3s ease;
}
.copy-btn {
background-color: #2196F3;
color: white;
}
.copy-btn:hover {
background-color: #1976D2;
}
.error {
color: #f44336;
background-color: #ffebee;
padding: 10px;
border-radius: 4px;
margin-top: 10px;
display: none;
}
.success {
color: #4CAF50;
background-color: #e8f5e8;
padding: 10px;
border-radius: 4px;
margin-top: 10px;
display: none;
}
@media (max-width: 768px) {
.converter-grid {
grid-template-columns: 1fr;
gap: 20px;
}
.container {
padding: 20px;
}
}
</style>
</head>
<body>
<div class="container">
<h1>JSON to Markdown transcript converter</h1>
<div class="info-note">
<h3>Generate JSON from audio</h3>
<p>To create the JSON format this tool expects, use this <a href="https://llm.datasette.io/" target="_blank">LLM</a> command:</p>
<code>llm -m gemini-2.5-flash \<br> -a path-to-audio \<br> --schema-multi 'timestamp:mm:ss,speaker:best guess at name,text'</code>
</div>
<div class="converter-grid">
<div class="input-section">
<label for="json-input">Paste your JSON here:</label>
<textarea
id="json-input"
placeholder='Paste your JSON here - conversion happens automatically!
{"items": [{"speaker": "Speaker Name", "text": "Text here", "timestamp": "01:01"}]}'
></textarea>
</div>
<div class="output-section">
<label for="markdown-output">Markdown output:</label>
<textarea
id="markdown-output"
readonly
placeholder="Your formatted markdown will appear here..."
></textarea>
</div>
</div>
<div class="button-container">
<button class="copy-btn" onclick="copyToClipboard()">Copy Markdown</button>
</div>
<div id="error-message" class="error"></div>
<div id="success-message" class="success"></div>
</div>
<script type="module">
function convertToMarkdown() {
const jsonInput = document.getElementById('json-input').value.trim();
const markdownOutput = document.getElementById('markdown-output');
const errorMessage = document.getElementById('error-message');
const successMessage = document.getElementById('success-message');
// Clear previous messages
errorMessage.style.display = 'none';
successMessage.style.display = 'none';
if (!jsonInput) {
showError('Please paste your JSON data first.');
return;
}
try {
const data = JSON.parse(jsonInput);
if (!data.items || !Array.isArray(data.items)) {
showError('JSON must contain an "items" array.');
return;
}
let markdown = '';
data.items.forEach((item, index) => {
if (!item.speaker || !item.text || !item.timestamp) {
showError(`Item ${index + 1} is missing required fields (speaker, text, timestamp).`);
return;
}
// Format: **[timestamp] Speaker:** text
markdown += `**[${item.timestamp}] ${item.speaker}:** ${item.text}\n\n`;
});
// Remove trailing newlines
markdown = markdown.trim();
markdownOutput.value = markdown;
showSuccess(`Successfully converted ${data.items.length} items to Markdown!`);
} catch (error) {
showError('Invalid JSON format. Please check your input.');
}
}
function copyToClipboard() {
const markdownOutput = document.getElementById('markdown-output');
const successMessage = document.getElementById('success-message');
if (!markdownOutput.value.trim()) {
showError('No markdown to copy. Please paste valid JSON first.');
return;
}
markdownOutput.select();
markdownOutput.setSelectionRange(0, 99999); // For mobile devices
try {
document.execCommand('copy');
showSuccess('Markdown copied to clipboard!');
} catch (err) {
// Fallback for modern browsers
navigator.clipboard.writeText(markdownOutput.value).then(() => {
showSuccess('Markdown copied to clipboard!');
}).catch(() => {
showError('Failed to copy to clipboard. Please select and copy manually.');
});
}
}
function clearAll() {
document.getElementById('json-input').value = '';
document.getElementById('markdown-output').value = '';
document.getElementById('error-message').style.display = 'none';
document.getElementById('success-message').style.display = 'none';
}
function showError(message) {
const errorMessage = document.getElementById('error-message');
errorMessage.textContent = message;
errorMessage.style.display = 'block';
document.getElementById('success-message').style.display = 'none';
}
function showSuccess(message) {
const successMessage = document.getElementById('success-message');
successMessage.textContent = message;
successMessage.style.display = 'block';
document.getElementById('error-message').style.display = 'none';
}
// Auto-convert on input/paste
document.getElementById('json-input').addEventListener('input', convertToMarkdown);
document.getElementById('json-input').addEventListener('paste', () => {
// Small delay to ensure pasted content is available
setTimeout(convertToMarkdown, 10);
});
// Make functions globally available
window.convertToMarkdown = convertToMarkdown;
window.copyToClipboard = copyToClipboard;
window.clearAll = clearAll;
</script>
</body>
</html>