reiji-h před 1 rokem
rodič
revize
59ea1bb359

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

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