1+ import path from 'node:path' ;
12import rehypeStringify from 'rehype-stringify' ;
3+ import remarkMdx from 'remark-mdx' ;
24import remarkParse from 'remark-parse' ;
35import remarkRehype from 'remark-rehype' ;
6+ import remarkStringify from 'remark-stringify' ;
47import { unified } from 'unified' ;
8+ import { VFile } from 'vfile' ;
59import { describe , expect , test } from 'vitest' ;
10+ import { remarkPluginNormalizeLink } from '../src/node/mdx/remarkPlugins/normalizeLink' ;
611
712describe ( 'Markdown compile cases' , ( ) => {
813 const processor = unified ( )
@@ -15,4 +20,35 @@ describe('Markdown compile cases', () => {
1520 const result = processor . processSync ( mdContent ) ;
1621 expect ( result . value ) . toMatchInlineSnapshot ( '"<h1>123</h1>"' ) ;
1722 } ) ;
23+
24+ describe ( 'remarkPluginNormalizeLink' , ( ) => {
25+ it ( 'should just work' , ( ) => {
26+ const processor = unified ( )
27+ . use ( remarkParse )
28+ . use ( remarkMdx )
29+ . use ( remarkPluginNormalizeLink , {
30+ root : process . cwd ( ) ,
31+ cleanUrls : false ,
32+ } )
33+ . use ( remarkStringify ) ;
34+
35+ const result = processor . processSync (
36+ new VFile ( {
37+ value : `
38+ [link1](./test1.md)
39+
40+ {/* jsx link will not be transformed */}
41+
42+ <a href="./test2">link2</a>
43+
44+ 
45+
46+ <img src="./test4.png" alt="alt2" />
47+ ` . trim ( ) ,
48+ path : path . resolve ( 'test.mdx' ) ,
49+ } ) ,
50+ ) ;
51+ expect ( result . value ) . matchSnapshot ( ) ;
52+ } ) ;
53+ } ) ;
1854} ) ;
0 commit comments