@lexibase/rdx-core 3.6.1 → 3.6.3

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.
@@ -2,30 +2,29 @@ import {
2
2
  collectPageRedirects,
3
3
  getDocsIndex,
4
4
  getSourceOptions
5
- } from "../chunk-EY2T3I2T.js";
5
+ } from "../chunk-YFA7NT73.js";
6
6
  import {
7
7
  changelogPluginName,
8
8
  getContentSources,
9
9
  isFallbackPage,
10
10
  parseStaticDocument,
11
11
  readChangelog
12
- } from "../chunk-OOKOB72A.js";
12
+ } from "../chunk-VVW5BNUX.js";
13
13
  import {
14
14
  RdxDocumentLinkError,
15
15
  createDocumentLinkResolver,
16
16
  readDocumentLinkField
17
17
  } from "../chunk-T27TQEAY.js";
18
18
  import {
19
- headingText
20
- } from "../chunk-FPBRKD4M.js";
19
+ getHeadingIds
20
+ } from "../chunk-GYXSGI72.js";
21
21
  import {
22
22
  remarkDocumentationComponents
23
- } from "../chunk-6WNFE2QG.js";
23
+ } from "../chunk-NQMIRIOR.js";
24
24
 
25
25
  // src/check/index.ts
26
26
  import fs from "fs";
27
27
  import path from "path";
28
- import GithubSlugger from "github-slugger";
29
28
  import remarkGfm from "remark-gfm";
30
29
  import remarkMdx from "remark-mdx";
31
30
  import remarkParse from "remark-parse";
@@ -77,7 +76,7 @@ function walk(node, visit) {
77
76
  visit(node);
78
77
  for (const child of node.children ?? []) walk(child, visit);
79
78
  }
