@@ -4,51 +4,67 @@ import * as assert from "uvu/assert";
4
4
import { Root , Paragraph } from "mdast" ;
5
5
import unified from "unified" ;
6
6
import markdown from "remark-parse" ;
7
+ import rehype from "remark-rehype" ;
8
+ import stringify from "rehype-stringify" ;
7
9
8
10
import { set_link_attributes } from "./links" ;
9
11
10
- const processor = unified ( ) . use ( markdown ) . use ( set_link_attributes ) ;
12
+ const { process } = unified ( )
13
+ . use ( markdown )
14
+ . use ( rehype )
15
+ . use ( set_link_attributes )
16
+ . use ( stringify ) ;
11
17
12
18
const _links = suite ( "links" ) ;
13
19
14
20
_links ( "renders link" , async ( ) => {
15
21
const src = `[a link](/local/path/to/file)` ;
16
- const output = ( await processor . run ( processor . parse ( src ) ) ) as Root ;
22
+ const output = await process ( src ) ;
17
23
18
- assert . is ( ( output . children [ 0 ] as Paragraph ) . children [ 0 ] . type , "html" ) ;
19
24
assert . is (
20
- ( output . children [ 0 ] as Paragraph ) . children [ 0 ] . value ,
21
- '<a href="http://github.com/local/path/to/file" rel="noopener noreferrer">a link</a>'
25
+ output . contents ,
26
+ '<p>< a href="http://github.com/local/path/to/file" rel="noopener noreferrer">a link</a></p >'
22
27
) ;
23
28
} ) ;
24
29
25
30
_links ( "renders link with title attribute" , async ( ) => {
26
31
const src = `[a link](/local/path/to/file "about my link")` ;
27
- const output = ( await processor . run ( processor . parse ( src ) ) ) as Root ;
32
+ const output = await process ( src ) ;
28
33
29
34
assert . is (
30
- ( output . children [ 0 ] as Paragraph ) . children [ 0 ] . value ,
31
- '<a href="http://github.com/local/path/to/file" title="about my link" rel="noopener noreferrer">a link</a>'
35
+ output . contents ,
36
+ '<p>< a href="http://github.com/local/path/to/file" title="about my link" rel="noopener noreferrer">a link</a></p >'
32
37
) ;
33
38
} ) ;
34
39
35
40
_links ( "renders external links with target _blank: no title" , async ( ) => {
36
41
const src = `[a link](https://google.com)` ;
37
- const output = ( await processor . run ( processor . parse ( src ) ) ) as Root ;
42
+ const output = await process ( src ) ;
38
43
39
44
assert . is (
40
- ( output . children [ 0 ] as Paragraph ) . children [ 0 ] . value ,
41
- '<a href="https://google.com/" target="_blank" rel="noopener noreferrer">a link</a>'
45
+ output . contents ,
46
+ '<p>< a href="https://google.com/" target="_blank" rel="noopener noreferrer">a link</a></p >'
42
47
) ;
43
48
} ) ;
44
49
45
- _links ( "renders external links with target _blank: no title" , async ( ) => {
50
+ _links ( "renders external links with target _blank: title" , async ( ) => {
46
51
const src = `[a link](https://google.com "a search engine")` ;
47
- const output = ( await processor . run ( processor . parse ( src ) ) ) as Root ;
52
+ const output = await process ( src ) ;
53
+
54
+ assert . is (
55
+ output . contents ,
56
+ '<p><a href="https://google.com" title="a search engine" target="_blank" rel="noopener noreferrer">a link</a></p>'
57
+ ) ;
58
+ } ) ;
59
+
60
+ _links ( "renders links containing multiple child nodes" , async ( ) => {
61
+ const src =
62
+ "[CommonJS packages in `noExternal`](https://github.com/vitejs/vite/issues/2579)" ;
63
+ const output = await process ( src ) ;
48
64
49
65
assert . is (
50
- ( output . children [ 0 ] as Paragraph ) . children [ 0 ] . value ,
51
- '<a href="https://google .com" target="_blank" title="a search engine" rel="noopener noreferrer">a link</a >'
66
+ output . contents ,
67
+ '<p>< a href="https://github .com/vitejs/vite/issues/2579 " target="_blank" rel="noopener noreferrer">CommonJS packages in <code>noExternal</code></a></p >'
52
68
) ;
53
69
} ) ;
54
70
0 commit comments