Yuki Takei 2 лет назад
Родитель
Сommit
7a9ee8450b

+ 33 - 34
apps/app/src/services/renderer/rehype-plugins/relative-links.spec.ts

@@ -1,10 +1,9 @@
-import { describe, test, expect } from 'vitest';
 
 import { select, type HastNode } from 'hast-util-select';
-
-import { unified } from 'unified';
 import parse from 'remark-parse';
 import remarkRehype from 'remark-rehype';
+import { unified } from 'unified';
+import { describe, test, expect } from 'vitest';
 
 import { relativeLinks } from './relative-links';
 
@@ -16,20 +15,20 @@ describe('relativeLinks', () => {
       ${'#header'}
     `('leaves the original href \'$originalHref\' as-is', ({ originalHref }) => {
 
-      // setup
-      const processor = unified()
-        .use(parse)
-        .use(remarkRehype)
-        .use(relativeLinks, {});
+    // setup
+    const processor = unified()
+      .use(parse)
+      .use(remarkRehype)
+      .use(relativeLinks, {});
 
-      // when
-      const mdastTree = processor.parse(`[link](${originalHref})`);
-      const hastTree = processor.runSync(mdastTree) as HastNode;
+    // when
+    const mdastTree = processor.parse(`[link](${originalHref})`);
+    const hastTree = processor.runSync(mdastTree) as HastNode;
 
-      // then
-      const anchorElement = select('a', hastTree);
-      expect(anchorElement?.properties?.href).toBe(originalHref);
-    });
+    // then
+    const anchorElement = select('a', hastTree);
+    expect(anchorElement?.properties?.href).toBe(originalHref);
+  });
 
   test.concurrent.each`
     originalHref                        | expectedHref
@@ -43,22 +42,22 @@ describe('relativeLinks', () => {
       ${'./Sandbox?q=foo#header'}       | ${'/foo/bar/Sandbox?q=foo#header'}
     `('rewrites the original href \'$originalHref\' to \'$expectedHref\'', ({ originalHref, expectedHref }) => {
 
-      // setup
-      const pagePath = '/foo/bar/baz';
-      const processor = unified()
-        .use(parse)
-        .use(remarkRehype)
-        .use(relativeLinks, { pagePath });
-
-      // when
-      const mdastTree = processor.parse(`[link](${originalHref})`);
-      const hastTree = processor.runSync(mdastTree) as HastNode;
-
-      // then
-      const anchorElement = select('a', hastTree);
-      expect(anchorElement).not.toBeNull();
-      expect(anchorElement?.properties).not.toBeNull();
-      expect(anchorElement?.properties?.href).toBe(expectedHref);
-    });
-
-})
+    // setup
+    const pagePath = '/foo/bar/baz';
+    const processor = unified()
+      .use(parse)
+      .use(remarkRehype)
+      .use(relativeLinks, { pagePath });
+
+    // when
+    const mdastTree = processor.parse(`[link](${originalHref})`);
+    const hastTree = processor.runSync(mdastTree) as HastNode;
+
+    // then
+    const anchorElement = select('a', hastTree);
+    expect(anchorElement).not.toBeNull();
+    expect(anchorElement?.properties).not.toBeNull();
+    expect(anchorElement?.properties?.href).toBe(expectedHref);
+  });
+
+});

+ 1 - 1
apps/app/src/services/renderer/rehype-plugins/relative-links.ts

@@ -18,7 +18,7 @@ const defaultUrlResolver: IUrlResolver = (relativeHref, basePath) => {
 const urlToHref = (url: URL): string => {
   const { pathname, search, hash } = url;
   return `${pathname}${search}${hash}`;
-}
+};
 
 const isAnchorLink = (href: string): boolean => {
   return href.toString().length > 0 && href[0] === '#';