Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
client/note type conversion: improve the warning messages
Adorian Doranc2792a07f478
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.jsonindex 12741c8664..6658512bad 100644--- a/apps/client/src/translations/en/translation.json+++ b/apps/client/src/translations/en/translation.json@@ -713,10 +713,11 @@"convert_note": "Convert","convert_note_to": "Convert note","choose_conversion": "(choose a conversion)",- "conversion_htmlToMarkdown": "Text Notes → Markdown Notes",+ "conversion_htmlToMarkdown": "Text Notes → Markdown Notes (lossy)","conversion_markdownToHtml": "Markdown Notes → Text Notes","help_text": "The conversion is applied only to notes matching the source type; other notes are left untouched. A revision of each converted note is saved beforehand.",- "warning": "Some formatting may be lost when converting notes and you may need to fix a few things afterwards. A revision of each converted note will be saved beforehand so you can restore it. Do you want to continue?"+ "warning": "Some formatting may be lost when converting notes and you may need to fix a few things afterwards. A revision of each converted note will be saved beforehand so you can restore it. Do you want to continue?",+ "warning_risky": "You are converting between two formats that don't have identical capabilities, so some formatting may be lost and some unsupported elements may be dropped.<br><br>Do you fully assume this risk and want to proceed with the conversion?<br><br>A revision of each converted note will be saved beforehand, so you can revert to the original format."},"rename_note": {"rename_note": "Rename note",@@ -920,6 +921,7 @@"convert_to_markdown": "Convert to Markdown Note","convert_to_text": "Convert to Text Note","convert_format_warning": "Some formatting may be lost during the conversion and you may need to fix a few things afterwards. A revision of the current note will be saved beforehand so you can restore it. Do you want to continue?",+ "convert_format_warning_risky": "You are converting between two formats that don't have identical capabilities, so some formatting may be lost and some unsupported elements may be dropped.<br><br>Do you fully assume this risk and want to proceed with the conversion?<br><br>A revision of the current note will be saved beforehand, so you can revert to the original format.","convert_to_markdown_successful": "Note has been converted to Markdown.","convert_to_text_successful": "Note has been converted to a text note.","print_pdf": "Export as PDF...",diff --git a/apps/client/src/widgets/bulk_actions/note/convert_note.tsx b/apps/client/src/widgets/bulk_actions/note/convert_note.tsxindex efe037a43c..69ff2a31fd 100644--- a/apps/client/src/widgets/bulk_actions/note/convert_note.tsx+++ b/apps/client/src/widgets/bulk_actions/note/convert_note.tsx@@ -1,4 +1,4 @@-import { NOTE_CONVERSION_IDS, NoteConversionId } from "@triliumnext/commons";+import { NOTE_CONVERSION_IDS, NoteConversionId, RISKY_NOTE_CONVERSION_IDS } from "@triliumnext/commons";import { useEffect, useState } from "preact/hooks";import { t } from "../../../services/i18n";@@ -43,7 +43,13 @@ export default class ConvertNoteBulkAction extends AbstractBulkAction {getConfirmationMessage() {// Only warn once a conversion has actually been selected.- return this.actionDef.conversion ? t("convert_note.warning") : null;+ const { conversion } = this.actionDef;+ if (!conversion) {+ return null;+ }+ return RISKY_NOTE_CONVERSION_IDS.includes(conversion)+ ? t("convert_note.warning_risky")+ : t("convert_note.warning");}static get actionName() {diff --git a/apps/client/src/widgets/ribbon/NoteActions.tsx b/apps/client/src/widgets/ribbon/NoteActions.tsxindex 624b766409..1ed77356c4 100644--- a/apps/client/src/widgets/ribbon/NoteActions.tsx+++ b/apps/client/src/widgets/ribbon/NoteActions.tsx@@ -392,7 +392,11 @@ function ConvertNoteFormat({ note }: { note: FNote }) {<FormListItemicon="bx bxl-markdown"onClick={async () => {- if (!(await dialog.confirm(t("note_actions.convert_format_warning")))) {+ // Text → Markdown is lossy; Markdown → Text is not, so use the milder warning there.+ const warning = isMarkdown+ ? t("note_actions.convert_format_warning")+ : t("note_actions.convert_format_warning_risky");+ if (!(await dialog.confirm(warning))) {return;}diff --git a/packages/commons/src/lib/bulk_actions.ts b/packages/commons/src/lib/bulk_actions.tsindex f99d7c95e0..c42925840b 100644--- a/packages/commons/src/lib/bulk_actions.ts+++ b/packages/commons/src/lib/bulk_actions.ts@@ -7,6 +7,12 @@ export const NOTE_CONVERSION_IDS = ["htmlToMarkdown", "markdownToHtml"] as constexport type NoteConversionId = (typeof NOTE_CONVERSION_IDS)[number];+/**+ * Conversions that are lossy: the target format cannot represent everything the source format can,+ * so formatting may be lost or unsupported elements dropped. These get a stronger confirmation prompt.+ */+export const RISKY_NOTE_CONVERSION_IDS: readonly NoteConversionId[] = ["htmlToMarkdown"];+export type ActionHandlers = {addLabel: {labelName: string;