80
- function parse(content, markdown) {
79
+ function parse(content, markdown, duplicateAnchor) {
81
80
  const processor = markdown ? markdownParser : parser;
82
81
  const tree = processor.runSync(processor.parse(content), {
83
82
  value: content
@@ -85,14 +84,24 @@ function parse(content, markdown) {
85
84
  const anchors = /* @__PURE__ */ new Set();
86
85
  const references = [];
87
86
  const definitions = /* @__PURE__ */ new Map();
88
- const slugger = new GithubSlugger();
87
+ const headingIds = getHeadingIds(tree);
89
88
  let dynamicIds = false;
90
89
  walk(tree, (node) => {
91
90
  if (node.type === "definition" && node.identifier && node.url && !definitions.has(identifier(node.identifier)))
92
91
  definitions.set(identifier(node.identifier), node.url);
93
92
  });
94
93
  walk(tree, (node) => {
95
- if (node.type === "heading") anchors.add(slugger.slug(headingText(node)));
94
+ const nodeAnchors = /* @__PURE__ */ new Set();
95
+ const headingId = headingIds.get(node);
96
+ if (headingId !== void 0) nodeAnchors.add(headingId);
97
+ for (const attribute of node.attributes ?? []) {
98
+ if (typeof attribute.value === "string" && (attribute.name === "id" || node.name === "a" && attribute.name === "name"))
99
+ nodeAnchors.add(attribute.value);
100
+ }
101
+ for (const id of nodeAnchors) {
102
+ if (anchors.has(id)) duplicateAnchor(id, node.position);
103
+ anchors.add(id);
104
+ }
96
105
  if (node.type === "link" || node.type === "image") {
97
106
  if (typeof node.url === "string")
98
107
  references.push({
@@ -113,8 +122,8 @@ function parse(content, markdown) {
113
122
  if (!node.type.startsWith("mdxJsx")) return;
114
123
  for (const attribute of node.attributes ?? []) {
115
124
  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;
125
+ if (attribute.value && typeof attribute.value !== "string")
126
+ dynamicIds = true;
118
127
  }
119
128
  if ((node.name === "a" && attribute.name === "href" || node.name === "img" && attribute.name === "src") && typeof attribute.value === "string") {
120
129
  references.push({
@@ -135,7 +144,15 @@ function checkDocumentation(project, options = {}) {
135
144
  const referencedPages = /* @__PURE__ */ new Set();
136
145
  const routes = /* @__PURE__ */ new Map();
137
146
  const coreRoutes = /* @__PURE__ */ new Map();
138
- const roots = /* @__PURE__ */ new Set(["/robots.txt", "/sitemap.xml"]);
147
+ const roots = /* @__PURE__ */ new Set([
148
+ "/robots.txt",
149
+ "/sitemap.xml",
150
+ "/docs/llms.txt"
151
+ ]);
152
+ for (const locale of project.localization?.locales ?? []) {
153
+ roots.add(`/${locale.path}/docs/llms.txt`);
154
+ if (project.config.homepage?.enabled) roots.add(`/${locale.path}`);
155
+ }
139
156
  const prefixes = [];
140
157
  const redirects = new Map(Object.entries(options.redirects ?? {}));
141
158
  const pageRedirects = /* @__PURE__ */ new Set();
@@ -155,6 +172,17 @@ function checkDocumentation(project, options = {}) {
155
172
  message: value.message ?? String(error)
156
173
  });
157
174
  }
175
+ function parseDocument(content, file, offset) {
176
+ return parse(content, file.endsWith(".md"), (id, position) => {
177
+ diagnostics.push({
178
+ file: relativeFile(file),
179
+ line: (position?.start.line ?? 1) + offset,
180
+ column: position?.start.column ?? 1,
181
+ code: "anchor",
182
+ message: `Duplicate section ID "${id}". Use a unique ID for each destination on this page.`
183
+ });
184
+ });
185
+ }
158
186
  const publicRoot = path.resolve(project.rootDir, "public");
159
187
  const publicDirectories = /* @__PURE__ */ new Map();
160
188
  function findPublicFile(pathname) {
@@ -273,8 +301,12 @@ function checkDocumentation(project, options = {}) {
273
301
  pages: []
274
302
  };
275
303
  redirectSources.push(redirectSource);
276
- if (project.config.search)
304
+ if (project.config.search) {
277
305
  roots.add(`/rdx-search/${source.routePrefix || "_"}`);
306
+ for (const locale of project.localization?.locales ?? [])
307
+ if (source.basePath === `/${locale.path}/docs`)
308
+ roots.add(`/${locale.path}/rdx-search/${source.routePrefix || "_"}`);
309
+ }
278
310
  for (const page of pages) {
279
311
  const hrefs = options.documentRoutes?.(source, page, pages) ?? [
280
312
  documentRoute(source, page)
@@ -288,6 +320,8 @@ function checkDocumentation(project, options = {}) {
288
320
  lineOffset: 0
289
321
  };
290
322
  documents.push(document);
323
+ if (!isFallbackPage(project, source, page.sourcePath))
324
+ roots.add(key(`/rdx-markdown${document.href}.md`));
291
325
  for (const href of hrefs) routes.set(key(href), document);
292
326
  coreRoutes.set(key(documentRoute(source, page)), document);
293
327
  if (page === pages[0]) {
@@ -311,9 +345,14 @@ function checkDocumentation(project, options = {}) {
311
345
  const changelogAnchors = /* @__PURE__ */ new Set();
312
346
  let changelogHasUnknownAnchors = false;
313
347
  const releaseChecks = releases.flatMap((release) => {
348
+ roots.add(`/rdx-markdown/changelog/${release.version}.md`);
314
349
  changelogAnchors.add(`v${release.version}`);
315
350
  try {
316
- const parsed = parse(release.content, release.sourcePath.endsWith(".md"));
351
+ const parsed = parseDocument(
352
+ release.content,
353
+ release.sourcePath,
354
+ release.lineOffset
355
+ );
317
356
  for (const anchor of parsed.anchors) changelogAnchors.add(anchor);
318
357
  changelogHasUnknownAnchors ||= parsed.dynamicIds;
319
358
  return [{ release, parsed }];
@@ -340,7 +379,11 @@ function checkDocumentation(project, options = {}) {
340
379
  const raw = fs.readFileSync(document.page.sourcePath, "utf8");
341
380
  const { content, data } = parseStaticDocument(raw);
342
381
  document.lineOffset = (raw.slice(0, raw.length - content.length).match(/\n/g) ?? []).length;
343
- document.parsed = parse(content, document.page.sourcePath.endsWith(".md"));
382
+ document.parsed = parseDocument(
383
+ content,
384
+ document.page.sourcePath,
385
+ document.lineOffset
386
+ );
344
387
  for (const field of ["related", "prerequisites"]) {
345
388
  try {
346
389
  document.parsed.references.push(
@@ -0,0 +1,58 @@
1
+ // src/mdx/heading-text.ts
2
+ import GithubSlugger from "github-slugger";
3
+ function headingText(node, footnotes) {
4
+ if (node.type === "footnoteReference") return footnotes.get(node) ?? "";
5
+ if (["image", "imageReference", "break"].includes(node.type)) return "";
6
+ if (node.children)
7
+ return node.children.map((child) => headingText(child, footnotes)).join("");
8
+ if (["mdxjsEsm", "mdxFlowExpression", "mdxTextExpression", "html"].includes(
9
+ node.type
10
+ ))
11
+ return "";
12
+ return node.value ?? "";
13
+ }
14
+ function getHeadingIds(tree) {
15
+ const definitions = /* @__PURE__ */ new Map();
16
+ function collect(node) {
17
+ if (node.type === "footnoteDefinition" && node.identifier) {
18
+ const id = node.identifier.toUpperCase();
19
+ if (!definitions.has(id)) definitions.set(id, node);
20
+ }
21
+ node.children?.forEach(collect);
22
+ }
23
+ collect(tree);
24
+ function walk(node, visit) {
25
+ if (node.type === "footnoteDefinition") return;
26
+ visit(node);
27
+ node.children?.forEach((child) => walk(child, visit));
28
+ }
29
+ const order = [];
30
+ const numbers = /* @__PURE__ */ new Map();
31
+ const footnotes = /* @__PURE__ */ new WeakMap();
32
+ function reference(node) {
33
+ if (node.type !== "footnoteReference" || !node.identifier) return;
34
+ const id = node.identifier.toUpperCase();
35
+ if (!numbers.has(id)) {
36
+ order.push(id);
37
+ numbers.set(id, String(order.length));
38
+ }
39
+ footnotes.set(node, numbers.get(id));
40
+ }
41
+ walk(tree, reference);
42
+ for (const id of order)
43
+ definitions.get(id)?.children?.forEach((child) => walk(child, reference));
44
+ const ids = /* @__PURE__ */ new WeakMap();
45
+ const slugger = new GithubSlugger();
46
+ function heading(node) {
47
+ if (node.type === "heading")
48
+ ids.set(node, slugger.slug(headingText(node, footnotes)));
49
+ }
50
+ walk(tree, heading);
51
+ for (const id of order)
52
+ definitions.get(id)?.children?.forEach((child) => walk(child, heading));
53
+ return ids;
54
+ }
55
+
56
+ export {
57
+ getHeadingIds
58
+ };
@@ -3,7 +3,7 @@ import {
3
3
  boundedProjectPath,
4
4
  inside,
5
5
  resolveProjectPath
6
- } from "./chunk-OOKOB72A.js";
6
+ } from "./chunk-VVW5BNUX.js";
7
7
 
8
8
  // src/config/index.ts
9
9
  import path6 from "path";
@@ -1,5 +1,22 @@
1
1
  // src/mdx/markdown-components.ts
2
2
  import remarkDirective from "remark-directive";
3
+
4
+ // src/mdx/tab-marker.ts
5
+ function hasDisabledTabMarker(children, source) {
6
+ const marker = children.at(-1);
7
+ if (!marker) return false;
8
+ const raw = source.slice(
9
+ marker.position?.start.offset,
10
+ marker.position?.end.offset
11
+ );
12
+ if (marker.type === "mdxTextExpression") {
13
+ const previous = children.at(-2);
14
+ return marker.value === "disabled" && raw === "{disabled}" && (!previous || previous.type === "text" && /\s$/.test(previous.value ?? ""));
15
+ }
16
+ return marker.type === "text" && /(?:^|\s)\{disabled\}[ \t]*$/.test(marker.value ?? "") && /(?:^|\s)\{disabled\}[ \t]*$/.test(raw);
17
+ }
18
+
19
+ // src/mdx/markdown-components.ts
3
20
  function component(name, attributes, children, inline = false) {
4
21
  return {
5
22
  type: inline ? "mdxJsxTextElement" : "mdxJsxFlowElement",
@@ -79,12 +96,15 @@ function container(node, source) {
79
96
  if (child.type === "heading" && child.depth === 3) {
80
97
  const children = [...child.children ?? []];
81
98
  const marker = children.at(-1);
82
- const beforeMarker = children.at(-2);
83
- const disabled = node.name === "tabs" && marker?.type === "mdxTextExpression" && marker.value === "disabled" && source.slice(
84
- marker.position?.start.offset,
85
- marker.position?.end.offset
86
- ) === "{disabled}" && (!beforeMarker || beforeMarker.type === "text" && /\s$/.test(beforeMarker.value ?? ""));
87
- if (disabled) children.pop();
99
+ const disabled = node.name === "tabs" && hasDisabledTabMarker(children, source);
100
+ if (disabled) {
101
+ if (marker.type === "text")
102
+ children[children.length - 1] = {
103
+ ...marker,
104
+ value: marker.value.replace(/\{disabled\}[ \t]*$/, "")
105
+ };
106
+ else children.pop();
107
+ }
88
108
  const title = label(children);
89
109
  if (!title)
90
110
  throw new Error(
@@ -207,5 +227,6 @@ function remarkDocumentationComponents() {
207
227
  }
208
228
 
209
229
  export {
230
+ hasDisabledTabMarker,
210
231
  remarkDocumentationComponents
211
232
  };
@@ -178,7 +178,39 @@ function readBadges(value) {
178
178
  return [...badges];
179
179
  }
180
180
  function isChangelogVersion(version) {
181
- return typeof version === "string" && /^\d+\.\d+\.\d+(?:-[\da-z.-]+)?(?:\+[\da-z.-]+)?$/i.test(version) && version === version.trim();
181
+ if (typeof version !== "string" || version !== version.trim()) return false;
182
+ const match = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-([\da-z-]+(?:\.[\da-z-]+)*))?(?:\+[\da-z-]+(?:\.[\da-z-]+)*)?$/i.exec(
183
+ version
184
+ );
185
+ return !!match && (match[4]?.split(".").every(
186
+ (part) => !/^\d+$/.test(part) || part === "0" || !part.startsWith("0")
187
+ ) ?? true);
188
+ }
189
+ function compareIdentifier(a, b) {
190
+ const numericA = /^\d+$/.test(a);
191
+ const numericB = /^\d+$/.test(b);
192
+ if (numericA !== numericB) return numericA ? -1 : 1;
193
+ if (numericA && a.length !== b.length) return a.length - b.length;
194
+ return a < b ? -1 : a > b ? 1 : 0;
195
+ }
196
+ function compareVersions(a, b) {
197
+ const [coreA, prereleaseA] = a.split("+", 1)[0].split(/-(.*)/, 2);
198
+ const [coreB, prereleaseB] = b.split("+", 1)[0].split(/-(.*)/, 2);
199
+ const partsA = coreA.split(".");
200
+ const partsB = coreB.split(".");
201
+ for (let i = 0; i < 3; i++) {
202
+ const difference = compareIdentifier(partsA[i], partsB[i]);
203
+ if (difference) return difference;
204
+ }
205
+ if (prereleaseA === void 0 || prereleaseB === void 0)
206
+ return prereleaseA === prereleaseB ? 0 : prereleaseA === void 0 ? 1 : -1;
207
+ const identifiersA = prereleaseA.split(".");
208
+ const identifiersB = prereleaseB.split(".");
209
+ for (let i = 0; i < Math.min(identifiersA.length, identifiersB.length); i++) {
210
+ const difference = compareIdentifier(identifiersA[i], identifiersB[i]);
211
+ if (difference) return difference;
212
+ }
213
+ return identifiersA.length - identifiersB.length;
182
214
  }
183
215
  function getChangelogDirectory(rootDir) {
184
216
  return boundedProjectPath(rootDir, "changelog", "changelog/");
@@ -246,7 +278,7 @@ function readChangelog(rootDir, onError) {
246
278
  });
247
279
  }
248
280
  }).sort(
249
- (a, b) => b.date.localeCompare(a.date) || b.version.localeCompare(a.version, "en", { numeric: true })
281
+ (a, b) => b.date.localeCompare(a.date) || compareVersions(b.version, a.version)
250
282
  );
251
283
  }
252
284
 
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  parseStaticDocument
3
- } from "./chunk-OOKOB72A.js";
3
+ } from "./chunk-VVW5BNUX.js";
4
4
  import {
5
5
  DEFAULT_POSITION,
6
6
  documentExtension,
@@ -11,7 +11,7 @@ import {
11
11
  readDocumentDate,
12
12
  resolveConfig,
13
13
  snapshotDatesFilename
14
- } from "../chunk-TTL5UOXQ.js";
14
+ } from "../chunk-HTAJZQVN.js";
15
15
  import {
16
16
  RdxConfigError,
17
17
  changelogPluginName,
@@ -21,7 +21,7 @@ import {
21
21
  isChangelogVersion,
22
22
  readChangelog,
23
23
  resolveProjectPath
24
- } from "../chunk-OOKOB72A.js";
24
+ } from "../chunk-VVW5BNUX.js";
25
25
  export {
26
26
  RdxConfigError,
27
27
  builtDocumentDatesFilename,
package/dist/index.js CHANGED
@@ -6,12 +6,12 @@ import {
6
6
  getProjectDocsPaths,
7
7
  getSourceOptions,
8
8
  resolveDocsRoute
9
- } from "./chunk-EY2T3I2T.js";
9
+ } from "./chunk-YFA7NT73.js";
10
10
  import {
11
11
  createRdxProject,
12
12
  defineConfig,
13
13
  resolveConfig
14
- } from "./chunk-TTL5UOXQ.js";
14
+ } from "./chunk-HTAJZQVN.js";
15
15
  import {
16
16
  RdxConfigError,
17
17
  getContentSources,
@@ -20,7 +20,7 @@ import {
20
20
  getLocalizedProject,
21
21
  isFallbackPage,
22
22
  resolveProjectPath
23
- } from "./chunk-OOKOB72A.js";
23
+ } from "./chunk-VVW5BNUX.js";
24
24
  import {
25
25
  RdxDocumentLinkError,
26
26
  createDocumentLinkResolver,
package/dist/mdx/index.js CHANGED
@@ -2,8 +2,9 @@ import {
2
2
  remarkDocumentLinks
3
3
  } from "../chunk-T27TQEAY.js";
4
4
  import {
5
+ hasDisabledTabMarker,
5
6
  remarkDocumentationComponents
6
- } from "../chunk-6WNFE2QG.js";
7
+ } from "../chunk-NQMIRIOR.js";
7
8
 
8
9
  // src/mdx/index.ts
9
10
  import { default as default2 } from "rehype-slug";
@@ -213,9 +214,11 @@ function exportMarkdownBody(content, links) {
213
214
  const processor = unified().use(remarkParse).use(remarkGfm).use(remarkDirective);
214
215
  if (links.sourcePath.endsWith(".mdx")) processor.use(remarkMdx);
215
216
  const exporter = processor.use(remarkStringify).use(() => (tree) => {
216
- function strip(node) {
217
+ function strip(node, parent) {
218
+ const disabled = node.type === "heading" && node.depth === 3 && parent?.type === "containerDirective" && parent.name === "tabs" && hasDisabledTabMarker(node.children ?? [], content);
219
+ const marker = disabled ? node.children?.at(-1) : void 0;
217
220
  node.children = node.children?.filter(
218
- (child) => !["mdxjsEsm", "mdxFlowExpression", "mdxTextExpression"].includes(
221
+ (child) => child === marker || !["mdxjsEsm", "mdxFlowExpression", "mdxTextExpression"].includes(
219
222
  child.type
220
223
  )
221
224
  );
@@ -223,7 +226,7 @@ function exportMarkdownBody(content, links) {
223
226
  node.attributes = node.attributes.filter(
224
227
  (attribute) => attribute.type !== "mdxJsxExpressionAttribute" && (typeof attribute.value !== "object" || attribute.value?.type !== "mdxJsxAttributeValueExpression")
225
228
  );
226
- node.children?.forEach(strip);
229
+ node.children?.forEach((child) => strip(child, node));
227
230
  }
228
231
  strip(tree);
229
232
  }).use(remarkDocumentLinks, links);
@@ -1,12 +1,11 @@
1
1
  import {
2
- headingText
3
- } from "../chunk-FPBRKD4M.js";
2
+ getHeadingIds
3
+ } from "../chunk-GYXSGI72.js";
4
4
  import {
5
5
  remarkDocumentationComponents
6
- } from "../chunk-6WNFE2QG.js";
6
+ } from "../chunk-NQMIRIOR.js";
7
7
 
8
8
  // src/search/index.ts
9
- import GithubSlugger from "github-slugger";
10
9
  import remarkGfm from "remark-gfm";
11
10
  import remarkMdx from "remark-mdx";
12
11
  import remarkParse from "remark-parse";
@@ -45,8 +44,8 @@ function buildSearchIndex(documents) {
45
44
  let visit2 = function(node, interactive = false) {
46
45
  if (node.type === "heading") {
47
46
  const title = plain(text(node));
48
- const id = slugger.slug(headingText(node));
49
- if (!title) return;
47
+ const id = headingIds.get(node);
48
+ if (!title || id === void 0) return;
50
49
  if (interactive) {
51
50
  current.text += ` ${title}`;
52
51
  return;
@@ -82,11 +81,11 @@ function buildSearchIndex(documents) {
82
81
  };
83
82
  var visit = visit2;
84
83
  const firstEntry = entries.length;
85
- const slugger = new GithubSlugger();
86
84
  const processor = document.sourcePath?.endsWith(".md") ? markdownParser : parser;
87
85
  const tree = processor.runSync(processor.parse(document.content), {
88
86
  value: document.content
89
87
  });
88
+ const headingIds = getHeadingIds(tree);
90
89
  let current = {
91
90
  href: document.href,
92
91
  title: document.title,
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.3",
4
4
  "description": "Content indexing and document utilities for RDX documentation projects.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -1,14 +0,0 @@
1
- // src/mdx/heading-text.ts
2
- function headingText(node) {
3
- if (["image", "imageReference", "break"].includes(node.type)) return "";
4
- if (node.children) return node.children.map(headingText).join("");
5
- if (["mdxjsEsm", "mdxFlowExpression", "mdxTextExpression", "html"].includes(
6
- node.type
7
- ))
8
- return "";
9
- return node.value ?? "";
10
- }
11
-
12
- export {
13
- headingText
14
- };