@lexibase/rdx-core 3.6.1 → 3.6.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.
@@ -77,7 +77,7 @@ function walk(node, visit) {
77
77
  visit(node);
78
78
  for (const child of node.children ?? []) walk(child, visit);
79
79
  }
80
- function parse(content, markdown) {
80
+ function parse(content, markdown, duplicateAnchor) {
81
81
  const processor = markdown ? markdownParser : parser;
82
82
  const tree = processor.runSync(processor.parse(content), {
83
83
  value: content
@@ -92,7 +92,17 @@ function parse(content, markdown) {
92
92
  definitions.set(identifier(node.identifier), node.url);
93
93
  });
94
94
  walk(tree, (node) => {
95
- if (node.type === "heading") anchors.add(slugger.slug(headingText(node)));
95
+ const nodeAnchors = /* @__PURE__ */ new Set();
96
+ if (node.type === "heading")
97
+ nodeAnchors.add(slugger.slug(headingText(node)));
98
+ for (const attribute of node.attributes ?? []) {
99
+ if (typeof attribute.value === "string" && (attribute.name === "id" || node.name === "a" && attribute.name === "name"))
100
+ nodeAnchors.add(attribute.value);
101
+ }
102
+ for (const id of nodeAnchors) {
103
+ if (anchors.has(id)) duplicateAnchor(id, node.position);
104
+ anchors.add(id);
105
+ }
96
106
  if (node.type === "link" || node.type === "image") {
97
107
  if (typeof node.url === "string")
98
108
  references.push({
@@ -113,8 +123,8 @@ function parse(content, markdown) {
113
123
  if (!node.type.startsWith("mdxJsx")) return;
114
124
  for (const attribute of node.attributes ?? []) {
115
125
  if (attribute.name === "id" || node.name === "a" && attribute.name === "name") {
116
- if (typeof attribute.value === "string") anchors.add(attribute.value);
117
- else if (attribute.value) dynamicIds = true;
126
+ if (attribute.value && typeof attribute.value !== "string")
127
+ dynamicIds = true;
118
128
  }
119
129
  if ((node.name === "a" && attribute.name === "href" || node.name === "img" && attribute.name === "src") && typeof attribute.value === "string") {
120
130
  references.push({
@@ -155,6 +165,17 @@ function checkDocumentation(project, options = {}) {
155
165
  message: value.message ?? String(error)
156
166
  });
157
167
  }
168
+ function parseDocument(content, file, offset) {
169
+ return parse(content, file.endsWith(".md"), (id, position) => {
170
+ diagnostics.push({
171
+ file: relativeFile(file),
172
+ line: (position?.start.line ?? 1) + offset,
173
+ column: position?.start.column ?? 1,
174
+ code: "anchor",
175
+ message: `Duplicate section ID "${id}". Use a unique ID for each destination on this page.`
176
+ });
177
+ });
178
+ }
158
179
  const publicRoot = path.resolve(project.rootDir, "public");
159
180
  const publicDirectories = /* @__PURE__ */ new Map();
160
181
  function findPublicFile(pathname) {
@@ -313,7 +334,11 @@ function checkDocumentation(project, options = {}) {
313
334
  const releaseChecks = releases.flatMap((release) => {
314
335
  changelogAnchors.add(`v${release.version}`);
315
336
  try {
316
- const parsed = parse(release.content, release.sourcePath.endsWith(".md"));
337
+ const parsed = parseDocument(
338
+ release.content,
339
+ release.sourcePath,
340
+ release.lineOffset
341
+ );
317
342
  for (const anchor of parsed.anchors) changelogAnchors.add(anchor);
318
343
  changelogHasUnknownAnchors ||= parsed.dynamicIds;
319
344
  return [{ release, parsed }];
@@ -340,7 +365,11 @@ function checkDocumentation(project, options = {}) {
340
365
  const raw = fs.readFileSync(document.page.sourcePath, "utf8");
341
366
  const { content, data } = parseStaticDocument(raw);
342
367
  document.lineOffset = (raw.slice(0, raw.length - content.length).match(/\n/g) ?? []).length;
343
- document.parsed = parse(content, document.page.sourcePath.endsWith(".md"));
368
+ document.parsed = parseDocument(
369
+ content,
370
+ document.page.sourcePath,
371
+ document.lineOffset
372
+ );
344
373
  for (const field of ["related", "prerequisites"]) {
345
374
  try {
346
375
  document.parsed.references.push(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lexibase/rdx-core",
3
- "version": "3.6.1",
3
+ "version": "3.6.2",
4
4
  "description": "Content indexing and document utilities for RDX documentation projects.",
5
5
  "license": "MIT",
6
6
  "type": "module",