mirror of
https://github.com/zadam/trilium.git
synced 2026-03-01 18:13:39 +01:00
feat(client/menus): add Copy as Markdown (#8808)
This commit is contained in:
commit
54be58ba1f
@ -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") {
|
||||
|
||||
@ -882,6 +882,7 @@
|
||||
"electron_context_menu": {
|
||||
"cut": "قص",
|
||||
"copy": "نسخ",
|
||||
"copy-as-markdown": "نسخ كـ Markdown",
|
||||
"paste": "لصق",
|
||||
"copy-link": "نسخ الرابط",
|
||||
"add-term-to-dictionary": "اضافة \"{{term}}\" الى القاموس",
|
||||
|
||||
@ -1760,6 +1760,7 @@
|
||||
"add-term-to-dictionary": "将 \"{{term}}\" 添加到字典",
|
||||
"cut": "剪切",
|
||||
"copy": "复制",
|
||||
"copy-as-markdown": "复制为 Markdown",
|
||||
"copy-link": "复制链接",
|
||||
"paste": "粘贴",
|
||||
"paste-as-plain-text": "以纯文本粘贴",
|
||||
|
||||
@ -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",
|
||||
|
||||
@ -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",
|
||||
|
||||
@ -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",
|
||||
|
||||
@ -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",
|
||||
|
||||
@ -1808,6 +1808,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í",
|
||||
|
||||
@ -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": "प्लेन टेक्स्ट की तरह पेस्ट करें",
|
||||
|
||||
@ -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",
|
||||
|
||||
@ -1353,6 +1353,7 @@
|
||||
"add-term-to-dictionary": "辞書に \"{{term}}\" を追加",
|
||||
"cut": "切り取り",
|
||||
"copy": "コピー",
|
||||
"copy-as-markdown": "Markdownとしてコピー",
|
||||
"copy-link": "リンクをコピー",
|
||||
"paste": "貼り付け",
|
||||
"paste-as-plain-text": "プレーンテキストで貼り付け",
|
||||
|
||||
@ -614,6 +614,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",
|
||||
|
||||
@ -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",
|
||||
|
||||
@ -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",
|
||||
|
||||
@ -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",
|
||||
|
||||
@ -708,6 +708,7 @@
|
||||
"paste": "Вставить",
|
||||
"copy-link": "Скопировать ссылку",
|
||||
"copy": "Скопировать",
|
||||
"copy-as-markdown": "Копировать как Markdown",
|
||||
"cut": "Вырезать",
|
||||
"search_online": "Поиск \"{{term}}\" в {{searchEngine}}",
|
||||
"add-term-to-dictionary": "Добавить \"{{term}}\" в словарь",
|
||||
|
||||
@ -1722,6 +1722,7 @@
|
||||
"add-term-to-dictionary": "將 \"{{term}}\" 新增至字典",
|
||||
"cut": "剪下",
|
||||
"copy": "複製",
|
||||
"copy-as-markdown": "複製為 Markdown",
|
||||
"copy-link": "複製連結",
|
||||
"paste": "貼上",
|
||||
"paste-as-plain-text": "以純文字貼上",
|
||||
|
||||
@ -1533,6 +1533,7 @@
|
||||
"add-term-to-dictionary": "Додати \"{{term}}\" до словника",
|
||||
"cut": "Вирізати",
|
||||
"copy": "Копіювати",
|
||||
"copy-as-markdown": "Копіювати як Markdown",
|
||||
"copy-link": "Копіювати посилання",
|
||||
"paste": "Вставити",
|
||||
"paste-as-plain-text": "Вставити як звичайний текст",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user