Skip to content

Smart paste in markdown notes: auto-detect SVG/JSON/HTML and wrap in fenced code block#177

Open
lklyne wants to merge 1 commit into
mainfrom
claude/issue-122
Open

Smart paste in markdown notes: auto-detect SVG/JSON/HTML and wrap in fenced code block#177
lklyne wants to merge 1 commit into
mainfrom
claude/issue-122

Conversation

@lklyne
Copy link
Copy Markdown
Owner

@lklyne lklyne commented May 29, 2026

Closes #122

What

Adds smart paste detection to the CodeMirror markdown note editor. When pasting content with a strong structural signal, it's automatically inserted as a fenced code block with the detected language tag.

Detection logic

Two layers, cheapest first:

  1. MIME type hintsimage/svg+xmlsvg, application/jsonjson
  2. Structural sniffs on text/plain:
    • Opens with <svg and closes with </svg>svg
    • Parses as a valid JSON object or array → json (pretty-printed)
    • Starts with <!DOCTYPE html> or <htmlhtml

Uncertain content always falls through to normal paste — bias is hard toward doing nothing so mis-fires can't wrap prose in code fences.

Undo

The formatted insert is a single CodeMirror dispatch transaction, captured by the Yjs UndoManager as one operation. One Cmd+Z reverses it.

Files changed

  • src/renderer/canvas-bg/entity-renderers/markdown-smart-paste.ts — detection function (detectSmartPaste) + CodeMirror extension (smartPasteExtension)
  • src/renderer/canvas-bg/entity-renderers/markdown-codemirror.ts — adds smartPasteExtension() to the editor extensions
  • tests/unit/markdown-smart-paste.test.ts — 16 unit tests covering all detection paths and no-match cases

Generated by Claude Code

…rap in fenced code block

On paste into a CodeMirror markdown editor, detectSmartPaste() checks for a
strong structural signal (MIME type or unambiguous parse) and, when confident,
inserts the content as a fenced code block with the detected language tag.
JSON is pretty-printed. Prose-like text always falls through to normal paste
so false positives cannot wrap ordinary text in code fences.

The paste is a single dispatch transaction, so Yjs undo reverses it in one Cmd+Z.

Closes #122

https://claude.ai/code/session_01QimxGbNH9tVirc5fJDPcGA
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Smart paste in markdown notes: auto-detect language and auto-format

2 participants