惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
罗磊的独立博客
博客园 - 【当耐特】
M
MIT News - Artificial intelligence
月光博客
月光博客
博客园_首页
博客园 - 叶小钗
T
Tailwind CSS Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
I
InfoQ
量子位
小众软件
小众软件
爱范儿
爱范儿
The GitHub Blog
The GitHub Blog
IT之家
IT之家
Jina AI
Jina AI
阮一峰的网络日志
阮一峰的网络日志
G
Google Developers Blog
WordPress大学
WordPress大学
人人都是产品经理
人人都是产品经理
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
J
Java Code Geeks
云风的 BLOG
云风的 BLOG
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
Why Copying Code from AI Chat Tools Still Breaks Your Ind...
doremi · 2026-04-26 · via DEV Community

If you've ever copied a code block from ChatGPT or Claude and pasted it into your editor, you've probably seen this:

# What ChatGPT shows you:
def process_data(items: list[dict]) -> dict:
    result = {}
    for item in items:
        if item.get("active"):
            key = item["category"]
            result.setdefault(key, []).append(item["value"])
    return result

Enter fullscreen mode Exit fullscreen mode

# What ends up in your clipboard:
def process_data(items: list[dict]) -> dict:
        result = {}
        for item in items:
            if item.get("active"):
                key = item["category"]
                    result.setdefault(key, []).append(item["value"])
    return result

Enter fullscreen mode Exit fullscreen mode

Tabs became spaces. Spaces became tabs. The whole thing is a mess. And if you're working with nested code — callbacks, decorators, class methods — it gets exponentially worse.

The Technical Root Cause

AI chat interfaces render code blocks using <pre><code> elements with CSS for styling. The syntax highlighting is applied via CSS classes (Prism.js, Highlight.js, or custom). When you select and copy:

  1. The browser's clipboard API tries to serialize the selection
  2. It includes CSS-computed styles as rich text
  3. Most target apps (VS Code, IDEs, terminals) expect plain text
  4. The mismatch causes indentation corruption

Here's the kicker: the underlying text in the DOM is usually correct. It's the clipboard serialization that breaks things. Different browsers handle this differently too — Chrome, Firefox, and Safari all have slightly different clipboard behavior.

I Tested 5 Approaches

1. Direct Copy-Paste

Result: Fails ~60% of the time with nested code
Why: Clipboard serialization corrupts whitespace

2. "View Source" in DevTools

Result: Works but tedious
Why: You get the raw text but have to manually extract it

3. ChatGPT's Share Link

Result: Preserves formatting but read-only
Why: It's a rendered webpage, not a code export

4. Export to Markdown

Result: Best option for developers
Why: Markdown preserves code fences with language tags. Clean, portable, editor-friendly.

5. Export to PDF with Syntax Highlighting

Result: Good for documentation, not for reuse
Why: Visual fidelity is high but you can't edit the code

The Solution I Settled On

I started using a Chrome extension that handles multi-platform AI export (ChatGPT, Claude, Gemini, DeepSeek, Grok). The Markdown export is what I use 90% of the time:

  • Code blocks come out with proper language tags and indentation
  • No formatting corruption — it's plain text with markdown syntax
  • Works with Obsidian, VS Code, any editor
  • Batch export — I can grab an entire conversation at once

The extension is called XWX AI Chat Exporter. It's free (PDF has a daily limit, but Markdown is unlimited). I'm not affiliated with the devs — just a user who got tired of fixing broken indentation.

Bonus: My Obsidian Integration

Since I'm exporting to Markdown anyway, I piped everything into Obsidian:

AI Conversations/
├── 2026-04/
│   ├── 2026-04-21-system-design.md
│   ├── 2026-04-20-api-refactor.md
│   └── 2026-04-19-auth-architecture.md

Enter fullscreen mode Exit fullscreen mode

Each exported file gets:

  • Frontmatter with date, AI platform, and topic tags
  • Proper code fences with language identifiers
  • Preserved headings for the conversation structure

This turns AI conversations into a searchable knowledge base. When I need to find "that conversation about rate limiting strategies," I just search my vault instead of scrolling through ChatGPT history.

The Real Issue

This whole problem shouldn't exist. AI chat tools are used by millions of developers who need to copy code reliably. The fact that the default copy-paste still breaks indentation in 2026 is... not great.

Until the platforms fix it properly (they should just offer a "Copy as plain text" button that actually works), extensions and workarounds are your best bet.

What's your approach? Do you deal with broken formatting, or have you found a workflow that works?