Skip to content

Commit 4698b52

Browse files
authored
1 parent a94b596 commit 4698b52

File tree

1 file changed

+26
-14
lines changed

1 file changed

+26
-14
lines changed

rich-text-to-markdown.html

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,6 @@ <h1>Rich Text → Markdown (No React)</h1>
119119
<span class="hint">Tip: long‑press → Paste</span>
120120
</div>
121121
<div id="input" class="dropzone" contenteditable="true" role="textbox" aria-label="Paste rich text here" data-placeholder="Paste here…"></div>
122-
<div class="btnrow" style="margin-top:10px;">
123-
<button id="clearBtn" type="button">Clear</button>
124-
</div>
125122
</section>
126123

127124
<section class="panel">
@@ -131,8 +128,8 @@ <h1>Rich Text → Markdown (No React)</h1>
131128
</div>
132129
<textarea id="output" class="output" spellcheck="false" aria-label="Markdown output" placeholder="Your Markdown will appear here…"></textarea>
133130
<div class="btnrow" style="margin-top:10px;">
134-
<button id="convertBtn" class="primary" type="button">Convert</button>
135131
<button id="copyBtn" type="button">Copy</button>
132+
<button id="quoteBtn" type="button" style="display:none;">Quote this</button>
136133
</div>
137134
<p class="hint" style="margin-top:10px;">Only <strong>bold</strong>, <em>italic</em>, inline links, line breaks, and paragraph breaks are converted. Other formatting is ignored.</p>
138135
</section>
@@ -149,9 +146,8 @@ <h1>Rich Text → Markdown (No React)</h1>
149146
<script>
150147
const input = document.getElementById('input');
151148
const output = document.getElementById('output');
152-
const convertBtn = document.getElementById('convertBtn');
153149
const copyBtn = document.getElementById('copyBtn');
154-
const clearBtn = document.getElementById('clearBtn');
150+
const quoteBtn = document.getElementById('quoteBtn');
155151
const toast = document.getElementById('toast');
156152

157153
// Placeholder behavior for contenteditable
@@ -267,10 +263,20 @@ <h1>Rich Text → Markdown (No React)</h1>
267263
return md.trim();
268264
}
269265

266+
function updateQuoteVisibility(md) {
267+
if (!quoteBtn) return;
268+
if (md && md.trim()) {
269+
quoteBtn.style.display = '';
270+
} else {
271+
quoteBtn.style.display = 'none';
272+
}
273+
}
274+
270275
function convert() {
271276
const html = input.getAttribute('data-empty') === 'true' ? '' : input.innerHTML;
272277
const md = htmlToMarkdown(html || '');
273278
output.value = md;
279+
updateQuoteVisibility(md);
274280
return md;
275281
}
276282

@@ -293,8 +299,6 @@ <h1>Rich Text → Markdown (No React)</h1>
293299
convert();
294300
});
295301

296-
convertBtn.addEventListener('click', convert);
297-
298302
copyBtn.addEventListener('click', async () => {
299303
try {
300304
await navigator.clipboard.writeText(output.value || '');
@@ -306,15 +310,23 @@ <h1>Rich Text → Markdown (No React)</h1>
306310
}
307311
});
308312

309-
clearBtn.addEventListener('click', () => {
310-
input.innerHTML = '';
311-
output.value = '';
312-
updatePlaceholder();
313-
input.focus();
314-
});
313+
if (quoteBtn) {
314+
quoteBtn.addEventListener('click', () => {
315+
const text = output.value || '';
316+
if (!text.trim()) return;
317+
const quoted = text.split('\n').map(line => {
318+
if (!line.trim()) {
319+
return '>';
320+
}
321+
return line.startsWith('>') ? line : `> ${line}`;
322+
}).join('\n');
323+
output.value = quoted;
324+
});
325+
}
315326

316327
// Init
317328
updatePlaceholder();
329+
updateQuoteVisibility('');
318330
</script>
319331
</body>
320332
</html>

0 commit comments

Comments
 (0)