svelte-intlayer 8.12.1 → 8.12.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.
@@ -1,7 +1,41 @@
1
1
  import { type ParsedMarkdown } from '@intlayer/core/markdown';
2
2
  /**
3
- * Compile markdown to HTML strings for Svelte.
3
+ * Intermediate AST produced by `parseMarkdown`.
4
+ * Pass this to `compileMarkdown` to skip re-parsing when the same content is
5
+ * rendered multiple times.
4
6
  */
5
7
  export type { ParsedMarkdown };
8
+ /**
9
+ * **Step 1 of 2 — parse only.**
10
+ * Converts a raw markdown string into a `ParsedMarkdown` AST without rendering
11
+ * any HTML. Use this when you need to:
12
+ * - Cache the parsed result and render it several times with different options.
13
+ * - Inspect or transform the AST before rendering.
14
+ * - Defer the render step to a later point.
15
+ *
16
+ * @param markdown - The markdown source string.
17
+ * @param options - Options that affect parsing (sanitizer, slugify, …).
18
+ * @returns A `ParsedMarkdown` AST ready to be passed to `compileMarkdown`.
19
+ *
20
+ * @example
21
+ * ```ts
22
+ * const ast = parseMarkdown('# Hello **World**');
23
+ * const html = compileMarkdown(ast);
24
+ * ```
25
+ */
6
26
  export declare const parseMarkdown: (markdown?: string, options?: any) => ParsedMarkdown;
27
+ /**
28
+ * **Steps 1 + 2 — parse and render in one shot.**
29
+ * Accepts a raw markdown string or a pre-parsed `ParsedMarkdown` AST and
30
+ * returns an HTML string suitable for Svelte's `{@html}` tag.
31
+ *
32
+ * @param input - Markdown string or pre-parsed AST.
33
+ * @param options - Rendering options (components, sanitizer, slugify, …).
34
+ * @returns An HTML string representing the rendered markdown.
35
+ *
36
+ * @example
37
+ * ```svelte
38
+ * <div>{@html compileMarkdown('# Hello **World**')}</div>
39
+ * ```
40
+ */
7
41
  export declare const compileMarkdown: (input?: string | ParsedMarkdown, options?: any) => unknown;
@@ -1,5 +1,23 @@
1
1
  import { compileWithOptions, parseMarkdown as coreParseMarkdown, renderMarkdownAst as coreRenderMarkdownAst, } from '@intlayer/core/markdown';
2
2
  import { svelteHtmlRuntime } from './runtime';
