We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 0f09d35 commit 49d53abCopy full SHA for 49d53ab
remark/rehype-link-transformer.js
@@ -1,14 +1,15 @@
1
-import { existsSync } from "fs";
+import { existsSync } from "node:fs";
2
+import { basename } from "node:path";
3
+import url from "node:url";
4
import { visit } from "unist-util-visit";
-import url from "url";
5
6
7
const rehypeLinkTransformer = () => (tree, vfile) => {
8
visit(tree, "element", (node) => {
9
if (node.tagName === "a") {
10
const href = url.parse(node.properties.href);
11
if (href.hostname === null && href.pathname?.endsWith(".md") && existsSync(vfile.history[0])) {
- href.pathname = href.pathname.replace(/.md$/, ".html");
12
+ href.pathname = basename(href.pathname).replace(/.md$/, ".html");
13
node.properties.href = url.format(href);
14
}
15
0 commit comments