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
feat(markdown): basic note type integration
Elian Dorane9d8aa82f448
diff --git a/apps/client/src/entities/fnote.ts b/apps/client/src/entities/fnote.tsindex a30a83975a..6f72e68def 100644--- a/apps/client/src/entities/fnote.ts+++ b/apps/client/src/entities/fnote.ts@@ -1069,6 +1069,10 @@ export default class FNote {return this.mime === "text/x-sqlite;schema=trilium";}+ isMarkdown() {+ return this.type === "code" && (this.mime === "text/x-markdown" || this.mime === "text/x-gfm");+ }+isTriliumScript() {return this.mime.startsWith("application/javascript");}diff --git a/apps/client/src/widgets/NoteDetail.tsx b/apps/client/src/widgets/NoteDetail.tsxindex e734bbf9c7..826cffa0e9 100644--- a/apps/client/src/widgets/NoteDetail.tsx+++ b/apps/client/src/widgets/NoteDetail.tsx@@ -356,6 +356,8 @@ export async function getExtendedWidgetType(note: FNote | null | undefined, noteresultingType = "readOnlyCode";} else if (type === "text") {resultingType = "editableText";+ } else if (note.isMarkdown()) {+ resultingType = "markdown";} else if (type === "code") {resultingType = "editableCode";} else if (type === "launcher") {diff --git a/apps/client/src/widgets/note_types.tsx b/apps/client/src/widgets/note_types.tsxindex f2f17dd590..67ec56a618 100644--- a/apps/client/src/widgets/note_types.tsx+++ b/apps/client/src/widgets/note_types.tsx@@ -12,7 +12,7 @@ import { TypeWidgetProps } from "./type_widgets/type_widget";* A `NoteType` altered by the note detail widget, taking into consideration whether the note is editable or not and adding special note types such as an empty one,* for protected session or attachment information.*/-export type ExtendedNoteType = Exclude<NoteType, "launcher" | "text" | "code" | "llmChat"> | "empty" | "readOnlyCode" | "readOnlyText" | "readOnlyOCRText" | "editableText" | "editableCode" | "attachmentDetail" | "attachmentList" | "protectedSession" | "sqlConsole" | "llmChat";+export type ExtendedNoteType = Exclude<NoteType, "launcher" | "text" | "code" | "llmChat"> | "empty" | "readOnlyCode" | "readOnlyText" | "readOnlyOCRText" | "editableText" | "editableCode" | "attachmentDetail" | "attachmentList" | "protectedSession" | "sqlConsole" | "markdown" | "llmChat";export type TypeWidget = ((props: TypeWidgetProps) => VNode | JSX.Element | undefined);type NoteTypeView = () => (Promise<{ default: TypeWidget } | TypeWidget> | TypeWidget);@@ -147,6 +147,12 @@ export const TYPE_MAPPINGS: Record<ExtendedNoteType, NoteTypeMapping> = {className: "sql-console-widget-container",isFullHeight: true},+ markdown: {+ view: () => import("./type_widgets/code/Markdown"),+ className: "note-detail-markdown",+ printable: true,+ isFullHeight: true+ },spreadsheet: {view: () => import("./type_widgets/spreadsheet/Spreadsheet"),className: "note-detail-spreadsheet",diff --git a/apps/client/src/widgets/type_widgets/code/Markdown.tsx b/apps/client/src/widgets/type_widgets/code/Markdown.tsxnew file mode 100644index 0000000000..3f7cf0df5f--- /dev/null+++ b/apps/client/src/widgets/type_widgets/code/Markdown.tsx@@ -0,0 +1,12 @@+import SplitEditor from "../helpers/SplitEditor";+import { TypeWidgetProps } from "../type_widget";++export default function Markdown(props: TypeWidgetProps) {+ return (+ <SplitEditor+ noteType="code"+ {...props}+ previewContent={<div>Hello World</div>}+ />+ );+}