File tree 2 files changed +20
-0
lines changed
2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change
1
+ import { existsSync } from "fs" ;
2
+ import { visit } from "unist-util-visit" ;
3
+ import url from "url" ;
4
+
5
+
6
+ const rehypeLinkTransformer = ( ) => ( tree , vfile ) => {
7
+ visit ( tree , "element" , ( node ) => {
8
+ if ( node . tagName === "a" ) {
9
+ const href = url . parse ( node . properties . href ) ;
10
+ if ( href . hostname === null && href . pathname ?. endsWith ( ".md" ) && existsSync ( vfile . history [ 0 ] ) ) {
11
+ href . pathname = href . pathname . replace ( / .m d $ / , ".html" ) ;
12
+ node . properties . href = url . format ( href ) ;
13
+ }
14
+ }
15
+ } ) ;
16
+ } ;
17
+
18
+ export default rehypeLinkTransformer ;
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ import remarkRehype from "remark-rehype";
6
6
import rehypeStringify from "rehype-stringify" ;
7
7
import rehypeDocument from "rehype-document" ;
8
8
import specsPreset from "./.remarkrc-specs.js" ;
9
+ import rehypeLinkTransformer from "../remark/rehype-link-transformer.js" ;
9
10
10
11
11
12
dotenv . config ( ) ;
@@ -15,6 +16,7 @@ export default {
15
16
specsPreset ,
16
17
remarkTorchLight ,
17
18
remarkRehype ,
19
+ rehypeLinkTransformer ,
18
20
[ rehypeDocument , {
19
21
css : [ "https://cdn.jsdelivr.net/npm/water.css@2/out/dark.css" ] ,
20
22
style : readFileSync ( resolve ( import . meta. dirname , "spec.css" ) , "utf8" )
You can’t perform that action at this time.
0 commit comments