reiji-h 1 год назад
Родитель
Сommit
4d350ef5f9

+ 5 - 5
apps/app/src/features/mermaid/services/mermaid.ts

@@ -1,9 +1,9 @@
 import type { Schema as SanitizeOption } from 'hast-util-sanitize';
 import type { Schema as SanitizeOption } from 'hast-util-sanitize';
-import { Plugin } from 'unified';
-import { Node } from 'unist';
+import type { Code } from 'mdast';
+import type { Plugin } from 'unified';
 import { visit } from 'unist-util-visit';
 import { visit } from 'unist-util-visit';
 
 
-function rewriteNode(node: Node) {
+function rewriteNode(node: Code) {
   // replace node
   // replace node
   const data = node.data ?? (node.data = {});
   const data = node.data ?? (node.data = {});
   data.hName = 'mermaid';
   data.hName = 'mermaid';
@@ -12,8 +12,8 @@ function rewriteNode(node: Node) {
 export const remarkPlugin: Plugin = function() {
 export const remarkPlugin: Plugin = function() {
   return (tree) => {
   return (tree) => {
     visit(tree, (node) => {
     visit(tree, (node) => {
-      if (node.type === 'code' && node.lang === 'mermaid') {
-        rewriteNode(node);
+      if (node.type === 'code' && (node as Code).lang === 'mermaid') {
+        rewriteNode(node as Code);
       }
       }
     });
     });
   };
   };

+ 5 - 4
apps/app/src/services/renderer/remark-plugins/xsv-to-table.ts

@@ -1,4 +1,5 @@
 import csvToMarkdownTable from 'csv-to-markdown-table';
 import csvToMarkdownTable from 'csv-to-markdown-table';
+import type { Code, Table } from 'mdast';
 import { fromMarkdown } from 'mdast-util-from-markdown';
 import { fromMarkdown } from 'mdast-util-from-markdown';
 import { gfmTableFromMarkdown } from 'mdast-util-gfm-table';
 import { gfmTableFromMarkdown } from 'mdast-util-gfm-table';
 import { gfmTable } from 'micromark-extension-gfm-table';
 import { gfmTable } from 'micromark-extension-gfm-table';
@@ -8,7 +9,7 @@ import { visit } from 'unist-util-visit';
 
 
 type Lang = 'csv' | 'csv-h' | 'tsv' | 'tsv-h';
 type Lang = 'csv' | 'csv-h' | 'tsv' | 'tsv-h';
 
 
-function isXsv(lang: unknown): lang is Lang {
+function isXsv(lang?: string | null | undefined): lang is Lang {
   return /^(csv|csv-h|tsv|tsv-h)$/.test(lang as string);
   return /^(csv|csv-h|tsv|tsv-h)$/.test(lang as string);
 }
 }
 
 
@@ -28,7 +29,7 @@ function rewriteNode(node: Node, lang: Lang) {
   // replace node
   // replace node
   if (tableTree.children[0] != null) {
   if (tableTree.children[0] != null) {
     node.type = 'table';
     node.type = 'table';
-    node.children = tableTree.children[0].children;
+    (node as Table).children = tableTree.children[0].children;
   }
   }
 }
 }
 
 
@@ -36,8 +37,8 @@ export const remarkPlugin: Plugin = function() {
   return (tree) => {
   return (tree) => {
     visit(tree, (node) => {
     visit(tree, (node) => {
       if (node.type === 'code') {
       if (node.type === 'code') {
-        if (isXsv(node.lang)) {
-          rewriteNode(node, node.lang);
+        if (isXsv((node as Code).lang)) {
+          rewriteNode((node as Code), (node as Code).lang as Lang);
         }
         }
       }
       }
     });
     });