修复md导入问题
This commit is contained in:
@@ -3,7 +3,6 @@
|
||||
import React, { createContext, useContext, useRef, useState, useCallback } from "react";
|
||||
import { useEditorStore } from "@/lib/store";
|
||||
import JSZip from "jszip";
|
||||
import { markdownToImportHtml } from "@/lib/markdown-import";
|
||||
|
||||
interface ImportContextType {
|
||||
triggerImport: (parentId?: string | null) => void;
|
||||
@@ -130,7 +129,7 @@ export function ImportProvider({ children }: { children: React.ReactNode }) {
|
||||
const handleSingleFileImport = async (file: File) => {
|
||||
const text = await file.text();
|
||||
const title = file.name.replace(/\.md$/i, "");
|
||||
const html = markdownToImportHtml(text);
|
||||
// 直接存储原始 Markdown,tiptap-markdown 扩展会在编辑器加载时自动解析
|
||||
const parentId = targetParentIdRef.current;
|
||||
const existing = pages.find((p) => p.type === "file" && p.parentId === parentId && (p.title || "").trim() === title.trim());
|
||||
if (existing) {
|
||||
@@ -138,8 +137,7 @@ export function ImportProvider({ children }: { children: React.ReactNode }) {
|
||||
existing.id,
|
||||
{
|
||||
title,
|
||||
content: html,
|
||||
importMarkdown: text,
|
||||
content: text,
|
||||
parentId,
|
||||
type: "file",
|
||||
},
|
||||
@@ -151,8 +149,7 @@ export function ImportProvider({ children }: { children: React.ReactNode }) {
|
||||
await postPage(
|
||||
{
|
||||
title,
|
||||
content: html,
|
||||
importMarkdown: text,
|
||||
content: text,
|
||||
parentId,
|
||||
type: "file",
|
||||
},
|
||||
@@ -252,15 +249,13 @@ export function ImportProvider({ children }: { children: React.ReactNode }) {
|
||||
|
||||
const markdown = await zipFile.async("string");
|
||||
const title = fileName.replace(/\.md$/i, "").replace(/\.txt$/i, "");
|
||||
const html = markdownToImportHtml(markdown);
|
||||
const existing = pages.find((p) => p.type === "file" && p.parentId === parentId && (p.title || "").trim() === title.trim());
|
||||
if (existing) {
|
||||
await putPage(
|
||||
existing.id,
|
||||
{
|
||||
title,
|
||||
content: html,
|
||||
importMarkdown: markdown,
|
||||
content: markdown,
|
||||
parentId,
|
||||
type: "file",
|
||||
},
|
||||
@@ -270,8 +265,7 @@ export function ImportProvider({ children }: { children: React.ReactNode }) {
|
||||
await postPage(
|
||||
{
|
||||
title,
|
||||
content: html,
|
||||
importMarkdown: markdown,
|
||||
content: markdown,
|
||||
parentId,
|
||||
type: "file",
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user