Skip to content

Commit bef80de

Browse files
committed
fix: convert html to markdown before save to obsidian
1 parent 6e949bb commit bef80de

File tree

4 files changed

+84
-2
lines changed

4 files changed

+84
-2
lines changed

apps/renderer/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
"franc-min": "6.2.0",
6363
"fuse.js": "7.0.0",
6464
"hast-util-to-jsx-runtime": "2.3.2",
65+
"hast-util-to-mdast": "^10.1.0",
6566
"hast-util-to-text": "4.0.2",
6667
"i18next": "^23.16.0",
6768
"i18next-browser-languagedetector": "8.0.0",
@@ -72,6 +73,7 @@
7273
"lethargy": "1.0.9",
7374
"lodash-es": "4.17.21",
7475
"masonic": "4.0.1",
76+
"mdast-util-to-markdown": "^2.1.0",
7577
"nanoid": "5.0.7",
7678
"ofetch": "1.4.1",
7779
"path-to-regexp": "8.2.0",

apps/renderer/src/hooks/biz/useEntryActions.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import { shortcuts } from "~/constants/shortcuts"
3333
import { tipcClient } from "~/lib/client"
3434
import { nextFrame } from "~/lib/dom"
3535
import { FeedViewType } from "~/lib/enum"
36+
import { parseHtml } from "~/lib/parse-html"
3637
import { getOS } from "~/lib/utils"
3738
import StarAnimationUri from "~/lottie/star.lottie?url"
3839
import type { CombinedEntryModel } from "~/models"
@@ -427,7 +428,7 @@ export const useEntryActions = ({
427428
saveToObsidian.mutate({
428429
url: populatedEntry.entries.url,
429430
title: populatedEntry.entries.title || "",
430-
content: populatedEntry.entries.content || "",
431+
content: parseHtml(populatedEntry.entries.content || "").toMarkdown(),
431432
author: populatedEntry.entries.author || "",
432433
publishedAt: populatedEntry.entries.publishedAt || "",
433434
vaultPath: obsidianVaultPath,

apps/renderer/src/lib/parse-html.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ import type { Element, Parent, Text } from "hast"
22
import type { Schema } from "hast-util-sanitize"
33
import type { Components } from "hast-util-to-jsx-runtime"
44
import { toJsxRuntime } from "hast-util-to-jsx-runtime"
5+
import { toMdast } from "hast-util-to-mdast"
56
import { toText } from "hast-util-to-text"
7+
import { toMarkdown } from "mdast-util-to-markdown"
68
import { createElement } from "react"
79
import { Fragment, jsx, jsxs } from "react/jsx-runtime"
810
import { renderToString } from "react-dom/server"
@@ -235,6 +237,7 @@ export const parseHtml = (
235237
},
236238
}),
237239
toText: () => toText(hastTree),
240+
toMarkdown: () => toMarkdown(toMdast(hastTree)),
238241
}
239242
}
240243

pnpm-lock.yaml

Lines changed: 77 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)