Skip to content

Commit b7e552d

Browse files
authored
Match links with anchors (#79)
1 parent 86138cb commit b7e552d

3 files changed

Lines changed: 71 additions & 3 deletions

File tree

cli.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,18 +59,21 @@ if (core.getBooleanInput("preprocess")) {
5959
console.log("Moved README.md to Home.md");
6060
}
6161

62-
const mdRe = /\.(?:md|markdown|mdown|mkdn|mkd|mdwn|mkdown|ron)$/;
62+
const mdRe = /\.(?:md|markdown|mdown|mkdn|mkd|mdwn|mkdown|ron)([:\/\?#\[\]@].*)?$/;
6363
const plugin = () => (tree: any) =>
6464
visit(tree, ["link", "linkReference"], (node: any) => {
65-
if (!mdRe.test(node.url)) {
65+
const matches = node.url?.match(mdRe)
66+
if (!matches) {
6667
return;
6768
}
6869
if (!new URL(node.url, "file:///-/").href.startsWith("file:///-/")) {
6970
return;
7071
}
7172

7273
const x = node.url;
73-
node.url = node.url.replace(mdRe, "");
74+
node.url = matches.length === 2
75+
? node.url.replace(mdRe, "$1")
76+
: node.url.replace(mdRe, "");
7477
if (new URL(node.url, "file:///-/").href === "file:///-/README") {
7578
node.url = "Home";
7679
}

wiki/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
👋 Hello! If you're seeing this in the <kbd>Wiki</kbd> tab, then the GitHub
22
Action successfully pushed the contents of the `wiki/` folder to the GitHub
33
wiki. 🥳
4+
5+
Check [this other page out](./another-page.md)!
6+
[This section](./another-page.md#some_impꗝrtant_stuff-) is also pretty important

wiki/another-page.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
Here's another page!
2+
3+
- Here's a really long list to ensure our link fragments sends us down to the header
4+
- 1
5+
- 1
6+
- 1
7+
- 1
8+
- 1
9+
- 1
10+
- 1
11+
- 1
12+
- 1
13+
- 1
14+
- 1
15+
- 1
16+
- 1
17+
- 1
18+
- 1
19+
- 1
20+
- 1
21+
- 1
22+
- 1
23+
- 1
24+
- 1
25+
- 1
26+
- 1
27+
- 1
28+
- 1
29+
- 1
30+
- 1
31+
- 1
32+
- 1
33+
- 1
34+
- 1
35+
- 1
36+
- 1
37+
- 1
38+
- 1
39+
- 1
40+
- 1
41+
- 1
42+
- 1
43+
- 1
44+
- 1
45+
- 1
46+
- 1
47+
- 1
48+
- 1
49+
- 1
50+
- 1
51+
- 1
52+
- 1
53+
- 1
54+
- 1
55+
- 1
56+
- 1
57+
- 1
58+
59+
60+
## Some_"impꗝrtant"_stuff~~~!!! 🥳
61+
62+
It's not really, but we gotta give this a try.

0 commit comments

Comments
 (0)