starlight-links-validator 0.4.1 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/libs/remark.ts +16 -2
  2. package/package.json +1 -1
package/libs/remark.ts CHANGED
@@ -24,8 +24,13 @@ export const remarkStarlightLinksValidator: Plugin<[], Root> = function () {
24
24
 
25
25
  const fileHeadings: string[] = []
26
26
  const fileLinks: string[] = []
27
+ const fileDefinitions = new Map<string, string>()
27
28
 
28
- visit(tree, ['heading', 'html', 'link', 'mdxJsxFlowElement', 'mdxJsxTextElement'], (node) => {
29
+ visit(tree, 'definition', (node) => {
30
+ fileDefinitions.set(node.identifier, node.url)
31
+ })
32
+
33
+ visit(tree, ['heading', 'html', 'link', 'linkReference', 'mdxJsxFlowElement', 'mdxJsxTextElement'], (node) => {
29
34
  // https://github.com/syntax-tree/mdast#nodes
30
35
  // https://github.com/syntax-tree/mdast-util-mdx-jsx#nodes
31
36
  switch (node.type) {
@@ -47,6 +52,15 @@ export const remarkStarlightLinksValidator: Plugin<[], Root> = function () {
47
52
 
48
53
  break
49
54
  }
55
+ case 'linkReference': {
56
+ const definition = fileDefinitions.get(node.identifier)
57
+
58
+ if (definition && isInternalLink(definition)) {
59
+ fileLinks.push(definition)
60
+ }
61
+
62
+ break
63
+ }
50
64
  case 'mdxJsxFlowElement': {
51
65
  for (const attribute of node.attributes) {
52
66
  if (isMdxIdAttribute(attribute)) {
@@ -130,7 +144,7 @@ function normalizeFilePath(filePath?: string) {
130
144
  .replace(/\.\w+$/, '')
131
145
  .replace(/index$/, '')
132
146
  .replace(/\/?$/, '/')
133
- .split('/')
147
+ .split(/[/\\]/)
134
148
  .map((segment) => slug(segment))
135
149
  .join('/')
136
150
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "starlight-links-validator",
3
- "version": "0.4.1",
3
+ "version": "0.4.2",
4
4
  "license": "MIT",
5
5
  "description": "Astro integration for Starlight to validate internal links.",
6
6
  "author": "HiDeoo <github@hideoo.dev> (https://hideoo.dev)",