Skip to content

Instantly share code, notes, and snippets.

@jimbrig
Created June 5, 2025 19:24
Show Gist options
  • Save jimbrig/069eaafc88196e43cd1ec239783608e2 to your computer and use it in GitHub Desktop.
Save jimbrig/069eaafc88196e43cd1ec239783608e2 to your computer and use it in GitHub Desktop.
Export ChatGPT to Markdown JS
function h(html) {
return html.replace(/<p>/g, '\n\n')
.replace(/<\/p>/g, '')
.replace(/<b>/g, '**')
.replace(/<\/b>/g, '**')
.replace(/<i>/g, '_')
.replace(/<\/i>/g, '_')
.replace(/<code[^>]*>/g, (match) => {
const lm = match.match(/class="[^"]*language-([^"]*)"/);
return lm ? '\n```' + lm[1] + '\n' : '```';
})
.replace(/<\/code[^>]*>/g, '```')
.replace(/<[^>]*>/g, '')
.replace(/Copy code/g, '')
.replace(/This content may violate our content policy. If you believe this to be in error, please submit your feedback — your input will aid our research in this area./g, '')
.trim();
}
(() => {
const e = document.querySelectorAll(".text-base");
let t = "";
for (const s of e) {
if (s.querySelector(".whitespace-pre-wrap")) {
t += `**${s.querySelector('img') ? 'You' : 'ChatGPT'}**: ${h(s.querySelector(".whitespace-pre-wrap").innerHTML)}\n\n`;
}
}
const o = document.createElement("a");
o.download = "Conversation with ChatGPT.md";
o.href = URL.createObjectURL(new Blob([t]));
o.style.display = "none";
document.body.appendChild(o);
o.click();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment