1+ import { BasicBlocksKit } from "@/components/editor/plugins/basic-blocks-kit" ;
2+ import { BasicMarksKit } from "@/components/editor/plugins/basic-marks-kit" ;
3+ import { CodeBlockKit } from "@/components/editor/plugins/code-block-kit" ;
4+ import { FixedToolbarKit } from "@/components/editor/plugins/fixed-toolbar-kit" ;
5+ import { FloatingToolbarKit } from "@/components/editor/plugins/floating-toolbar-kit" ;
6+ import { FontKit } from "@/components/editor/plugins/font-kit" ;
7+ import { LinkKit } from "@/components/editor/plugins/link-kit" ;
8+ import { ListKit } from "@/components/editor/plugins/list-kit" ;
9+ import { MathKit } from "@/components/editor/plugins/math-kit" ;
10+ import { TableKit } from "@/components/editor/plugins/table-kit" ;
111import { Serialized } from "@/types/node" ;
212import { Path } from "@/utils/path" ;
13+ import { MarkdownPlugin } from "@platejs/markdown" ;
314import { readFile } from "@tauri-apps/plugin-fs" ;
15+ import { createPlateEditor } from "platejs/react" ;
16+ import remarkBreaks from "remark-breaks" ;
17+ import remarkGfm from "remark-gfm" ;
18+ import remarkMath from "remark-math" ;
419import { v4 as uuidv4 } from "uuid" ;
520import { URI } from "vscode-uri" ;
621
@@ -338,12 +353,32 @@ export namespace ProjectUpgrader {
338353 b : arr [ 2 ] ,
339354 a : arr [ 3 ] ,
340355 } ) ;
341-
342356 const toVector = ( arr : number [ ] ) => ( {
343357 _ : "Vector" ,
344358 x : arr [ 0 ] ,
345359 y : arr [ 1 ] ,
346360 } ) ;
361+ const toDetails = ( md : string ) => {
362+ const editor = createPlateEditor ( {
363+ plugins : [
364+ ...FloatingToolbarKit ,
365+ ...FixedToolbarKit ,
366+ ...BasicMarksKit ,
367+ ...BasicBlocksKit ,
368+ ...FontKit ,
369+ ...TableKit ,
370+ ...MathKit ,
371+ ...CodeBlockKit ,
372+ ...ListKit ,
373+ ...LinkKit ,
374+ MarkdownPlugin ,
375+ ] ,
376+ } ) ;
377+ const value = editor . api . markdown . deserialize ( md , {
378+ remarkPlugins : [ remarkGfm , remarkMath , remarkBreaks ] ,
379+ } ) ;
380+ return value ;
381+ } ;
347382
348383 // Recursively convert all entities
349384 async function convertEntityVAnyToN1 (
@@ -363,7 +398,7 @@ export namespace ProjectUpgrader {
363398 _ : "TextNode" ,
364399 uuid : entity . uuid ,
365400 text : entity . text ,
366- details : entity . details ,
401+ details : toDetails ( entity . details ) ,
367402 collisionBox : {
368403 _ : "CollisionBox" ,
369404 shapes : [
@@ -399,7 +434,7 @@ export namespace ProjectUpgrader {
399434 _ : "Section" ,
400435 uuid : entity . uuid ,
401436 text : entity . text ,
402- details : entity . details ,
437+ details : toDetails ( entity . details ) ,
403438 isCollapsed : entity . isCollapsed ,
404439 isHidden : entity . isHidden ,
405440 children,
@@ -432,7 +467,7 @@ export namespace ProjectUpgrader {
432467 _ : "ImageNode" ,
433468 uuid : entity . uuid ,
434469 attachmentId,
435- details : entity . details ,
470+ details : toDetails ( entity . details ) ,
436471 collisionBox : {
437472 _ : "CollisionBox" ,
438473 shapes : [
0 commit comments