svelte-streamdown 2.5.1 → 2.5.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.
package/README.md CHANGED
@@ -69,6 +69,10 @@ Full support for
69
69
  with _rich_ **content** support
70
70
  and multiline
71
71
 
72
+ > [!NOTE]
73
+ > 🧠 **AI Prompting Tip:** For best results, use our [comprehensive prompt](/prompting) covering all supported markdown features.
74
+
75
+
72
76
  ### 💻 Interactive Code Blocks
73
77
 
74
78
  - Syntax highlighting powered by Shiki
@@ -1,6 +1,6 @@
1
1
  <script lang="ts">
2
2
  import { useStreamdown } from '../context.svelte.js';
3
- import { transformUrl } from '../utils/url.js';
3
+ import { isPathRelativeUrl, transformUrl } from '../utils/url.js';
4
4
  import Slot from './Slot.svelte';
5
5
  import type { Tokens } from 'marked';
6
6
  import type { Snippet } from 'svelte';
@@ -17,16 +17,18 @@
17
17
  id: string;
18
18
  } = $props();
19
19
 
20
+ const isRelativeUrl = $derived(isPathRelativeUrl(token.href));
21
+
20
22
  const transformedUrl = $derived(
21
23
  transformUrl(token.href, streamdown.allowedImagePrefixes ?? [], streamdown.defaultOrigin)
22
24
  );
23
25
  </script>
24
26
 
25
27
  {#if token.href !== 'streamdown:incomplete-image'}
26
- {#if transformedUrl}
28
+ {#if transformedUrl || isRelativeUrl}
27
29
  <Slot
28
30
  props={{
29
- src: transformedUrl,
31
+ src: isRelativeUrl ? token.href : transformedUrl,
30
32
  alt: token.text,
31
33
  children,
32
34
  token
@@ -38,7 +40,11 @@
38
40
  style={streamdown.isMounted ? streamdown.animationBlockStyle : ''}
39
41
  class={streamdown.theme.image.base}
40
42
  >
41
- <img class={streamdown.theme.image.image} src={transformedUrl} alt={token.text} />
43
+ <img
44
+ class={streamdown.theme.image.image}
45
+ src={isRelativeUrl ? token.href : transformedUrl}
46
+ alt={token.text}
47
+ />
42
48
  </span>
43
49
  </Slot>
44
50
  {:else}
@@ -1,6 +1,6 @@
1
1
  <script lang="ts">
2
2
  import { useStreamdown } from '../context.svelte.js';
3
- import { transformUrl } from '../utils/url.js';
3
+ import { isPathRelativeUrl, transformUrl } from '../utils/url.js';
4
4
  import Slot from './Slot.svelte';
5
5
  import type { Tokens } from 'marked';
6
6
  import type { Snippet } from 'svelte';
@@ -17,12 +17,14 @@
17
17
  id: string;
18
18
  } = $props();
19
19
 
20
+ const isRelativeUrl = $derived(isPathRelativeUrl(token.href));
21
+
20
22
  const transformedUrl = $derived(
21
23
  transformUrl(token.href, streamdown.allowedLinkPrefixes ?? [], streamdown.defaultOrigin)
22
24
  );
23
25
  </script>
24
26
 
25
- {#if transformedUrl || token.href === 'streamdown:incomplete-link'}
27
+ {#if transformedUrl || token.href === 'streamdown:incomplete-link' || isRelativeUrl}
26
28
  <Slot
27
29
  props={{
28
30
  href: transformedUrl,
@@ -37,9 +39,9 @@
37
39
  <a
38
40
  data-streamdown-link={id}
39
41
  class={streamdown.theme.link.base}
40
- href={transformedUrl}
41
- target="_blank"
42
- rel="noopener noreferrer"
42
+ {...isRelativeUrl
43
+ ? { href: token.href }
44
+ : { href: transformedUrl, target: '_blank', rel: 'noopener noreferrer' }}
43
45
  >
44
46
  {@render children()}
45
47
  </a>
package/dist/theme.js CHANGED
@@ -104,7 +104,7 @@ export const theme = {
104
104
  mermaid: {
105
105
  base: 'group relative my-4 h-auto rounded-xl border border-gray-200 bg-white overflow-hidden items-center min-h-[500px]',
106
106
  icon: 'size-5',
107
- buttons: 'absolute right-1 top-1 z-10 flex h-fit w-fit items-center gap-1'
107
+ buttons: 'absolute right-1 top-1 flex h-fit w-fit items-center gap-1'
108
108
  },
109
109
  math: {
110
110
  block: '',
@@ -257,7 +257,7 @@ export const shadcnTheme = {
257
257
  mermaid: {
258
258
  base: 'group relative my-4 h-auto rounded-lg border border-border bg-card overflow-hidden items-center min-h-[500px]',
259
259
  icon: 'size-5',
260
- buttons: 'absolute right-1 top-1 z-10 flex h-fit w-fit items-center gap-1'
260
+ buttons: 'absolute right-1 top-1 flex h-fit w-fit items-center gap-1'
261
261
  },
262
262
  math: {
263
263
  block: 'text-foreground',
@@ -1,2 +1,3 @@
1
1
  export declare const parseUrl: (url: unknown, defaultOrigin?: string) => URL | null;
2
+ export declare const isPathRelativeUrl: (url: unknown) => boolean;
2
3
  export declare const transformUrl: (url: unknown, allowedPrefixes: string[], defaultOrigin?: string) => string | null;
package/dist/utils/url.js CHANGED
@@ -20,7 +20,7 @@ export const parseUrl = (url, defaultOrigin) => {
20
20
  return null;
21
21
  }
22
22
  };
23
- const isPathRelativeUrl = (url) => {
23
+ export const isPathRelativeUrl = (url) => {
24
24
  if (typeof url !== 'string')
25
25
  return false;
26
26
  return url.startsWith('/');
@@ -29,6 +29,7 @@ export const transformUrl = (url, allowedPrefixes, defaultOrigin) => {
29
29
  if (!url)
30
30
  return null;
31
31
  const parsedUrl = parseUrl(url, defaultOrigin);
32
+ console.log('parsedUrl', { parsedUrl, url });
32
33
  if (!parsedUrl)
33
34
  return null;
34
35
  // If the input is path relative, we output a path relative URL as well,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelte-streamdown",
3
- "version": "2.5.1",
3
+ "version": "2.5.2",
4
4
  "scripts": {
5
5
  "dev": "vite dev",
6
6
  "build": "vite build && npm run prepack",