Export ChatGPT Chats to Markdown

A quick guide on how to export your ChatGPT conversations to Markdown format for easy sharing and documentation.

Tools
April 18, 2026
ChatGPT Markdown Exporting

ChatGPT is a powerful tool for generating text-based content, although you can share the conversations with others, it can be useful to export them in a more portable format like Markdown. This allows you to easily share your chats or include them in documentation.

Motivation

The sharable link can't be accessed by other LLMs, I wanted a way to export the conversation in a format that can be easily shared and processed by other tools. Markdown is a great choice because it's widely supported and can be easily converted to other formats if needed.

How to Export ChatGPT Chats to Markdown

  1. Open Your ChatGPT Conversation: Start by opening the conversation you want to export.

  2. Open Developer Tools: Press F12 or right-click and select "Inspect" to open the browser's developer tools.

  3. Navigate to the Console: Click on the "Console" tab in the developer tools.

  4. Run the Export Script: Copy and paste the following JavaScript code into the console and press Enter:

(() => {
    function formatDate(date = new Date()) {
        return date.toISOString().split('T')[0];
    }

    function escapeMarkdown(text) {
        return text
            .replace(/\\/g, '\\\\')
            .replace(/\*/g, '\\*')
            .replace(/_/g, '\\_')
            .replace(/`/g, '\\`')
            .replace(/\n{3,}/g, '\n\n');
    }

    function processMessageContent(element) {
        const clone = element.cloneNode(true);

        // Replace <pre><code> blocks
        clone.querySelectorAll('pre').forEach(pre => {
            const code = pre.innerText.trim();
            const langMatch = pre.querySelector('code')?.className?.match(/language-([a-zA-Z0-9]+)/);
            const lang = langMatch ? langMatch[1] : '';
            pre.replaceWith(`\n\n\`\`\`${lang}\n${code}\n\`\`\`\n`);
        });

        // Replace images and canvas with placeholders
        clone.querySelectorAll('img, canvas').forEach(el => {
            el.replaceWith('[Image or Canvas]');
        });

        // Convert remaining HTML to plain markdown-style text
        return escapeMarkdown(clone.innerText.trim());
    }

    const messages = document.querySelectorAll('div[class*="group"]');
    const lines = [];

    const title = 'Conversation with ChatGPT';
    const date = formatDate();
    const url = window.location.href;

    lines.push(`# ${title}\n`);
    lines.push(`**Date:** ${date}`);
    lines.push(`**Source:** [chat.openai.com](${url})\n`);
    lines.push(`---\n`);

    messages.forEach(group => {
        const isUser = !group.classList.contains("agent-turn");
        const sender = isUser ? 'You' : 'ChatGPT';
        const block = group.querySelector('.markdown, .prose, .whitespace-pre-wrap');

        if (block) {
            const content = processMessageContent(block);
            if (content) {
                lines.push(`### **${sender}**\n`);
                lines.push(content);
                lines.push('\n---\n');
            }
        }
    });

    const markdown = lines.join('\n').trim();
    const blob = new Blob([markdown], { type: 'text/markdown' });
    const a = document.createElement('a');
    a.download = `ChatGPT_Conversation_${date}.md`;
    a.href = URL.createObjectURL(blob);
    document.body.appendChild(a);
    a.click();
    document.body.removeChild(a);
})();
  1. Download starts Automatically: After running the script, a Markdown file containing your ChatGPT conversation will be automatically downloaded to your computer.

Don't worry it's a simple script that extracts the conversation and formats it in Markdown. You can easily share this file or include it in your documentation. Happy chatting!

Based on the original script by @rashidazarang

Conclusion

Exporting your ChatGPT conversations to Markdown is a great way to preserve and share your interactions. With the provided script, you can quickly convert any conversation into a well-formatted Markdown file. This can be especially useful for sharing insights, documenting interactions, or even creating content based on your chats.