diff --git a/apps/renderer/src/hooks/biz/useIntegrationActions.tsx b/apps/renderer/src/hooks/biz/useIntegrationActions.tsx index 76c9596df..e069613ca 100644 --- a/apps/renderer/src/hooks/biz/useIntegrationActions.tsx +++ b/apps/renderer/src/hooks/biz/useIntegrationActions.tsx @@ -116,14 +116,23 @@ export const useIntegrationActions = ({ const items = useMemo(() => { if (!populatedEntry || view === undefined) return [] - const getEntryContentAsMarkdown = () => { + const getEntryContentAsMarkdown = async () => { const isReadabilityReady = getReadabilityStatus()[populatedEntry.entries.id] === ReadabilityStatus.SUCCESS const content = (isReadabilityReady ? getReadabilityContent()[populatedEntry.entries.id].content : populatedEntry.entries.content) || "" - return parseHtml(content).toMarkdown() + + const [toMarkdown, toMdast, gfmTableToMarkdown] = await Promise.all([ + import("mdast-util-to-markdown").then((m) => m.toMarkdown), + import("hast-util-to-mdast").then((m) => m.toMdast), + import("mdast-util-gfm-table").then((m) => m.gfmTableToMarkdown), + ]) + + return toMarkdown(toMdast(parseHtml(content).hastTree), { + extensions: [gfmTableToMarkdown()], + }) } const items: { @@ -331,10 +340,10 @@ export const useIntegrationActions = ({ icon: , key: "saveToObsidian", hide: !isObsidianEnabled || !populatedEntry?.entries?.url || !IN_ELECTRON, - onClick: () => { + onClick: async () => { if (!isObsidianEnabled || !populatedEntry?.entries?.url || !IN_ELECTRON) return - const markdownContent = getEntryContentAsMarkdown() + const markdownContent = await getEntryContentAsMarkdown() window.analytics?.capture("integration", { type: "obsidian", event: "save", @@ -379,7 +388,7 @@ export const useIntegrationActions = ({ }) collectionId = collection.data.id } - const markdownContent = getEntryContentAsMarkdown() + const markdownContent = await getEntryContentAsMarkdown() await request("documents.create", { title: populatedEntry.entries.title, text: markdownContent, diff --git a/apps/renderer/src/lib/parse-html.ts b/apps/renderer/src/lib/parse-html.ts index 33849ccbc..477c47952 100644 --- a/apps/renderer/src/lib/parse-html.ts +++ b/apps/renderer/src/lib/parse-html.ts @@ -4,10 +4,7 @@ import type { Element, Parent, Text } from "hast" import type { Schema } from "hast-util-sanitize" import type { Components } from "hast-util-to-jsx-runtime" import { toJsxRuntime } from "hast-util-to-jsx-runtime" -import { toMdast } from "hast-util-to-mdast" import { toText } from "hast-util-to-text" -import { gfmTableToMarkdown } from "mdast-util-gfm-table" -import { toMarkdown } from "mdast-util-to-markdown" import { createElement } from "react" import { Fragment, jsx, jsxs } from "react/jsx-runtime" import { renderToString } from "react-dom/server" @@ -259,7 +256,6 @@ export const parseHtml = ( }, }), toText: () => toText(hastTree), - toMarkdown: () => toMarkdown(toMdast(hastTree), { extensions: [gfmTableToMarkdown()] }), } }