@next-library/theme 1.0.8 → 1.0.10

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.
@@ -1,7 +1,23 @@
1
1
  interface MarkdownRendererProps {
2
2
  markdown: string;
3
3
  className?: string;
4
+ /**
5
+ * Directory of the current page within the docs tree, locale-agnostic and
6
+ * without a trailing filename (e.g. `offensive/.../api` for an index page, or
7
+ * `offensive/.../api/graphql` for a leaf page). Relative `.md` links in the
8
+ * markdown are resolved against this so they become working site routes.
9
+ */
10
+ baseDir?: string;
11
+ /** Current locale, used to build the `/<locale>/docs/...` route prefix. */
12
+ locale?: string;
4
13
  }
5
- export declare function MarkdownRenderer({ markdown, className }: MarkdownRendererProps): import("react/jsx-runtime").JSX.Element;
14
+ /**
15
+ * Resolve a relative markdown link (e.g. `../database/index.md`) to a working
16
+ * site route (`/<locale>/docs/offensive/.../database`). Returns null for links
17
+ * that must be left untouched: external, protocol, mailto, anchor-only,
18
+ * already-absolute, or non-`.md` targets.
19
+ */
20
+ export declare function resolveInternalDocHref(href: string | undefined, baseDir: string | undefined, locale: string | undefined): string | null;
21
+ export declare function MarkdownRenderer({ markdown, className, baseDir, locale }: MarkdownRendererProps): import("react/jsx-runtime").JSX.Element;
6
22
  export {};
7
23
  //# sourceMappingURL=markdown-renderer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"markdown-renderer.d.ts","sourceRoot":"","sources":["../../../src/components/markdown/markdown-renderer.tsx"],"names":[],"mappings":"AAgBA,UAAU,qBAAqB;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AA0ID,wBAAgB,gBAAgB,CAAC,EAAE,QAAQ,EAAE,SAAc,EAAE,EAAE,qBAAqB,2CAYnF"}
