Repository navigation
v1.12.0
Minor Changes
-
bece0dd: Add
react-smart-copy/code: copy code the way developers expect, paste it safely.codePayload(source, options?): a copy payload for a string or a rendered, highlighted code block. It holds plain text for editors and terminals, plus monospaced HTML with the block's syntax colours for Google Docs, Word, Slack, Teams and mail. Line-number gutters,user-select: noneandaria-hiddenparts, hidden parts, buttons anddata-copy-ignoreare left out.codeFromElementreturns just the text.- Terminal and REPL sessions copy as their commands (
prompt: 'auto'): bash/zsh, PowerShell, cmd, Python, IPython and Node prompts, or your own pattern. Continued commands stay whole (a trailing backslash, a heredoc, an open quote), and output is dropped.diff: 'after' | 'before'copies one side of a unified diff, andlineNumbers: trueremoves typed line numbers that count up. Shared indentation and trailing whitespace are removed and line endings normalised.normalizeCodeexposes all of this, and also works on the server. pasteAsCode(event, options?): a paste handler for code fields. It fixes curly quotes, dashes, no-break spaces and invisible characters, dedents, and indents each line to the cursor. The browser's undo stays intact.onPastesees every finding and can cancel.pasteToCode(result)servesusePaste, CodeMirror and Monaco.inspectCode(text)finds code that runs differently from how it reads, with line, column and Unicode name: Trojan Source bidi overrides (CVE-2021-42574), invisible identifiers (Hangul fillers), hidden tag characters, runs of variation selectors, Cyrillic and Greek lookalikes in Latin words, control characters, unusual spaces and typographic punctuation. Joiners in Arabic, Persian, Indic and emoji, and full-width punctuation in CJK text, are left alone.cleanCode(text)applies safe replacements until nothing fixable is left, and never guesses a letter.- Pasted code is never cut: past
maxLengthit is atoo-largeerror, or a native paste withpasteAsCode. HTML is parsed inertly.
insertTextnow lives in one shared module and is exported from both/markdownand/code.