diff --git a/apps/client/src/menus/electron_context_menu.ts b/apps/client/src/menus/electron_context_menu.ts index 219a009c7c..6baba6a951 100644 --- a/apps/client/src/menus/electron_context_menu.ts +++ b/apps/client/src/menus/electron_context_menu.ts @@ -3,6 +3,8 @@ import options from "../services/options.js"; import zoomService from "../components/zoom.js"; import contextMenu, { type MenuItem } from "./context_menu.js"; import { t } from "../services/i18n.js"; +import server from "../services/server.js"; +import * as clipboardExt from "../services/clipboard_ext.js"; import type { BrowserWindow } from "electron"; import type { CommandNames, AppContext } from "../components/app_context.js"; @@ -60,6 +62,33 @@ function setupContextMenu() { uiIcon: "bx bx-copy", handler: () => webContents.copy() }); + + items.push({ + enabled: hasText, + title: t("electron_context_menu.copy-as-markdown"), + uiIcon: "bx bx-copy-alt", + handler: async () => { + const selection = window.getSelection(); + if (!selection || !selection.rangeCount) return ''; + + const range = selection.getRangeAt(0); + const div = document.createElement('div'); + div.appendChild(range.cloneContents()); + + const htmlContent = div.innerHTML; + if (htmlContent) { + try { + const { markdownContent } = await server.post<{ markdownContent: string }>( + "other/to-markdown", + { htmlContent } + ); + await clipboardExt.copyTextWithToast(markdownContent); + } catch (error) { + console.error("Failed to copy as markdown:", error); + } + } + } + }); } if (!["", "javascript:", "about:blank#blocked"].includes(params.linkURL) && params.mediaType === "none") { diff --git a/apps/client/src/translations/ar/translation.json b/apps/client/src/translations/ar/translation.json index 3eaf9a8432..18831c4a8a 100644 --- a/apps/client/src/translations/ar/translation.json +++ b/apps/client/src/translations/ar/translation.json @@ -882,6 +882,7 @@ "electron_context_menu": { "cut": "قص", "copy": "نسخ", + "copy-as-markdown": "نسخ كـ Markdown", "paste": "لصق", "copy-link": "نسخ الرابط", "add-term-to-dictionary": "اضافة \"{{term}}\" الى القاموس", diff --git a/apps/client/src/translations/cn/translation.json b/apps/client/src/translations/cn/translation.json index 9b27037faf..a70fab24a3 100644 --- a/apps/client/src/translations/cn/translation.json +++ b/apps/client/src/translations/cn/translation.json @@ -1758,6 +1758,7 @@ "add-term-to-dictionary": "将 \"{{term}}\" 添加到字典", "cut": "剪切", "copy": "复制", + "copy-as-markdown": "复制为 Markdown", "copy-link": "复制链接", "paste": "粘贴", "paste-as-plain-text": "以纯文本粘贴", diff --git a/apps/client/src/translations/de/translation.json b/apps/client/src/translations/de/translation.json index b90f5f8ebf..9f8bf82b0b 100644 --- a/apps/client/src/translations/de/translation.json +++ b/apps/client/src/translations/de/translation.json @@ -1729,6 +1729,7 @@ "add-term-to-dictionary": "Begriff \"{{term}}\" zum Wörterbuch hinzufügen", "cut": "Ausschneiden", "copy": "Kopieren", + "copy-as-markdown": "Als Markdown kopieren", "copy-link": "Link kopieren", "paste": "Einfügen", "paste-as-plain-text": "Als unformatierten Text einfügen", diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json index 04a372ddae..1f4d42db9c 100644 --- a/apps/client/src/translations/en/translation.json +++ b/apps/client/src/translations/en/translation.json @@ -1810,6 +1810,7 @@ "add-term-to-dictionary": "Add \"{{term}}\" to dictionary", "cut": "Cut", "copy": "Copy", + "copy-as-markdown": "Copy as markdown", "copy-link": "Copy link", "paste": "Paste", "paste-as-plain-text": "Paste as plain text", diff --git a/apps/client/src/translations/es/translation.json b/apps/client/src/translations/es/translation.json index 7f4538c6d5..2c31f84f2f 100644 --- a/apps/client/src/translations/es/translation.json +++ b/apps/client/src/translations/es/translation.json @@ -1778,6 +1778,7 @@ "add-term-to-dictionary": "Agregar \"{{term}}\" al diccionario", "cut": "Cortar", "copy": "Copiar", + "copy-as-markdown": "Copiar como markdown", "copy-link": "Copiar enlace", "paste": "Pegar", "paste-as-plain-text": "Pegar como texto plano", diff --git a/apps/client/src/translations/fr/translation.json b/apps/client/src/translations/fr/translation.json index c1d844ae99..be1265054b 100644 --- a/apps/client/src/translations/fr/translation.json +++ b/apps/client/src/translations/fr/translation.json @@ -1689,6 +1689,7 @@ "add-term-to-dictionary": "Ajouter «{{term}}» au dictionnaire", "cut": "Couper", "copy": "Copier", + "copy-as-markdown": "Copier en markdown", "copy-link": "Copier le lien", "paste": "Coller", "paste-as-plain-text": "Coller comme texte brut", diff --git a/apps/client/src/translations/ga/translation.json b/apps/client/src/translations/ga/translation.json index c5020a4d0c..d8d94fb7af 100644 --- a/apps/client/src/translations/ga/translation.json +++ b/apps/client/src/translations/ga/translation.json @@ -1807,6 +1807,7 @@ "add-term-to-dictionary": "Cuir \"{{term}}\" leis an bhfoclóir", "cut": "Gearr", "copy": "Cóipeáil", + "copy-as-markdown": "Cóipeáil mar markdown", "copy-link": "Cóipeáil nasc", "paste": "Greamaigh", "paste-as-plain-text": "Greamaigh mar théacs simplí", diff --git a/apps/client/src/translations/hi/translation.json b/apps/client/src/translations/hi/translation.json index ac5ed8073d..a48c11c6de 100644 --- a/apps/client/src/translations/hi/translation.json +++ b/apps/client/src/translations/hi/translation.json @@ -1810,6 +1810,7 @@ "add-term-to-dictionary": "\"{{term}}\" को डिक्शनरी में जोड़ें", "cut": "कट (Cut)", "copy": "कॉपी (Copy)", + "copy-as-markdown": "Markdown के रूप में कॉपी करें", "copy-link": "लिंक कॉपी करें", "paste": "पेस्ट (Paste)", "paste-as-plain-text": "प्लेन टेक्स्ट की तरह पेस्ट करें", diff --git a/apps/client/src/translations/it/translation.json b/apps/client/src/translations/it/translation.json index 0ce70cbf62..8e26e7d191 100644 --- a/apps/client/src/translations/it/translation.json +++ b/apps/client/src/translations/it/translation.json @@ -334,6 +334,7 @@ "electron_context_menu": { "cut": "Taglia", "copy": "Copia", + "copy-as-markdown": "Copia come markdown", "paste": "Incolla", "copy-link": "Copia collegamento", "paste-as-plain-text": "Incolla come testo semplice", diff --git a/apps/client/src/translations/ja/translation.json b/apps/client/src/translations/ja/translation.json index e040e7e6e1..cd0eeb9a35 100644 --- a/apps/client/src/translations/ja/translation.json +++ b/apps/client/src/translations/ja/translation.json @@ -1352,6 +1352,7 @@ "add-term-to-dictionary": "辞書に \"{{term}}\" を追加", "cut": "切り取り", "copy": "コピー", + "copy-as-markdown": "Markdownとしてコピー", "copy-link": "リンクをコピー", "paste": "貼り付け", "paste-as-plain-text": "プレーンテキストで貼り付け", diff --git a/apps/client/src/translations/pl/translation.json b/apps/client/src/translations/pl/translation.json index 982cb71c43..48a62eec65 100644 --- a/apps/client/src/translations/pl/translation.json +++ b/apps/client/src/translations/pl/translation.json @@ -612,6 +612,7 @@ "electron_context_menu": { "cut": "Wytnij", "copy": "Kopiuj", + "copy-as-markdown": "Kopiuj jako markdown", "copy-link": "Kopiuj link", "paste": "Wklej", "paste-as-plain-text": "Wklej jako zwykły tekst", diff --git a/apps/client/src/translations/pt/translation.json b/apps/client/src/translations/pt/translation.json index 167d85e8c0..45570c6db4 100644 --- a/apps/client/src/translations/pt/translation.json +++ b/apps/client/src/translations/pt/translation.json @@ -1774,6 +1774,7 @@ "add-term-to-dictionary": "Adicionar \"{{term}}\" ao dicionário", "cut": "Cortar", "copy": "Copiar", + "copy-as-markdown": "Copiar como markdown", "copy-link": "Copiar ligação", "paste": "Colar", "paste-as-plain-text": "Colar como texto sem formatação", diff --git a/apps/client/src/translations/pt_br/translation.json b/apps/client/src/translations/pt_br/translation.json index 3db8d8c8e1..22fd6856d1 100644 --- a/apps/client/src/translations/pt_br/translation.json +++ b/apps/client/src/translations/pt_br/translation.json @@ -1637,6 +1637,7 @@ "add-term-to-dictionary": "Adicionar \"{{term}}\" ao dicionário", "cut": "Cortar", "copy": "Copiar", + "copy-as-markdown": "Copiar como markdown", "copy-link": "Copiar link", "paste": "Colar", "paste-as-plain-text": "Colar como texto sem formatação", diff --git a/apps/client/src/translations/ro/translation.json b/apps/client/src/translations/ro/translation.json index a7bfd1f00b..e1f5810cf0 100644 --- a/apps/client/src/translations/ro/translation.json +++ b/apps/client/src/translations/ro/translation.json @@ -1724,6 +1724,7 @@ "electron_context_menu": { "add-term-to-dictionary": "Adaugă „{{term}}” în dicționar", "copy": "Copiază", + "copy-as-markdown": "Copiază ca markdown", "copy-link": "Copiază legătura", "cut": "Decupează", "paste": "Lipește", diff --git a/apps/client/src/translations/ru/translation.json b/apps/client/src/translations/ru/translation.json index f023814bdc..c3e1344e2d 100644 --- a/apps/client/src/translations/ru/translation.json +++ b/apps/client/src/translations/ru/translation.json @@ -708,6 +708,7 @@ "paste": "Вставить", "copy-link": "Скопировать ссылку", "copy": "Скопировать", + "copy-as-markdown": "Копировать как Markdown", "cut": "Вырезать", "search_online": "Поиск \"{{term}}\" в {{searchEngine}}", "add-term-to-dictionary": "Добавить \"{{term}}\" в словарь", diff --git a/apps/client/src/translations/tw/translation.json b/apps/client/src/translations/tw/translation.json index 71eaf097a5..9eecb868e1 100644 --- a/apps/client/src/translations/tw/translation.json +++ b/apps/client/src/translations/tw/translation.json @@ -1722,6 +1722,7 @@ "add-term-to-dictionary": "將 \"{{term}}\" 新增至字典", "cut": "剪下", "copy": "複製", + "copy-as-markdown": "複製為 Markdown", "copy-link": "複製連結", "paste": "貼上", "paste-as-plain-text": "以純文字貼上", diff --git a/apps/client/src/translations/uk/translation.json b/apps/client/src/translations/uk/translation.json index 8861fca0bc..6c1951a035 100644 --- a/apps/client/src/translations/uk/translation.json +++ b/apps/client/src/translations/uk/translation.json @@ -1533,6 +1533,7 @@ "add-term-to-dictionary": "Додати \"{{term}}\" до словника", "cut": "Вирізати", "copy": "Копіювати", + "copy-as-markdown": "Копіювати як Markdown", "copy-link": "Копіювати посилання", "paste": "Вставити", "paste-as-plain-text": "Вставити як звичайний текст",