1
+ {"version":3,"file":"markdown-renderer.d.ts","sourceRoot":"","sources":["../../../src/components/markdown/markdown-renderer.tsx"],"names":[],"mappings":"AAiBA,UAAU,qBAAqB;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;;OAKG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,2EAA2E;IAC3E,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,MAAM,GAAG,SAAS,EACxB,OAAO,EAAE,MAAM,GAAG,SAAS,EAC3B,MAAM,EAAE,MAAM,GAAG,SAAS,GACzB,MAAM,GAAG,IAAI,CAqBf;AA4KD,wBAAgB,gBAAgB,CAAC,EAAE,QAAQ,EAAE,SAAc,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,qBAAqB,2CAgBpG"}
package/dist/index.js CHANGED
@@ -2617,7 +2617,7 @@ function PageHeader({
2617
2617
  translations: translations2,
2618
2618
  showCopyButton = true
2619
2619
  }) {
2620
- return /* @__PURE__ */ jsxs("div", { className: `flex flex-col gap-2 lg:gap-4 pb-8 font-bold prose prose-md max-w-none dark:prose-invert ${className}`, children: [
2620
+ return /* @__PURE__ */ jsxs("div", { className: `flex flex-col gap-2 lg:gap-4 pb-8 prose prose-md max-w-none dark:prose-invert ${className}`, children: [
2621
2621
  showCopyButton && /* @__PURE__ */ jsx(
2622
2622
  CopyPageButton,
2623
2623
  {
@@ -5631,6 +5631,27 @@ function FolderCards({ nodes }) {
5631
5631
  node.websitePath
5632
5632
  )) });
5633
5633
  }
5634
+ function resolveInternalDocHref(href, baseDir, locale) {
5635
+ if (!href || baseDir === void 0 || !locale) return null;
5636
+ if (/^[a-z][a-z0-9+.-]*:/i.test(href) || href.startsWith("//") || href.startsWith("#") || href.startsWith("/")) {
5637
+ return null;
5638
+ }
5639
+ const marker = href.search(/[#?]/);
5640
+ const pathPart = marker === -1 ? href : href.slice(0, marker);
5641
+ const suffix = marker === -1 ? "" : href.slice(marker);
5642
+ if (!/\.md$/i.test(pathPart)) return null;
5643
+ const segments = baseDir.split("/").filter(Boolean);
5644
+ for (const raw of pathPart.split("/")) {
5645
+ if (raw === "" || raw === ".") continue;
5646
+ if (raw === "..") {
5647
+ if (segments.length) segments.pop();
5648
+ continue;
5649
+ }
5650
+ segments.push(raw);
5651
+ }
5652
+ const resolved = segments.join("/").replace(/\/index\.md$/i, "").replace(/\.md$/i, "");
5653
+ return resolved ? `/${locale}/docs/${resolved}${suffix}` : `/${locale}/docs${suffix}`;
5654
+ }
5634
5655
  function CodeBlock({ children, ...props }) {
5635
5656
  const preRef = useRef(null);
5636
5657
  const [copied, setCopied] = useState(false);
@@ -5657,10 +5678,26 @@ function CodeBlock({ children, ...props }) {
5657
5678
  /* @__PURE__ */ jsx("pre", { ref: preRef, ...props, children })
5658
5679
  ] });
5659
5680
  }
5660
- var markdownComponents = {
5661
- h1: () => null,
5662
- pre: CodeBlock
5663
- };
5681
+ function makeAnchor(baseDir, locale) {
5682
+ return function Anchor({
5683
+ href,
5684
+ children,
5685
+ ...props
5686
+ }) {
5687
+ const internal = resolveInternalDocHref(href, baseDir, locale);
5688
+ if (internal) {
5689
+ return /* @__PURE__ */ jsx(Link2, { href: internal, children });
5690
+ }
5691
+ return /* @__PURE__ */ jsx("a", { href, ...props, children });
5692
+ };
5693
+ }
5694
+ function makeComponents(baseDir, locale) {
5695
+ return {
5696
+ h1: () => null,
5697
+ pre: CodeBlock,
5698
+ a: makeAnchor(baseDir, locale)
5699
+ };
5700
+ }
5664
5701
  var remarkPlugins = [remarkLint, remarkGfm, remarkFrontmatter];
5665
5702
  var rehypePlugins = [
5666
5703
  rehypeSanitize,
@@ -5677,10 +5714,22 @@ var rehypePlugins = [
5677
5714
  rehypeExternalLinks,
5678
5715
  rehypeHighlight
5679
5716
  ];
5680
- function Markdown({ markdown }) {
5681
- return /* @__PURE__ */ jsx(ReactMarkdown, { remarkPlugins, rehypePlugins, components: markdownComponents, children: markdown });
5717
+ function Markdown({
5718
+ markdown,
5719
+ baseDir,
5720
+ locale
5721
+ }) {
5722
+ return /* @__PURE__ */ jsx(
5723
+ ReactMarkdown,
5724
+ {
5725
+ remarkPlugins,
5726
+ rehypePlugins,
5727
+ components: makeComponents(baseDir, locale),
5728
+ children: markdown
5729
+ }
5730
+ );
5682
5731
  }
5683
- function Tabs({ tabs }) {
5732
+ function Tabs({ tabs, baseDir, locale }) {
5684
5733
  const [active, setActive] = useState(0);
5685
5734
  return /* @__PURE__ */ jsxs("div", { className: "cl-tabs not-prose", children: [
5686
5735
  /* @__PURE__ */ jsx("div", { className: "cl-tabs-list", role: "tablist", children: tabs.map((t, i) => /* @__PURE__ */ jsx(
@@ -5695,7 +5744,7 @@ function Tabs({ tabs }) {
5695
5744
  },
5696
5745
  i
5697
5746
  )) }),
5698
- /* @__PURE__ */ jsx("div", { className: "cl-tabs-panel prose prose-md max-w-none dark:prose-invert", children: /* @__PURE__ */ jsx(Markdown, { markdown: tabs[active]?.content ?? "" }) })
5747
+ /* @__PURE__ */ jsx("div", { className: "cl-tabs-panel prose prose-md max-w-none dark:prose-invert", children: /* @__PURE__ */ jsx(Markdown, { markdown: tabs[active]?.content ?? "", baseDir, locale }) })
5699
5748
  ] });
5700
5749
  }
5701
5750
  function parseSegments(md) {
@@ -5719,10 +5768,10 @@ function parseTabs(block) {
5719
5768
  }
5720
5769
  return tabs.length ? tabs : [{ title: "Tab", content: block }];
5721
5770
  }
5722
- function MarkdownRenderer({ markdown, className = "" }) {
5771
+ function MarkdownRenderer({ markdown, className = "", baseDir, locale }) {
5723
5772
  const segments = markdown.includes("<!-- tabs") ? parseSegments(markdown) : [{ type: "md", content: markdown }];
5724
5773
  return /* @__PURE__ */ jsx("article", { className: `cl-content-in prose prose-md max-w-none dark:prose-invert ${className}`, children: segments.map(
5725
- (s, i) => s.type === "tabs" ? /* @__PURE__ */ jsx(Tabs, { tabs: s.tabs }, i) : /* @__PURE__ */ jsx(Markdown, { markdown: s.content }, i)
5774
+ (s, i) => s.type === "tabs" ? /* @__PURE__ */ jsx(Tabs, { tabs: s.tabs, baseDir, locale }, i) : /* @__PURE__ */ jsx(Markdown, { markdown: s.content, baseDir, locale }, i)
5726
5775
  ) });
5727
5776
  }
5728
5777
  function ChatGPTIcon({ className }) {