3
+ /**
4
+ * **Step 1 of 2 — parse only.**
5
+ * Converts a raw markdown string into a `ParsedMarkdown` AST without rendering
6
+ * any HTML. Use this when you need to:
7
+ * - Cache the parsed result and render it several times with different options.
8
+ * - Inspect or transform the AST before rendering.
9
+ * - Defer the render step to a later point.
10
+ *
11
+ * @param markdown - The markdown source string.
12
+ * @param options - Options that affect parsing (sanitizer, slugify, …).
13
+ * @returns A `ParsedMarkdown` AST ready to be passed to `compileMarkdown`.
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * const ast = parseMarkdown('# Hello **World**');
18
+ * const html = compileMarkdown(ast);
19
+ * ```
20
+ */
3
21
  export const parseMarkdown = (markdown = '', options = {}) => {
4
22
  const { components, namedCodesToUnicode, sanitizer, slugify, ...compilerOptions } = options;
5
23
  const ctx = {
@@ -11,6 +29,20 @@ export const parseMarkdown = (markdown = '', options = {}) => {
11
29
  };
12
30
  return coreParseMarkdown(markdown, ctx, compilerOptions);
13
31
  };
32
+ /**
33
+ * **Steps 1 + 2 — parse and render in one shot.**
34
+ * Accepts a raw markdown string or a pre-parsed `ParsedMarkdown` AST and
35
+ * returns an HTML string suitable for Svelte's `{@html}` tag.
36
+ *
37
+ * @param input - Markdown string or pre-parsed AST.
38
+ * @param options - Rendering options (components, sanitizer, slugify, …).
39
+ * @returns An HTML string representing the rendered markdown.
40
+ *
41
+ * @example
42
+ * ```svelte
43
+ * <div>{@html compileMarkdown('# Hello **World**')}</div>
44
+ * ```
45
+ */
14
46
  export const compileMarkdown = (input = '', options = {}) => {
15
47
  if (typeof input === 'string') {
16
48
  return compileWithOptions(input, svelteHtmlRuntime, options);
@@ -1,10 +1,31 @@
1
- export { getMarkdownContext, type MarkdownContext, type RenderMarkdownOptions, setMarkdownContext, setMarkdownContext as setIntlayerMarkdown, } from './context';
2
1
  import { type ParsedMarkdown } from './compiler';
3
2
  import { type RenderMarkdownOptions } from './context';
4
- export * from './compiler';
3
+ export { compileMarkdown, type ParsedMarkdown, parseMarkdown, } from './compiler';
4
+ export { getMarkdownContext, type MarkdownContext, type MarkdownProviderOptions, type RenderMarkdownOptions, setMarkdownContext, setMarkdownContext as setIntlayerMarkdown, } from './context';
5
5
  export { default as MarkdownMetadataRenderer } from './MarkdownMetadataRenderer.svelte';
6
6
  export { default as MarkdownProvider } from './MarkdownProvider.svelte';
7
7
  export { default as MarkdownRenderer } from './MarkdownRenderer.svelte';
8
8
  export type RenderMarkdownProps = RenderMarkdownOptions;
9
+ /**
10
+ * Context-aware render function. Equivalent to `compileMarkdown` when called
11
+ * outside a `<MarkdownProvider>`; delegates to the provider's render function
12
+ * when one is active.
13
+ */
9
14
  export declare const renderMarkdown: (input?: string | ParsedMarkdown, options?: any) => unknown;
10
- export declare const useMarkdownRenderer: (options?: RenderMarkdownProps) => (content: string | ParsedMarkdown) => string | Promise<string>;
15
+ /**
16
+ * Returns a render function bound to the current `<MarkdownProvider>` context.
17
+ * The returned function forwards its call to whichever `renderMarkdown`
18
+ * implementation was injected by the nearest provider.
19
+ *
20
+ * @param options - Default rendering options applied on every call.
21
+ * @returns A function that accepts markdown content and returns an HTML string.
22
+ *
23
+ * @example
24
+ * ```svelte
25
+ * <script>
26
+ * const render = useMarkdownRenderer({ forceBlock: true });
27
+ * </script>
28
+ * <div>{@html render(markdownString)}</div>
29
+ * ```
30
+ */
31
+ export declare const useMarkdownRenderer: (options?: RenderMarkdownOptions) => (content: string | ParsedMarkdown) => string | Promise<string>;
@@ -1,11 +1,32 @@
1
- export { getMarkdownContext, setMarkdownContext, setMarkdownContext as setIntlayerMarkdown, } from './context';
2
1
  import { compileMarkdown } from './compiler';
3
2
  import { getMarkdownContext } from './context';
4
- export * from './compiler';
3
+ export { compileMarkdown, parseMarkdown, } from './compiler';
4
+ export { getMarkdownContext, setMarkdownContext, setMarkdownContext as setIntlayerMarkdown, } from './context';
5
5
  export { default as MarkdownMetadataRenderer } from './MarkdownMetadataRenderer.svelte';
6
6
  export { default as MarkdownProvider } from './MarkdownProvider.svelte';
7
7
  export { default as MarkdownRenderer } from './MarkdownRenderer.svelte';
8
+ /**
9
+ * Context-aware render function. Equivalent to `compileMarkdown` when called
10
+ * outside a `<MarkdownProvider>`; delegates to the provider's render function
11
+ * when one is active.
12
+ */
8
13
  export const renderMarkdown = compileMarkdown;
14
+ /**
15
+ * Returns a render function bound to the current `<MarkdownProvider>` context.
16
+ * The returned function forwards its call to whichever `renderMarkdown`
17
+ * implementation was injected by the nearest provider.
18
+ *
19
+ * @param options - Default rendering options applied on every call.
20
+ * @returns A function that accepts markdown content and returns an HTML string.
21
+ *
22
+ * @example
23
+ * ```svelte
24
+ * <script>
25
+ * const render = useMarkdownRenderer({ forceBlock: true });
26
+ * </script>
27
+ * <div>{@html render(markdownString)}</div>
28
+ * ```
29
+ */
9
30
  export const useMarkdownRenderer = (options = {}) => {
10
31
  const context = getMarkdownContext();
11
32
  return (content) => context.renderMarkdown(content, options);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelte-intlayer",
3
- "version": "8.12.1",
3
+ "version": "8.12.3",
4
4
  "description": "Easily internationalize i18n your Svelte applications with type-safe multilingual content management.",
5
5
  "keywords": [
6
6
  "intlayer",
@@ -82,24 +82,24 @@
82
82
  "typecheck": "tsc --noEmit --project tsconfig.types.json"
83
83
  },
84
84
  "dependencies": {
85
- "@intlayer/api": "8.12.1",
86
- "@intlayer/config": "8.12.1",
87
- "@intlayer/core": "8.12.1",
88
- "@intlayer/editor": "8.12.1",
89
- "@intlayer/types": "8.12.1"
85
+ "@intlayer/api": "8.12.3",
86
+ "@intlayer/config": "8.12.3",
87
+ "@intlayer/core": "8.12.3",
88
+ "@intlayer/editor": "8.12.3",
89
+ "@intlayer/types": "8.12.3"
90
90
  },
91
91
  "devDependencies": {
92
92
  "@sveltejs/adapter-auto": "7.0.1",
93
93
  "@sveltejs/package": "2.5.7",
94
94
  "@sveltejs/vite-plugin-svelte": "7.1.2",
95
- "@types/node": "25.9.1",
95
+ "@types/node": "25.9.2",
96
96
  "@utils/ts-config": "1.0.4",
97
97
  "@utils/ts-config-types": "1.0.4",
98
98
  "@utils/tsdown-config": "1.0.4",
99
99
  "rimraf": "6.1.3",
100
100
  "svelte": "5.55.8",
101
101
  "svelte-check": "4.4.8",
102
- "tsdown": "0.22.1",
102
+ "tsdown": "0.21.10",
103
103
  "typescript": "6.0.3",
104
104
  "vite": "8.0.16",
105
105
  "vitest": "4.1.8"