@usequeek/theme-kit 0.5.10 → 0.5.11

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/package.json +1 -1
  2. package/utils/markdown.tsx +13 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@usequeek/theme-kit",
3
- "version": "0.5.10",
3
+ "version": "0.5.11",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "description": "The runtime a Queek storefront theme is built on: hooks, stores, page renderer, navigation, shared blocks and locale strings.",
@@ -1,5 +1,6 @@
1
1
  import type { JSX } from 'react';
2
2
  import { Fragment } from 'react';
3
+ import { Link } from '../navigation';
3
4
 
4
5
  /**
5
6
  * Strip markdown syntax to plain text. Use for previews / single-line contexts
@@ -39,6 +40,13 @@ function withBasePath(href: string, basePath?: string): string {
39
40
  return `${basePath}${href}`;
40
41
  }
41
42
 
43
+ // Root-relative ("/about"), not protocol-relative ("//host"): the only hrefs
44
+ // the router can move to without a full page load. Everything else (http(s),
45
+ // mailto:, tel:, #anchors, bare relative paths) stays a plain anchor.
46
+ function isInternalHref(href: string): boolean {
47
+ return href.startsWith('/') && !href.startsWith('//');
48
+ }
49
+
42
50
  function parseInline(text: string, keyPrefix: string, basePath?: string): React.ReactNode[] {
43
51
  const parts = text.split(INLINE_RE).filter(Boolean);
44
52
 
@@ -75,9 +83,13 @@ function parseInline(text: string, keyPrefix: string, basePath?: string): React.
75
83
  const linkMatch = part.match(/^\[([^\]]+)\]\(([^)]+)\)$/);
76
84
  if (linkMatch) {
77
85
  const [, label, href] = linkMatch;
86
+ const resolved = withBasePath(href, basePath);
87
+ if (isInternalHref(href)) {
88
+ return <Link key={key} href={resolved}>{label}</Link>;
89
+ }
78
90
  const isExternal = href.startsWith('http://') || href.startsWith('https://');
79
91
  return (
80
- <a key={key} href={withBasePath(href, basePath)} {...(isExternal ? { target: '_blank', rel: 'noopener noreferrer' } : {})}>
92
+ <a key={key} href={resolved} {...(isExternal ? { target: '_blank', rel: 'noopener noreferrer' } : {})}>
81
93
  {label}
82
94
  </a>
83
95
  );