reiji-h 1 год назад
Родитель
Сommit
59ea1bb359
1 измененных файлов с 8 добавлено и 7 удалено
  1. 8 7
      apps/app/src/services/renderer/remark-plugins/attachment.ts

+ 8 - 7
apps/app/src/services/renderer/remark-plugins/attachment.ts

@@ -1,8 +1,9 @@
 import path from 'path';
 
-import { Schema as SanitizeOption } from 'hast-util-sanitize';
-import { Plugin } from 'unified';
-import { Node } from 'unist';
+import type { Schema as SanitizeOption } from 'hast-util-sanitize';
+import type { Link } from 'mdast';
+import type { Plugin } from 'unified';
+import type { Node } from 'unist';
 import { visit } from 'unist-util-visit';
 
 const SUPPORTED_ATTRIBUTES = ['attachmentId', 'url', 'attachmentName'];
@@ -13,14 +14,14 @@ const isAttachmentLink = (url: string): boolean => {
   return attachmentUrlFormat.test(url);
 };
 
-const rewriteNode = (node: Node) => {
+const rewriteNode = (node: Link) => {
   const attachmentId = path.basename(node.url as string);
   const data = node.data ?? (node.data = {});
   data.hName = 'attachment';
   data.hProperties = {
     attachmentId,
     url: node.url,
-    attachmentName: (node.children as any)[0]?.value,
+    attachmentName: node.children[0] ?? '',
   };
 };
 
@@ -29,8 +30,8 @@ export const remarkPlugin: Plugin = () => {
   return (tree) => {
     visit(tree, (node) => {
       if (node.type === 'link') {
-        if (isAttachmentLink(node.url as string)) {
-          rewriteNode(node);
+        if (isAttachmentLink((node as Link).url as string)) {
+          rewriteNode(node as Link);
         }
       }
     });