react-intlayer 9.4.4 → 9.5.0
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 +0 -2
- package/dist/cjs/markdown/processor.cjs +4 -13
- package/dist/cjs/markdown/processor.cjs.map +1 -1
- package/dist/cjs/markdown/runtime.cjs +31 -3
- package/dist/cjs/markdown/runtime.cjs.map +1 -1
- package/dist/esm/markdown/processor.mjs +4 -13
- package/dist/esm/markdown/processor.mjs.map +1 -1
- package/dist/esm/markdown/runtime.mjs +31 -3
- package/dist/esm/markdown/runtime.mjs.map +1 -1
- package/dist/types/markdown/processor.d.ts.map +1 -1
- package/dist/types/markdown/runtime.d.ts.map +1 -1
- package/package.json +9 -9
package/README.md
CHANGED
|
@@ -69,8 +69,6 @@ With **per-locale content files**, **TypeScript autocompletion**, **tree-shakabl
|
|
|
69
69
|
| <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/interoperability.png?raw=true" alt="Feature" width="700"> | **Interoperability**<br><br>Allow interoperability with react-i18next, next-i18next, next-intl, react-intl, vue-i18n. <br><br> - [Intlayer and react-intl](https://intlayer.org/blog/intlayer-with-react-intl) <br> - [Intlayer and next-intl](https://intlayer.org/blog/intlayer-with-next-intl) <br> - [Intlayer and next-i18next](https://intlayer.org/blog/intlayer-with-next-i18next) <br> - [Intlayer and vue-i18n](https://intlayer.org/blog/intlayer-with-vue-i18n) <br> - [Intlayer compat adapters](https://intlayer.org/doc/compatibility) |
|
|
70
70
|
| <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/benchmark.png?raw=true" alt="Feature" width="700"> | **Performances & Benchmark**<br><br>Uses advanced tree-shaking and dynamic loading to boost performances and keep the solution as light as possible. <br><br> - [Performances & Benchmark](https://intlayer.org/doc/benchmark) |
|
|
71
71
|
|
|
72
|
-
---
|
|
73
|
-
|
|
74
72
|
## 📦 Installation
|
|
75
73
|
|
|
76
74
|
Start your journey with Intlayer today and experience a smoother, more powerful approach to internationalization.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_markdown_runtime = require('./runtime.cjs');
|
|
2
3
|
let _intlayer_core_markdown = require("@intlayer/core/markdown");
|
|
3
|
-
let react = require("react");
|
|
4
4
|
|
|
5
5
|
//#region src/markdown/processor.tsx
|
|
6
6
|
/**
|
|
@@ -9,15 +9,6 @@ let react = require("react");
|
|
|
9
9
|
* [simple-markdown v0.2.2](https://github.com/Khan/simple-markdown) from Khan Academy.
|
|
10
10
|
*/
|
|
11
11
|
/**
|
|
12
|
-
* Default React runtime for markdown rendering.
|
|
13
|
-
*/
|
|
14
|
-
const DEFAULT_RUNTIME = {
|
|
15
|
-
createElement: react.createElement,
|
|
16
|
-
cloneElement: react.cloneElement,
|
|
17
|
-
Fragment: react.Fragment,
|
|
18
|
-
normalizeProps: (_tag, props) => props
|
|
19
|
-
};
|
|
20
|
-
/**
|
|
21
12
|
* **Step 1 of 2 — parse only.**
|
|
22
13
|
* Converts a raw markdown string into a `ParsedMarkdown` AST without rendering
|
|
23
14
|
* any React elements. Use this when you need to:
|
|
@@ -38,7 +29,7 @@ const DEFAULT_RUNTIME = {
|
|
|
38
29
|
const parseMarkdown = (markdown = "", options = {}) => {
|
|
39
30
|
const { disableAutoLink, disableParsingRawHTML, enforceAtxHeadings, forceBlock, forceInline, forceWrapper, namedCodesToUnicode, components, sanitizer, slugify, wrapper, preserveFrontmatter, tagfilter } = options;
|
|
40
31
|
return (0, _intlayer_core_markdown.parseMarkdown)(markdown, {
|
|
41
|
-
runtime:
|
|
32
|
+
runtime: require_markdown_runtime.reactRuntime,
|
|
42
33
|
components,
|
|
43
34
|
namedCodesToUnicode,
|
|
44
35
|
sanitizer,
|
|
@@ -74,9 +65,9 @@ const compileMarkdown = (input = "", options = {}) => {
|
|
|
74
65
|
const { createElement: customCreateElement, disableAutoLink, disableParsingRawHTML, enforceAtxHeadings, forceBlock, forceInline, forceWrapper, namedCodesToUnicode, components, renderRule, sanitizer, slugify, wrapper, preserveFrontmatter, tagfilter } = options;
|
|
75
66
|
const ctx = {
|
|
76
67
|
runtime: customCreateElement ? {
|
|
77
|
-
...
|
|
68
|
+
...require_markdown_runtime.reactRuntime,
|
|
78
69
|
createElement: customCreateElement
|
|
79
|
-
} :
|
|
70
|
+
} : require_markdown_runtime.reactRuntime,
|
|
80
71
|
components,
|
|
81
72
|
namedCodesToUnicode,
|
|
82
73
|
sanitizer,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"processor.cjs","names":["
|
|
1
|
+
{"version":3,"file":"processor.cjs","names":["coreParseMarkdown","reactRuntime","coreCompile","coreRenderMarkdownAst"],"sources":["../../../src/markdown/processor.tsx"],"sourcesContent":["/**\n * it's a fork\n * [markdown-to-jsx v7.7.14](https://github.com/quantizor/markdown-to-jsx) from quantizor\n * [simple-markdown v0.2.2](https://github.com/Khan/simple-markdown) from Khan Academy.\n */\n\nimport {\n compile as coreCompile,\n parseMarkdown as coreParseMarkdown,\n renderMarkdownAst as coreRenderMarkdownAst,\n type MarkdownContext,\n type MarkdownOptions,\n type ParsedMarkdown,\n type RenderRuleHook,\n} from '@intlayer/core/markdown';\nimport type { createElement, JSX, ReactNode } from 'react';\nimport type { HTMLComponents } from '../html/HTMLComponentTypes';\nimport { reactRuntime } from './runtime';\n\ntype HTMLTags = keyof JSX.IntrinsicElements;\n\n/**\n * Refined MarkdownRendererOptions type.\n */\nexport type MarkdownRendererOptions = Partial<{\n /**\n * Ultimate control over the output of all rendered JSX.\n */\n createElement: (\n tag: Parameters<typeof createElement>[0],\n props: JSX.IntrinsicAttributes,\n ...children: ReactNode[]\n ) => ReactNode;\n\n /**\n * The library automatically generates an anchor tag for bare URLs included in the markdown\n * document, but this behavior can be disabled if desired.\n */\n disableAutoLink: boolean;\n\n /**\n * Disable the compiler's best-effort transcription of provided raw HTML\n * into JSX-equivalent.\n */\n disableParsingRawHTML: boolean;\n\n /**\n * Forces the compiler to have space between hash sign and the header text.\n */\n enforceAtxHeadings: boolean;\n\n /**\n * Forces the compiler to always output content with a block-level wrapper.\n */\n forceBlock: boolean;\n\n /**\n * Forces the compiler to always output content with an inline wrapper.\n */\n forceInline: boolean;\n\n /**\n * Forces the compiler to wrap results, even if there is only a single child.\n */\n forceWrapper: boolean;\n\n /**\n * Supply additional HTML entity: unicode replacement mappings.\n */\n namedCodesToUnicode: {\n [key: string]: string;\n };\n\n /**\n * Selectively control the output of particular HTML tags.\n */\n components: HTMLComponents;\n\n /**\n * Allows for full control over rendering of particular rules.\n */\n renderRule: RenderRuleHook;\n\n /**\n * Override the built-in sanitizer function for URLs.\n */\n sanitizer: (value: string, tag: HTMLTags, attribute: string) => string | null;\n\n /**\n * Override normalization of non-URI-safe characters for anchor linking.\n */\n slugify: (input: string) => string;\n\n /**\n * Declare the type of the wrapper to be used when there are multiple children.\n */\n wrapper: any | null;\n\n /**\n * Whether to preserve frontmatter in the markdown content.\n */\n preserveFrontmatter: boolean;\n\n /**\n * Whether to use the GitHub Tag Filter.\n */\n tagfilter: boolean;\n}>;\n\n/**\n * Default React runtime for markdown rendering.\n */\n\n/**\n * Intermediate AST produced by `parseMarkdown`.\n * Pass this to `compileMarkdown` or `<MarkdownRenderer>` to skip re-parsing\n * when the same content is rendered multiple times.\n */\nexport type { ParsedMarkdown };\n\n/**\n * **Step 1 of 2 — parse only.**\n * Converts a raw markdown string into a `ParsedMarkdown` AST without rendering\n * any React elements. Use this when you need to:\n * - Cache the parsed result and render it several times with different options.\n * - Inspect or transform the AST before rendering.\n * - Defer the render step to a later point in the pipeline.\n *\n * @param markdown - The markdown source string.\n * @param options - Options that affect parsing (sanitizer, slugify, …).\n * @returns A `ParsedMarkdown` AST ready to be passed to `compileMarkdown`.\n *\n * @example\n * ```tsx\n * const ast = parseMarkdown('# Hello **world**');\n * const element = compileMarkdown(ast, { forceBlock: true });\n * ```\n */\nexport const parseMarkdown = (\n markdown: string = '',\n options: MarkdownRendererOptions = {}\n): ParsedMarkdown => {\n const {\n disableAutoLink,\n disableParsingRawHTML,\n enforceAtxHeadings,\n forceBlock,\n forceInline,\n forceWrapper,\n namedCodesToUnicode,\n components,\n sanitizer,\n slugify,\n wrapper,\n preserveFrontmatter,\n tagfilter,\n } = options;\n\n const ctx: MarkdownContext<HTMLComponents> = {\n runtime: reactRuntime,\n components,\n namedCodesToUnicode,\n sanitizer: sanitizer as any,\n slugify,\n };\n\n const compilerOptions: MarkdownOptions = {\n disableAutoLink,\n disableParsingRawHTML,\n enforceAtxHeadings,\n forceBlock,\n forceInline,\n forceWrapper,\n wrapper,\n preserveFrontmatter,\n tagfilter,\n };\n\n return coreParseMarkdown(markdown, ctx, compilerOptions);\n};\n\n/**\n * **Steps 1 + 2 — parse and render in one shot.**\n * Accepts a raw markdown string or a pre-parsed `ParsedMarkdown` AST and\n * returns a React element. Use `parseMarkdown` first when you need to reuse\n * the same AST with different options.\n *\n * @param input - Markdown string or pre-parsed AST.\n * @param options - Rendering options (custom components, sanitizer, slugify, …).\n * @returns A React JSX element representing the rendered markdown.\n *\n * @example\n * ```tsx\n * const element = compileMarkdown('# Hello **world**', { forceBlock: true });\n * ```\n */\nexport const compileMarkdown = (\n input: string | ParsedMarkdown = '',\n options: MarkdownRendererOptions = {}\n): JSX.Element => {\n const {\n createElement: customCreateElement,\n disableAutoLink,\n disableParsingRawHTML,\n enforceAtxHeadings,\n forceBlock,\n forceInline,\n forceWrapper,\n namedCodesToUnicode,\n components,\n renderRule,\n sanitizer,\n slugify,\n wrapper,\n preserveFrontmatter,\n tagfilter,\n } = options;\n\n const runtime = customCreateElement\n ? { ...reactRuntime, createElement: customCreateElement as any }\n : reactRuntime;\n\n const ctx: MarkdownContext<HTMLComponents> = {\n runtime,\n components,\n namedCodesToUnicode,\n sanitizer: sanitizer as any,\n slugify,\n };\n\n const compilerOptions: MarkdownOptions = {\n disableAutoLink,\n disableParsingRawHTML,\n enforceAtxHeadings,\n forceBlock,\n forceInline,\n forceWrapper,\n renderRule,\n wrapper,\n preserveFrontmatter,\n tagfilter,\n };\n\n if (typeof input === 'string') {\n return coreCompile(input, ctx, compilerOptions) as JSX.Element;\n }\n\n return coreRenderMarkdownAst(input, ctx, compilerOptions) as JSX.Element;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0IA,MAAa,iBACX,WAAmB,IACnB,UAAmC,CAAC,MACjB;CACnB,MAAM,EACJ,iBACA,uBACA,oBACA,YACA,aACA,cACA,qBACA,YACA,WACA,SACA,SACA,qBACA,cACE;CAsBJ,WAAOA,uCAAkB,UAAU;EAnBjC,SAASC;EACT;EACA;EACW;EACX;CAemC,GAAG;EAXtC;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CAGoD,CAAC;AACzD;;;;;;;;;;;;;;;;AAiBA,MAAa,mBACX,QAAiC,IACjC,UAAmC,CAAC,MACpB;CAChB,MAAM,EACJ,eAAe,qBACf,iBACA,uBACA,oBACA,YACA,aACA,cACA,qBACA,YACA,YACA,WACA,SACA,SACA,qBACA,cACE;CAMJ,MAAM,MAAuC;EAC3C,SALc,sBACZ;GAAE,GAAGA;GAAc,eAAe;EAA2B,IAC7DA;EAIF;EACA;EACW;EACX;CACF;CAEA,MAAM,kBAAmC;EACvC;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF;CAEA,IAAI,OAAO,UAAU,UACnB,WAAOC,iCAAY,OAAO,KAAK,eAAe;CAGhD,WAAOC,2CAAsB,OAAO,KAAK,eAAe;AAC1D"}
|
|
@@ -6,15 +6,43 @@ let react = require("react");
|
|
|
6
6
|
* React-specific runtime for the markdown processor.
|
|
7
7
|
* Implements the MarkdownRuntime interface using React's primitives.
|
|
8
8
|
*/
|
|
9
|
+
let REACT_ELEMENT_TYPE;
|
|
10
|
+
try {
|
|
11
|
+
const sample = (0, react.createElement)("div");
|
|
12
|
+
REACT_ELEMENT_TYPE = sample && typeof sample === "object" && "$$typeof" in sample && typeof sample.$$typeof === "symbol" ? sample.$$typeof : Symbol.for("react.transitional.element");
|
|
13
|
+
} catch {
|
|
14
|
+
REACT_ELEMENT_TYPE = Symbol.for("react.transitional.element");
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* React-specific runtime for the markdown processor.
|
|
18
|
+
* Implements the MarkdownRuntime interface using React's primitives.
|
|
19
|
+
*/
|
|
9
20
|
const reactRuntime = {
|
|
10
21
|
/**
|
|
11
22
|
* Creates a React element.
|
|
12
23
|
* Handles the conversion of props and children to React format.
|
|
13
24
|
*/
|
|
14
25
|
createElement: (type, props, ...children) => {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
26
|
+
let key = null;
|
|
27
|
+
const finalProps = props || {};
|
|
28
|
+
if (props && props.key != null) {
|
|
29
|
+
key = String(props.key);
|
|
30
|
+
finalProps.key = void 0;
|
|
31
|
+
}
|
|
32
|
+
const childCount = children.length;
|
|
33
|
+
if (childCount === 1) finalProps.children = children[0];
|
|
34
|
+
else if (childCount > 1) finalProps.children = children;
|
|
35
|
+
return {
|
|
36
|
+
$$typeof: REACT_ELEMENT_TYPE,
|
|
37
|
+
type,
|
|
38
|
+
key,
|
|
39
|
+
ref: null,
|
|
40
|
+
props: finalProps,
|
|
41
|
+
_owner: null,
|
|
42
|
+
_store: {},
|
|
43
|
+
_debugStack: null,
|
|
44
|
+
_debugTask: null
|
|
45
|
+
};
|
|
18
46
|
},
|
|
19
47
|
/**
|
|
20
48
|
* Clones a React element with new props.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.cjs","names":["createElement","cloneElement"],"sources":["../../../src/markdown/runtime.ts"],"sourcesContent":["import type { HTMLTag, MarkdownRuntime } from '@intlayer/core/markdown';\nimport {\n cloneElement,\n createElement,\n Fragment,\n type ReactElement,\n type ReactNode,\n} from 'react';\n\n/**\n * React-specific runtime for the markdown processor.\n * Implements the MarkdownRuntime interface using React's primitives.\n */\nexport const reactRuntime: MarkdownRuntime = {\n /**\n * Creates a React element.\n * Handles the conversion of props and children to React format.\n */\n createElement: (\n type: string | any,\n props: Record<string, any> | null,\n ...children: any[]\n ): ReactNode => {\n
|
|
1
|
+
{"version":3,"file":"runtime.cjs","names":["createElement","cloneElement"],"sources":["../../../src/markdown/runtime.ts"],"sourcesContent":["import type { HTMLTag, MarkdownRuntime } from '@intlayer/core/markdown';\nimport {\n cloneElement,\n createElement,\n Fragment,\n type ReactElement,\n type ReactNode,\n} from 'react';\n\n/**\n * React-specific runtime for the markdown processor.\n * Implements the MarkdownRuntime interface using React's primitives.\n */\nlet REACT_ELEMENT_TYPE: symbol;\ntry {\n const sample = createElement('div');\n REACT_ELEMENT_TYPE =\n sample &&\n typeof sample === 'object' &&\n '$$typeof' in sample &&\n typeof sample.$$typeof === 'symbol'\n ? (sample.$$typeof as symbol)\n : Symbol.for('react.transitional.element');\n} catch {\n REACT_ELEMENT_TYPE = Symbol.for('react.transitional.element');\n}\n\n/**\n * React-specific runtime for the markdown processor.\n * Implements the MarkdownRuntime interface using React's primitives.\n */\nexport const reactRuntime: MarkdownRuntime = {\n /**\n * Creates a React element.\n * Handles the conversion of props and children to React format.\n */\n createElement: (\n type: string | any,\n props: Record<string, any> | null,\n ...children: any[]\n ): ReactNode => {\n let key: string | null = null;\n const finalProps: any = props || {};\n\n if (props && props.key != null) {\n key = String(props.key);\n finalProps.key = undefined;\n }\n\n const childCount = children.length;\n if (childCount === 1) {\n finalProps.children = children[0];\n } else if (childCount > 1) {\n finalProps.children = children;\n }\n\n return {\n $$typeof: REACT_ELEMENT_TYPE,\n type,\n key,\n ref: null,\n props: finalProps,\n _owner: null,\n _store: {},\n _debugStack: null,\n _debugTask: null,\n } as unknown as ReactNode;\n },\n\n /**\n * Clones a React element with new props.\n */\n cloneElement: (\n element: unknown,\n props: Record<string, any>,\n ...children: any[]\n ): ReactNode => {\n if (children.length === 0) {\n return cloneElement(element as ReactElement, props);\n }\n return cloneElement(element as ReactElement, props, ...children);\n },\n\n /**\n * React Fragment component.\n */\n Fragment,\n\n /**\n * React-specific prop normalization.\n * React uses className instead of class, htmlFor instead of for, etc.\n * The core processor already handles ATTRIBUTE_TO_NODE_PROP_MAP,\n * so this is mostly a no-op but can be used for additional React-specific transforms.\n */\n normalizeProps: (\n _tag: HTMLTag,\n props: Record<string, any>\n ): Record<string, any> => {\n // The core already handles class -> className and for -> htmlFor\n // via ATTRIBUTE_TO_NODE_PROP_MAP in the attrStringToMap function.\n // This hook is available for any additional React-specific transforms.\n return props;\n },\n};\n\n/**\n * Creates a React runtime with custom createElement for advanced use cases.\n * Useful for wrapping elements or adding middleware.\n */\nexport const createReactRuntime = (\n options: {\n onCreateElement?: (\n type: string | any,\n props: Record<string, any> | null,\n children: any[]\n ) => ReactNode;\n } = {}\n): MarkdownRuntime => {\n const { onCreateElement } = options;\n\n if (onCreateElement) {\n return {\n ...reactRuntime,\n createElement: (\n type: string | any,\n props: Record<string, any> | null,\n ...children: any[]\n ): ReactNode => {\n return onCreateElement(type, props, children);\n },\n };\n }\n\n return reactRuntime;\n};\n"],"mappings":";;;;;;;;AAaA,IAAI;AACJ,IAAI;CACF,MAAM,aAASA,qBAAc,KAAK;CAClC,qBACE,UACA,OAAO,WAAW,YAClB,cAAc,UACd,OAAO,OAAO,aAAa,WACtB,OAAO,WACR,OAAO,IAAI,4BAA4B;AAC/C,QAAQ;CACN,qBAAqB,OAAO,IAAI,4BAA4B;AAC9D;;;;;AAMA,MAAa,eAAgC;;;;;CAK3C,gBACE,MACA,OACA,GAAG,aACW;EACd,IAAI,MAAqB;EACzB,MAAM,aAAkB,SAAS,CAAC;EAElC,IAAI,SAAS,MAAM,OAAO,MAAM;GAC9B,MAAM,OAAO,MAAM,GAAG;GACtB,WAAW,MAAM;EACnB;EAEA,MAAM,aAAa,SAAS;EAC5B,IAAI,eAAe,GACjB,WAAW,WAAW,SAAS;OAC1B,IAAI,aAAa,GACtB,WAAW,WAAW;EAGxB,OAAO;GACL,UAAU;GACV;GACA;GACA,KAAK;GACL,OAAO;GACP,QAAQ;GACR,QAAQ,CAAC;GACT,aAAa;GACb,YAAY;EACd;CACF;;;;CAKA,eACE,SACA,OACA,GAAG,aACW;EACd,IAAI,SAAS,WAAW,GACtB,WAAOC,oBAAa,SAAyB,KAAK;EAEpD,WAAOA,oBAAa,SAAyB,OAAO,GAAG,QAAQ;CACjE;;;;CAKA;;;;;;;CAQA,iBACE,MACA,UACwB;EAIxB,OAAO;CACT;AACF;;;;;AAMA,MAAa,sBACX,UAMI,CAAC,MACe;CACpB,MAAM,EAAE,oBAAoB;CAE5B,IAAI,iBACF,OAAO;EACL,GAAG;EACH,gBACE,MACA,OACA,GAAG,aACW;GACd,OAAO,gBAAgB,MAAM,OAAO,QAAQ;EAC9C;CACF;CAGF,OAAO;AACT"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { reactRuntime } from "./runtime.mjs";
|
|
1
2
|
import { compile, parseMarkdown as parseMarkdown$1, renderMarkdownAst } from "@intlayer/core/markdown";
|
|
2
|
-
import { Fragment, cloneElement, createElement } from "react";
|
|
3
3
|
|
|
4
4
|
//#region src/markdown/processor.tsx
|
|
5
5
|
/**
|
|
@@ -8,15 +8,6 @@ import { Fragment, cloneElement, createElement } from "react";
|
|
|
8
8
|
* [simple-markdown v0.2.2](https://github.com/Khan/simple-markdown) from Khan Academy.
|
|
9
9
|
*/
|
|
10
10
|
/**
|
|
11
|
-
* Default React runtime for markdown rendering.
|
|
12
|
-
*/
|
|
13
|
-
const DEFAULT_RUNTIME = {
|
|
14
|
-
createElement,
|
|
15
|
-
cloneElement,
|
|
16
|
-
Fragment,
|
|
17
|
-
normalizeProps: (_tag, props) => props
|
|
18
|
-
};
|
|
19
|
-
/**
|
|
20
11
|
* **Step 1 of 2 — parse only.**
|
|
21
12
|
* Converts a raw markdown string into a `ParsedMarkdown` AST without rendering
|
|
22
13
|
* any React elements. Use this when you need to:
|
|
@@ -37,7 +28,7 @@ const DEFAULT_RUNTIME = {
|
|
|
37
28
|
const parseMarkdown = (markdown = "", options = {}) => {
|
|
38
29
|
const { disableAutoLink, disableParsingRawHTML, enforceAtxHeadings, forceBlock, forceInline, forceWrapper, namedCodesToUnicode, components, sanitizer, slugify, wrapper, preserveFrontmatter, tagfilter } = options;
|
|
39
30
|
return parseMarkdown$1(markdown, {
|
|
40
|
-
runtime:
|
|
31
|
+
runtime: reactRuntime,
|
|
41
32
|
components,
|
|
42
33
|
namedCodesToUnicode,
|
|
43
34
|
sanitizer,
|
|
@@ -73,9 +64,9 @@ const compileMarkdown = (input = "", options = {}) => {
|
|
|
73
64
|
const { createElement: customCreateElement, disableAutoLink, disableParsingRawHTML, enforceAtxHeadings, forceBlock, forceInline, forceWrapper, namedCodesToUnicode, components, renderRule, sanitizer, slugify, wrapper, preserveFrontmatter, tagfilter } = options;
|
|
74
65
|
const ctx = {
|
|
75
66
|
runtime: customCreateElement ? {
|
|
76
|
-
...
|
|
67
|
+
...reactRuntime,
|
|
77
68
|
createElement: customCreateElement
|
|
78
|
-
} :
|
|
69
|
+
} : reactRuntime,
|
|
79
70
|
components,
|
|
80
71
|
namedCodesToUnicode,
|
|
81
72
|
sanitizer,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"processor.mjs","names":["coreParseMarkdown","coreCompile","coreRenderMarkdownAst"],"sources":["../../../src/markdown/processor.tsx"],"sourcesContent":["/**\n * it's a fork\n * [markdown-to-jsx v7.7.14](https://github.com/quantizor/markdown-to-jsx) from quantizor\n * [simple-markdown v0.2.2](https://github.com/Khan/simple-markdown) from Khan Academy.\n */\n\nimport {\n compile as coreCompile,\n parseMarkdown as coreParseMarkdown,\n renderMarkdownAst as coreRenderMarkdownAst,\n type MarkdownContext,\n type MarkdownOptions,\n type
|
|
1
|
+
{"version":3,"file":"processor.mjs","names":["coreParseMarkdown","coreCompile","coreRenderMarkdownAst"],"sources":["../../../src/markdown/processor.tsx"],"sourcesContent":["/**\n * it's a fork\n * [markdown-to-jsx v7.7.14](https://github.com/quantizor/markdown-to-jsx) from quantizor\n * [simple-markdown v0.2.2](https://github.com/Khan/simple-markdown) from Khan Academy.\n */\n\nimport {\n compile as coreCompile,\n parseMarkdown as coreParseMarkdown,\n renderMarkdownAst as coreRenderMarkdownAst,\n type MarkdownContext,\n type MarkdownOptions,\n type ParsedMarkdown,\n type RenderRuleHook,\n} from '@intlayer/core/markdown';\nimport type { createElement, JSX, ReactNode } from 'react';\nimport type { HTMLComponents } from '../html/HTMLComponentTypes';\nimport { reactRuntime } from './runtime';\n\ntype HTMLTags = keyof JSX.IntrinsicElements;\n\n/**\n * Refined MarkdownRendererOptions type.\n */\nexport type MarkdownRendererOptions = Partial<{\n /**\n * Ultimate control over the output of all rendered JSX.\n */\n createElement: (\n tag: Parameters<typeof createElement>[0],\n props: JSX.IntrinsicAttributes,\n ...children: ReactNode[]\n ) => ReactNode;\n\n /**\n * The library automatically generates an anchor tag for bare URLs included in the markdown\n * document, but this behavior can be disabled if desired.\n */\n disableAutoLink: boolean;\n\n /**\n * Disable the compiler's best-effort transcription of provided raw HTML\n * into JSX-equivalent.\n */\n disableParsingRawHTML: boolean;\n\n /**\n * Forces the compiler to have space between hash sign and the header text.\n */\n enforceAtxHeadings: boolean;\n\n /**\n * Forces the compiler to always output content with a block-level wrapper.\n */\n forceBlock: boolean;\n\n /**\n * Forces the compiler to always output content with an inline wrapper.\n */\n forceInline: boolean;\n\n /**\n * Forces the compiler to wrap results, even if there is only a single child.\n */\n forceWrapper: boolean;\n\n /**\n * Supply additional HTML entity: unicode replacement mappings.\n */\n namedCodesToUnicode: {\n [key: string]: string;\n };\n\n /**\n * Selectively control the output of particular HTML tags.\n */\n components: HTMLComponents;\n\n /**\n * Allows for full control over rendering of particular rules.\n */\n renderRule: RenderRuleHook;\n\n /**\n * Override the built-in sanitizer function for URLs.\n */\n sanitizer: (value: string, tag: HTMLTags, attribute: string) => string | null;\n\n /**\n * Override normalization of non-URI-safe characters for anchor linking.\n */\n slugify: (input: string) => string;\n\n /**\n * Declare the type of the wrapper to be used when there are multiple children.\n */\n wrapper: any | null;\n\n /**\n * Whether to preserve frontmatter in the markdown content.\n */\n preserveFrontmatter: boolean;\n\n /**\n * Whether to use the GitHub Tag Filter.\n */\n tagfilter: boolean;\n}>;\n\n/**\n * Default React runtime for markdown rendering.\n */\n\n/**\n * Intermediate AST produced by `parseMarkdown`.\n * Pass this to `compileMarkdown` or `<MarkdownRenderer>` to skip re-parsing\n * when the same content is rendered multiple times.\n */\nexport type { ParsedMarkdown };\n\n/**\n * **Step 1 of 2 — parse only.**\n * Converts a raw markdown string into a `ParsedMarkdown` AST without rendering\n * any React elements. Use this when you need to:\n * - Cache the parsed result and render it several times with different options.\n * - Inspect or transform the AST before rendering.\n * - Defer the render step to a later point in the pipeline.\n *\n * @param markdown - The markdown source string.\n * @param options - Options that affect parsing (sanitizer, slugify, …).\n * @returns A `ParsedMarkdown` AST ready to be passed to `compileMarkdown`.\n *\n * @example\n * ```tsx\n * const ast = parseMarkdown('# Hello **world**');\n * const element = compileMarkdown(ast, { forceBlock: true });\n * ```\n */\nexport const parseMarkdown = (\n markdown: string = '',\n options: MarkdownRendererOptions = {}\n): ParsedMarkdown => {\n const {\n disableAutoLink,\n disableParsingRawHTML,\n enforceAtxHeadings,\n forceBlock,\n forceInline,\n forceWrapper,\n namedCodesToUnicode,\n components,\n sanitizer,\n slugify,\n wrapper,\n preserveFrontmatter,\n tagfilter,\n } = options;\n\n const ctx: MarkdownContext<HTMLComponents> = {\n runtime: reactRuntime,\n components,\n namedCodesToUnicode,\n sanitizer: sanitizer as any,\n slugify,\n };\n\n const compilerOptions: MarkdownOptions = {\n disableAutoLink,\n disableParsingRawHTML,\n enforceAtxHeadings,\n forceBlock,\n forceInline,\n forceWrapper,\n wrapper,\n preserveFrontmatter,\n tagfilter,\n };\n\n return coreParseMarkdown(markdown, ctx, compilerOptions);\n};\n\n/**\n * **Steps 1 + 2 — parse and render in one shot.**\n * Accepts a raw markdown string or a pre-parsed `ParsedMarkdown` AST and\n * returns a React element. Use `parseMarkdown` first when you need to reuse\n * the same AST with different options.\n *\n * @param input - Markdown string or pre-parsed AST.\n * @param options - Rendering options (custom components, sanitizer, slugify, …).\n * @returns A React JSX element representing the rendered markdown.\n *\n * @example\n * ```tsx\n * const element = compileMarkdown('# Hello **world**', { forceBlock: true });\n * ```\n */\nexport const compileMarkdown = (\n input: string | ParsedMarkdown = '',\n options: MarkdownRendererOptions = {}\n): JSX.Element => {\n const {\n createElement: customCreateElement,\n disableAutoLink,\n disableParsingRawHTML,\n enforceAtxHeadings,\n forceBlock,\n forceInline,\n forceWrapper,\n namedCodesToUnicode,\n components,\n renderRule,\n sanitizer,\n slugify,\n wrapper,\n preserveFrontmatter,\n tagfilter,\n } = options;\n\n const runtime = customCreateElement\n ? { ...reactRuntime, createElement: customCreateElement as any }\n : reactRuntime;\n\n const ctx: MarkdownContext<HTMLComponents> = {\n runtime,\n components,\n namedCodesToUnicode,\n sanitizer: sanitizer as any,\n slugify,\n };\n\n const compilerOptions: MarkdownOptions = {\n disableAutoLink,\n disableParsingRawHTML,\n enforceAtxHeadings,\n forceBlock,\n forceInline,\n forceWrapper,\n renderRule,\n wrapper,\n preserveFrontmatter,\n tagfilter,\n };\n\n if (typeof input === 'string') {\n return coreCompile(input, ctx, compilerOptions) as JSX.Element;\n }\n\n return coreRenderMarkdownAst(input, ctx, compilerOptions) as JSX.Element;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AA0IA,MAAa,iBACX,WAAmB,IACnB,UAAmC,CAAC,MACjB;CACnB,MAAM,EACJ,iBACA,uBACA,oBACA,YACA,aACA,cACA,qBACA,YACA,WACA,SACA,SACA,qBACA,cACE;CAsBJ,OAAOA,gBAAkB,UAAU;EAnBjC,SAAS;EACT;EACA;EACW;EACX;CAemC,GAAG;EAXtC;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CAGoD,CAAC;AACzD;;;;;;;;;;;;;;;;AAiBA,MAAa,mBACX,QAAiC,IACjC,UAAmC,CAAC,MACpB;CAChB,MAAM,EACJ,eAAe,qBACf,iBACA,uBACA,oBACA,YACA,aACA,cACA,qBACA,YACA,YACA,WACA,SACA,SACA,qBACA,cACE;CAMJ,MAAM,MAAuC;EAC3C,SALc,sBACZ;GAAE,GAAG;GAAc,eAAe;EAA2B,IAC7D;EAIF;EACA;EACW;EACX;CACF;CAEA,MAAM,kBAAmC;EACvC;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF;CAEA,IAAI,OAAO,UAAU,UACnB,OAAOC,QAAY,OAAO,KAAK,eAAe;CAGhD,OAAOC,kBAAsB,OAAO,KAAK,eAAe;AAC1D"}
|
|
@@ -5,15 +5,43 @@ import { Fragment, cloneElement, createElement } from "react";
|
|
|
5
5
|
* React-specific runtime for the markdown processor.
|
|
6
6
|
* Implements the MarkdownRuntime interface using React's primitives.
|
|
7
7
|
*/
|
|
8
|
+
let REACT_ELEMENT_TYPE;
|
|
9
|
+
try {
|
|
10
|
+
const sample = createElement("div");
|
|
11
|
+
REACT_ELEMENT_TYPE = sample && typeof sample === "object" && "$$typeof" in sample && typeof sample.$$typeof === "symbol" ? sample.$$typeof : Symbol.for("react.transitional.element");
|
|
12
|
+
} catch {
|
|
13
|
+
REACT_ELEMENT_TYPE = Symbol.for("react.transitional.element");
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* React-specific runtime for the markdown processor.
|
|
17
|
+
* Implements the MarkdownRuntime interface using React's primitives.
|
|
18
|
+
*/
|
|
8
19
|
const reactRuntime = {
|
|
9
20
|
/**
|
|
10
21
|
* Creates a React element.
|
|
11
22
|
* Handles the conversion of props and children to React format.
|
|
12
23
|
*/
|
|
13
24
|
createElement: (type, props, ...children) => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
25
|
+
let key = null;
|
|
26
|
+
const finalProps = props || {};
|
|
27
|
+
if (props && props.key != null) {
|
|
28
|
+
key = String(props.key);
|
|
29
|
+
finalProps.key = void 0;
|
|
30
|
+
}
|
|
31
|
+
const childCount = children.length;
|
|
32
|
+
if (childCount === 1) finalProps.children = children[0];
|
|
33
|
+
else if (childCount > 1) finalProps.children = children;
|
|
34
|
+
return {
|
|
35
|
+
$$typeof: REACT_ELEMENT_TYPE,
|
|
36
|
+
type,
|
|
37
|
+
key,
|
|
38
|
+
ref: null,
|
|
39
|
+
props: finalProps,
|
|
40
|
+
_owner: null,
|
|
41
|
+
_store: {},
|
|
42
|
+
_debugStack: null,
|
|
43
|
+
_debugTask: null
|
|
44
|
+
};
|
|
17
45
|
},
|
|
18
46
|
/**
|
|
19
47
|
* Clones a React element with new props.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.mjs","names":[],"sources":["../../../src/markdown/runtime.ts"],"sourcesContent":["import type { HTMLTag, MarkdownRuntime } from '@intlayer/core/markdown';\nimport {\n cloneElement,\n createElement,\n Fragment,\n type ReactElement,\n type ReactNode,\n} from 'react';\n\n/**\n * React-specific runtime for the markdown processor.\n * Implements the MarkdownRuntime interface using React's primitives.\n */\nexport const reactRuntime: MarkdownRuntime = {\n /**\n * Creates a React element.\n * Handles the conversion of props and children to React format.\n */\n createElement: (\n type: string | any,\n props: Record<string, any> | null,\n ...children: any[]\n ): ReactNode => {\n
|
|
1
|
+
{"version":3,"file":"runtime.mjs","names":[],"sources":["../../../src/markdown/runtime.ts"],"sourcesContent":["import type { HTMLTag, MarkdownRuntime } from '@intlayer/core/markdown';\nimport {\n cloneElement,\n createElement,\n Fragment,\n type ReactElement,\n type ReactNode,\n} from 'react';\n\n/**\n * React-specific runtime for the markdown processor.\n * Implements the MarkdownRuntime interface using React's primitives.\n */\nlet REACT_ELEMENT_TYPE: symbol;\ntry {\n const sample = createElement('div');\n REACT_ELEMENT_TYPE =\n sample &&\n typeof sample === 'object' &&\n '$$typeof' in sample &&\n typeof sample.$$typeof === 'symbol'\n ? (sample.$$typeof as symbol)\n : Symbol.for('react.transitional.element');\n} catch {\n REACT_ELEMENT_TYPE = Symbol.for('react.transitional.element');\n}\n\n/**\n * React-specific runtime for the markdown processor.\n * Implements the MarkdownRuntime interface using React's primitives.\n */\nexport const reactRuntime: MarkdownRuntime = {\n /**\n * Creates a React element.\n * Handles the conversion of props and children to React format.\n */\n createElement: (\n type: string | any,\n props: Record<string, any> | null,\n ...children: any[]\n ): ReactNode => {\n let key: string | null = null;\n const finalProps: any = props || {};\n\n if (props && props.key != null) {\n key = String(props.key);\n finalProps.key = undefined;\n }\n\n const childCount = children.length;\n if (childCount === 1) {\n finalProps.children = children[0];\n } else if (childCount > 1) {\n finalProps.children = children;\n }\n\n return {\n $$typeof: REACT_ELEMENT_TYPE,\n type,\n key,\n ref: null,\n props: finalProps,\n _owner: null,\n _store: {},\n _debugStack: null,\n _debugTask: null,\n } as unknown as ReactNode;\n },\n\n /**\n * Clones a React element with new props.\n */\n cloneElement: (\n element: unknown,\n props: Record<string, any>,\n ...children: any[]\n ): ReactNode => {\n if (children.length === 0) {\n return cloneElement(element as ReactElement, props);\n }\n return cloneElement(element as ReactElement, props, ...children);\n },\n\n /**\n * React Fragment component.\n */\n Fragment,\n\n /**\n * React-specific prop normalization.\n * React uses className instead of class, htmlFor instead of for, etc.\n * The core processor already handles ATTRIBUTE_TO_NODE_PROP_MAP,\n * so this is mostly a no-op but can be used for additional React-specific transforms.\n */\n normalizeProps: (\n _tag: HTMLTag,\n props: Record<string, any>\n ): Record<string, any> => {\n // The core already handles class -> className and for -> htmlFor\n // via ATTRIBUTE_TO_NODE_PROP_MAP in the attrStringToMap function.\n // This hook is available for any additional React-specific transforms.\n return props;\n },\n};\n\n/**\n * Creates a React runtime with custom createElement for advanced use cases.\n * Useful for wrapping elements or adding middleware.\n */\nexport const createReactRuntime = (\n options: {\n onCreateElement?: (\n type: string | any,\n props: Record<string, any> | null,\n children: any[]\n ) => ReactNode;\n } = {}\n): MarkdownRuntime => {\n const { onCreateElement } = options;\n\n if (onCreateElement) {\n return {\n ...reactRuntime,\n createElement: (\n type: string | any,\n props: Record<string, any> | null,\n ...children: any[]\n ): ReactNode => {\n return onCreateElement(type, props, children);\n },\n };\n }\n\n return reactRuntime;\n};\n"],"mappings":";;;;;;;AAaA,IAAI;AACJ,IAAI;CACF,MAAM,SAAS,cAAc,KAAK;CAClC,qBACE,UACA,OAAO,WAAW,YAClB,cAAc,UACd,OAAO,OAAO,aAAa,WACtB,OAAO,WACR,OAAO,IAAI,4BAA4B;AAC/C,QAAQ;CACN,qBAAqB,OAAO,IAAI,4BAA4B;AAC9D;;;;;AAMA,MAAa,eAAgC;;;;;CAK3C,gBACE,MACA,OACA,GAAG,aACW;EACd,IAAI,MAAqB;EACzB,MAAM,aAAkB,SAAS,CAAC;EAElC,IAAI,SAAS,MAAM,OAAO,MAAM;GAC9B,MAAM,OAAO,MAAM,GAAG;GACtB,WAAW,MAAM;EACnB;EAEA,MAAM,aAAa,SAAS;EAC5B,IAAI,eAAe,GACjB,WAAW,WAAW,SAAS;OAC1B,IAAI,aAAa,GACtB,WAAW,WAAW;EAGxB,OAAO;GACL,UAAU;GACV;GACA;GACA,KAAK;GACL,OAAO;GACP,QAAQ;GACR,QAAQ,CAAC;GACT,aAAa;GACb,YAAY;EACd;CACF;;;;CAKA,eACE,SACA,OACA,GAAG,aACW;EACd,IAAI,SAAS,WAAW,GACtB,OAAO,aAAa,SAAyB,KAAK;EAEpD,OAAO,aAAa,SAAyB,OAAO,GAAG,QAAQ;CACjE;;;;CAKA;;;;;;;CAQA,iBACE,MACA,UACwB;EAIxB,OAAO;CACT;AACF;;;;;AAMA,MAAa,sBACX,UAMI,CAAC,MACe;CACpB,MAAM,EAAE,oBAAoB;CAE5B,IAAI,iBACF,OAAO;EACL,GAAG;EACH,gBACE,MACA,OACA,GAAG,aACW;GACd,OAAO,gBAAgB,MAAM,OAAO,QAAQ;EAC9C;CACF;CAGF,OAAO;AACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"processor.d.ts","names":[],"sources":["../../../src/markdown/processor.tsx"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"processor.d.ts","names":[],"sources":["../../../src/markdown/processor.tsx"],"mappings":";;;;KAmBK,iBAAiB,IAAI;;;;YAKd,0BAA0B;;;;EAIpC,gBACE,KAAK,kBAAkB,mBACvB,OAAO,IAAI,wBACR,UAAU,gBACV;;;;;EAML;;;;;EAMA;;;;EAKA;;;;EAKA;;;;EAKA;;;;EAKA;;;;EAKA;KACG;;;;;EAMH,YAAY;;;;EAKZ,YAAY;;;;EAKZ,YAAY,eAAe,KAAK,UAAU;;;;EAK1C,UAAU;;;;EAKV;;;;EAKA;;;;EAKA;;;;;;;;;;;;;;;;;;;;qBAgCW,gBAAa,mBACR,UACP,4BACR;;;;;;;;;;;;;;;;qBAuDU,kBAAe,iBACV,gBAAc,UACrB,4BACR,IAAI"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.d.ts","names":[],"sources":["../../../src/markdown/runtime.ts"],"mappings":";;;;;;;
|
|
1
|
+
{"version":3,"file":"runtime.d.ts","names":[],"sources":["../../../src/markdown/runtime.ts"],"mappings":";;;;;;;qBA+Ba,cAAc;;;;;qBA8Ed,qBAAkB;EAE3B,mBACE,oBACA,OAAO,4BACP,oBACG;MAEN"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-intlayer",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.5.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Easily internationalize i18n your React applications with type-safe multilingual content management.",
|
|
6
6
|
"keywords": [
|
|
@@ -132,17 +132,17 @@
|
|
|
132
132
|
"typecheck": "tsc --noEmit --project tsconfig.types.json"
|
|
133
133
|
},
|
|
134
134
|
"dependencies": {
|
|
135
|
-
"@intlayer/api": "9.
|
|
136
|
-
"@intlayer/config": "9.
|
|
137
|
-
"@intlayer/core": "9.
|
|
138
|
-
"@intlayer/dictionaries-entry": "9.
|
|
139
|
-
"@intlayer/editor": "9.
|
|
140
|
-
"@intlayer/types": "9.
|
|
135
|
+
"@intlayer/api": "9.5.0",
|
|
136
|
+
"@intlayer/config": "9.5.0",
|
|
137
|
+
"@intlayer/core": "9.5.0",
|
|
138
|
+
"@intlayer/dictionaries-entry": "9.5.0",
|
|
139
|
+
"@intlayer/editor": "9.5.0",
|
|
140
|
+
"@intlayer/types": "9.5.0"
|
|
141
141
|
},
|
|
142
142
|
"devDependencies": {
|
|
143
143
|
"@craco/types": "7.1.0",
|
|
144
144
|
"@testing-library/react": "16.3.3",
|
|
145
|
-
"@types/node": "26.
|
|
145
|
+
"@types/node": "26.5.0",
|
|
146
146
|
"@types/react": ">=16.0.0",
|
|
147
147
|
"@types/react-dom": ">=16.0.0",
|
|
148
148
|
"@utils/ts-config": "1.0.4",
|
|
@@ -158,7 +158,7 @@
|
|
|
158
158
|
"react-dom": ">=16.0.0"
|
|
159
159
|
},
|
|
160
160
|
"optionalDependencies": {
|
|
161
|
-
"@intlayer/analytics": "9.
|
|
161
|
+
"@intlayer/analytics": "9.5.0"
|
|
162
162
|
},
|
|
163
163
|
"engines": {
|
|
164
164
|
"node": ">=14.18"
|