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
Open
Smart paste in markdown notes: auto-detect SVG/JSON/HTML and wrap in fenced code block#177lklyne wants to merge 1 commit into
lklyne wants to merge 1 commit into
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
image/svg+xml→svg,application/json→jsontext/plain:<svgand closes with</svg>→svgjson(pretty-printed)<!DOCTYPE html>or<html→htmlUncertain 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— addssmartPasteExtension()to the editor extensionstests/unit/markdown-smart-paste.test.ts— 16 unit tests covering all detection paths and no-match casesGenerated by Claude Code