Просмотр исходного кода

create method to replace <ol> to <ul>

yuken 3 лет назад
Родитель
Сommit
0a6d0a2733
1 измененных файлов с 16 добавлено и 1 удалено
  1. 16 1
      packages/app/src/services/renderer/renderer.tsx

+ 16 - 1
packages/app/src/services/renderer/renderer.tsx

@@ -242,8 +242,23 @@ export const generateViewOptions = (
   // store toc node
   // store toc node
   if (rehypePlugins != null) {
   if (rehypePlugins != null) {
     rehypePlugins.push([toc, {
     rehypePlugins.push([toc, {
+      nav: false,
       headings: ['h1', 'h2', 'h3'],
       headings: ['h1', 'h2', 'h3'],
-      customizeTOC: storeTocNode,
+      customizeTOC: (toc: HtmlElementNode) => {
+        // method for replace <ol> to <ul>
+        const replacer = (children) => {
+          children.forEach((child) => {
+            if (child.type === 'element' && child.tagName === 'ol') {
+              child.tagName = 'ul';
+            }
+            if (child.children) {
+              replacer(child.children);
+            }
+          });
+        };
+        replacer([toc]); // replace <ol> to <ul>
+        storeTocNode(toc); // store tocNode to global state with swr
+      },
     }]);
     }]);
   }
   }
   // renderer.rehypePlugins.push([autoLinkHeadings, {
   // renderer.rehypePlugins.push([autoLinkHeadings, {