Browse Source

Fixed type HastNode => HtmlElementNode

Taichi Masuyama 3 years ago
parent
commit
93180c59b3

+ 4 - 5
packages/app/src/services/renderer/renderer.ts

@@ -1,12 +1,11 @@
 import { MutableRefObject } from 'react';
 
-import { HastNode } from 'hast-util-select';
 import { ReactMarkdownOptions } from 'react-markdown/lib/react-markdown';
 import katex from 'rehype-katex';
 import raw from 'rehype-raw';
 import sanitize, { defaultSchema as sanitizeDefaultSchema } from 'rehype-sanitize';
 import slug from 'rehype-slug';
-import toc from 'rehype-toc';
+import toc, { HtmlElementNode } from 'rehype-toc';
 import breaks from 'remark-breaks';
 import emoji from 'remark-emoji';
 import gfm from 'remark-gfm';
@@ -248,7 +247,7 @@ const generateCommonOptions = (pagePath: string|undefined, config: RendererConfi
 export const generateViewOptions = (
     pagePath: string,
     config: RendererConfig,
-    tocRef: MutableRefObject<HastNode | undefined>,
+    tocRef: MutableRefObject<HtmlElementNode | undefined>,
 ): RendererOptions => {
 
   const options = generateCommonOptions(pagePath, config);
@@ -270,7 +269,7 @@ export const generateViewOptions = (
     rehypePlugins.push([toc, {
       nav: false,
       headings: ['h1', 'h2', 'h3'],
-      customizeTOC: (toc: HastNode) => {
+      customizeTOC: (toc: HtmlElementNode) => {
         // method for replace <ol> to <ul>
         const replacer = (children) => {
           children.forEach((child) => {
@@ -318,7 +317,7 @@ export const generateViewOptions = (
   return options;
 };
 
-export const generateTocOptions = (config: RendererConfig, tocNode: HastNode | undefined): RendererOptions => {
+export const generateTocOptions = (config: RendererConfig, tocNode: HtmlElementNode | undefined): RendererOptions => {
 
   const options = generateCommonOptions(undefined, config);
 

+ 2 - 2
packages/app/src/stores/context.tsx

@@ -1,4 +1,4 @@
-import { HastNode } from 'hast-util-select';
+import { HtmlElementNode } from 'rehype-toc';
 import { Key, SWRResponse } from 'swr';
 import useSWRImmutable from 'swr/immutable';
 
@@ -273,7 +273,7 @@ export const useIsEditable = (): SWRResponse<boolean, Error> => {
   );
 };
 
-export const useCurrentPageTocNode = (): SWRResponse<HastNode, any> => {
+export const useCurrentPageTocNode = (): SWRResponse<HtmlElementNode, any> => {
   const { data: currentPagePath } = useCurrentPagePath();
 
   return useStaticSWR(['currentPageTocNode', currentPagePath]);

+ 2 - 2
packages/app/src/stores/renderer.tsx

@@ -1,6 +1,6 @@
 import { useEffect, useRef } from 'react';
 
-import { HastNode } from 'hast-util-select';
+import { HtmlElementNode } from 'rehype-toc';
 import { Key, SWRResponse } from 'swr';
 import useSWRImmutable from 'swr/immutable';
 
@@ -49,7 +49,7 @@ export const useViewOptions = (): SWRResponse<RendererOptions, Error> => {
 
   // Pass tocRef to generateViewOptions (=> rehypePlugin => customizeTOC) to call mutateCurrentPageTocNode when tocRef.current changes.
   // The toc node passed by customizeTOC is assigned to tocRef.current.
-  const tocRef = useRef<HastNode>();
+  const tocRef = useRef<HtmlElementNode>();
 
   const isAllDataValid = currentPagePath != null && rendererConfig != null;