From aefe6790779427ddacafb27348a64cd743412e93 Mon Sep 17 00:00:00 2001 From: Andy Pickering Date: Tue, 28 Apr 2026 16:06:54 +0900 Subject: [PATCH] Copy response text as both plain text and rich HTML When an OLS response is copied to the clipboard, write both text/plain (raw Markdown) and text/html (rendered HTML via marked) so that pasting into rich text editors preserves formatting, while plain text editors still receive the raw Markdown. Made-with: Cursor --- package-lock.json | 14 ++++++++++++++ package.json | 1 + src/clipboard.ts | 11 +++++++++-- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 2cc0ed5d..192e1596 100644 --- a/package-lock.json +++ b/package-lock.json @@ -19,6 +19,7 @@ "immutable": "^3.8.3", "js-yaml": "^4.1.1", "lodash": "^4.18.1", + "marked": "14.0.0", "react": "17.0.2", "react-dom": "17.0.2", "react-i18next": "11.18.6", @@ -6399,6 +6400,7 @@ "version": "2.3.2", "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -8486,6 +8488,18 @@ "url": "https://github.com/sponsors/wooorm" } }, + "node_modules/marked": { + "version": "14.0.0", + "resolved": "https://registry.npmjs.org/marked/-/marked-14.0.0.tgz", + "integrity": "sha512-uIj4+faQ+MgHgwUW1l2PsPglZLOLOT1uErt06dAPtx2kjteLAkbsd/0FiYg/MGS+i7ZKLb7w2WClxHkzOOuryQ==", + "license": "MIT", + "bin": { + "marked": "bin/marked.js" + }, + "engines": { + "node": ">= 18" + } + }, "node_modules/matcher-collection": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/matcher-collection/-/matcher-collection-2.0.1.tgz", diff --git a/package.json b/package.json index d5d98798..a505985a 100644 --- a/package.json +++ b/package.json @@ -32,6 +32,7 @@ "immutable": "^3.8.3", "js-yaml": "^4.1.1", "lodash": "^4.18.1", + "marked": "14.0.0", "react": "17.0.2", "react-dom": "17.0.2", "react-i18next": "11.18.6", diff --git a/src/clipboard.ts b/src/clipboard.ts index fd1058d5..67704c06 100644 --- a/src/clipboard.ts +++ b/src/clipboard.ts @@ -1,6 +1,13 @@ -export const copyToClipboard = (value: string): void => { +import { marked } from 'marked'; + +export const copyToClipboard = async (value: string): Promise => { try { - navigator.clipboard.writeText(value); + const html = marked.parse(value) as string; + const clipboardItem = new ClipboardItem({ + 'text/plain': new Blob([value], { type: 'text/plain' }), + 'text/html': new Blob([html], { type: 'text/html' }), + }); + await navigator.clipboard.write([clipboardItem]); } catch (err) { // eslint-disable-next-line no-console console.error('Failed to copy to clipboard: ', err);