@intlayer/design-system 7.6.0-canary.1 → 8.0.0-canary.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.
Files changed (152) hide show
  1. package/dist/esm/components/CopyToClipboard/index.mjs +12 -9
  2. package/dist/esm/components/CopyToClipboard/index.mjs.map +1 -1
  3. package/dist/esm/components/DictionaryFieldEditor/DictionaryDetails/DictionaryDetailsForm.mjs +32 -1
  4. package/dist/esm/components/DictionaryFieldEditor/DictionaryDetails/DictionaryDetailsForm.mjs.map +1 -1
  5. package/dist/esm/components/DictionaryFieldEditor/DictionaryDetails/dictionaryDetails.content.mjs +116 -14
  6. package/dist/esm/components/DictionaryFieldEditor/DictionaryDetails/dictionaryDetails.content.mjs.map +1 -1
  7. package/dist/esm/components/DictionaryFieldEditor/DictionaryDetails/useDictionaryDetailsSchema.mjs +5 -0
  8. package/dist/esm/components/DictionaryFieldEditor/DictionaryDetails/useDictionaryDetailsSchema.mjs.map +1 -1
  9. package/dist/esm/components/DictionaryFieldEditor/DictionaryFieldEditor.mjs +11 -5
  10. package/dist/esm/components/DictionaryFieldEditor/DictionaryFieldEditor.mjs.map +1 -1
  11. package/dist/esm/components/Flags/Flag.mjs +5 -8
  12. package/dist/esm/components/Flags/Flag.mjs.map +1 -1
  13. package/dist/esm/components/MarkDownRender/MarkDownRender.mjs +1 -1
  14. package/dist/esm/components/MarkDownRender/MarkDownRender.mjs.map +1 -1
  15. package/dist/esm/components/MarkDownRender/index.mjs +2 -1
  16. package/dist/esm/components/MarkDownRender/processor-adapter.mjs +57 -0
  17. package/dist/esm/components/MarkDownRender/processor-adapter.mjs.map +1 -0
  18. package/dist/esm/components/MarkDownRender/processor.mjs +5 -5
  19. package/dist/esm/components/MarkDownRender/processor.mjs.map +1 -1
  20. package/dist/esm/components/Popover/static.mjs +12 -10
  21. package/dist/esm/components/Popover/static.mjs.map +1 -1
  22. package/dist/esm/components/RightDrawer/RightDrawer.mjs +4 -5
  23. package/dist/esm/components/RightDrawer/RightDrawer.mjs.map +1 -1
  24. package/dist/esm/components/RightDrawer/index.mjs +2 -2
  25. package/dist/esm/components/RightDrawer/useRightDrawer.mjs +65 -0
  26. package/dist/esm/components/RightDrawer/useRightDrawer.mjs.map +1 -0
  27. package/dist/esm/components/index.mjs +3 -2
  28. package/dist/esm/hooks/useScrollBlockage/index.mjs +1 -6
  29. package/dist/esm/hooks/useScrollBlockage/index.mjs.map +1 -1
  30. package/dist/esm/hooks/useScrollBlockage/useScrollBlockageStore.mjs +60 -31
  31. package/dist/esm/hooks/useScrollBlockage/useScrollBlockageStore.mjs.map +1 -1
  32. package/dist/types/components/Badge/index.d.ts +2 -2
  33. package/dist/types/components/Breadcrumb/breadcrumb.content.d.ts +3 -3
  34. package/dist/types/components/Breadcrumb/index.d.ts +2 -2
  35. package/dist/types/components/Browser/Browser.content.d.ts +17 -17
  36. package/dist/types/components/Browser/Browser.d.ts +2 -2
  37. package/dist/types/components/Browser/Browser.d.ts.map +1 -1
  38. package/dist/types/components/Button/Button.d.ts +7 -7
  39. package/dist/types/components/CollapsibleTable/CollapsibleTable.d.ts +3 -3
  40. package/dist/types/components/CollapsibleTable/CollapsibleTable.d.ts.map +1 -1
  41. package/dist/types/components/Command/index.d.ts +16 -16
  42. package/dist/types/components/Command/index.d.ts.map +1 -1
  43. package/dist/types/components/Container/index.d.ts +10 -10
  44. package/dist/types/components/Container/index.d.ts.map +1 -1
  45. package/dist/types/components/CopyButton/CopyButton.content.d.ts +3 -3
  46. package/dist/types/components/CopyButton/CopyButton.content.d.ts.map +1 -1
  47. package/dist/types/components/CopyToClipboard/index.d.ts +18 -7
  48. package/dist/types/components/CopyToClipboard/index.d.ts.map +1 -1
  49. package/dist/types/components/DictionaryFieldEditor/DictionaryCreationForm/dictionaryCreationForm.content.d.ts +25 -25
  50. package/dist/types/components/DictionaryFieldEditor/DictionaryCreationForm/useDictionaryFormSchema.content.d.ts +9 -9
  51. package/dist/types/components/DictionaryFieldEditor/DictionaryDetails/DictionaryDetailsForm.d.ts.map +1 -1
  52. package/dist/types/components/DictionaryFieldEditor/DictionaryDetails/dictionaryDetails.content.d.ts +265 -48
  53. package/dist/types/components/DictionaryFieldEditor/DictionaryDetails/dictionaryDetails.content.d.ts.map +1 -1
  54. package/dist/types/components/DictionaryFieldEditor/DictionaryDetails/useDictionaryDetailsSchema.content.d.ts +33 -33
  55. package/dist/types/components/DictionaryFieldEditor/DictionaryDetails/useDictionaryDetailsSchema.content.d.ts.map +1 -1
  56. package/dist/types/components/DictionaryFieldEditor/DictionaryDetails/useDictionaryDetailsSchema.d.ts +6 -1
  57. package/dist/types/components/DictionaryFieldEditor/DictionaryDetails/useDictionaryDetailsSchema.d.ts.map +1 -1
  58. package/dist/types/components/DictionaryFieldEditor/DictionaryFieldEditor.d.ts.map +1 -1
  59. package/dist/types/components/DictionaryFieldEditor/NavigationView/navigationViewNode.content.d.ts +25 -25
  60. package/dist/types/components/DictionaryFieldEditor/SaveForm/saveForm.content.d.ts +33 -33
  61. package/dist/types/components/DictionaryFieldEditor/StructureView/structureView.content.d.ts +9 -9
  62. package/dist/types/components/DictionaryFieldEditor/VersionSwitcherDropDown/versionSwitcherDropDown.content.d.ts +7 -7
  63. package/dist/types/components/DictionaryFieldEditor/dictionaryFieldEditor.content.d.ts +5 -5
  64. package/dist/types/components/DictionaryFieldEditor/nodeTypeSelector.content.d.ts +31 -31
  65. package/dist/types/components/DictionaryFieldEditor/nodeTypeSelector.content.d.ts.map +1 -1
  66. package/dist/types/components/ExpandCollapse/expandCollapse.content.d.ts +3 -3
  67. package/dist/types/components/Form/FormBase.d.ts +2 -2
  68. package/dist/types/components/Form/FormField.d.ts +2 -2
  69. package/dist/types/components/Form/FormItem.d.ts +2 -2
  70. package/dist/types/components/Form/FormItem.d.ts.map +1 -1
  71. package/dist/types/components/Form/elements/EditableFieldInputElement.d.ts +2 -2
  72. package/dist/types/components/Form/elements/EditableFieldTextAreaElement.d.ts +2 -2
  73. package/dist/types/components/Form/elements/EditableFieldTextAreaElement.d.ts.map +1 -1
  74. package/dist/types/components/Form/elements/FormElement.d.ts +2 -2
  75. package/dist/types/components/Form/elements/FormElement.d.ts.map +1 -1
  76. package/dist/types/components/Form/elements/MultiselectElement.d.ts +2 -2
  77. package/dist/types/components/Form/elements/MultiselectElement.d.ts.map +1 -1
  78. package/dist/types/components/Form/elements/OTPElement.d.ts +2 -2
  79. package/dist/types/components/Form/elements/OTPElement.d.ts.map +1 -1
  80. package/dist/types/components/Form/elements/SelectElement.d.ts +2 -2
  81. package/dist/types/components/Form/elements/SelectElement.d.ts.map +1 -1
  82. package/dist/types/components/Form/elements/SwitchSelectorElement.d.ts +2 -2
  83. package/dist/types/components/Form/elements/SwitchSelectorElement.d.ts.map +1 -1
  84. package/dist/types/components/IDE/CodeContext.d.ts +2 -2
  85. package/dist/types/components/IDE/CodeContext.d.ts.map +1 -1
  86. package/dist/types/components/IDE/code.content.d.ts +5 -5
  87. package/dist/types/components/IDE/copyCode.content.d.ts +5 -5
  88. package/dist/types/components/IDE/selectors.content.d.ts +13 -13
  89. package/dist/types/components/Input/Checkbox.d.ts +4 -4
  90. package/dist/types/components/Input/Checkbox.d.ts.map +1 -1
  91. package/dist/types/components/Input/Input.d.ts +3 -3
  92. package/dist/types/components/Input/Input.d.ts.map +1 -1
  93. package/dist/types/components/Input/OTPInput.d.ts +6 -6
  94. package/dist/types/components/Input/SearchInput.d.ts +2 -2
  95. package/dist/types/components/Link/Link.d.ts +5 -5
  96. package/dist/types/components/Loader/index.content.d.ts +3 -3
  97. package/dist/types/components/Loader/index.content.d.ts.map +1 -1
  98. package/dist/types/components/Loader/spinner.d.ts +2 -2
  99. package/dist/types/components/Loader/spinner.d.ts.map +1 -1
  100. package/dist/types/components/LocaleSwitcherContentDropDown/localeSwitcher.content.d.ts +17 -17
  101. package/dist/types/components/LocaleSwitcherDropDown/localeSwitcher.content.d.ts +13 -13
  102. package/dist/types/components/MarkDownRender/MarkDownRender.d.ts +1 -1
  103. package/dist/types/components/MarkDownRender/MarkDownRender.d.ts.map +1 -1
  104. package/dist/types/components/MarkDownRender/index.d.ts +2 -1
  105. package/dist/types/components/MarkDownRender/processor-adapter.d.ts +85 -0
  106. package/dist/types/components/MarkDownRender/processor-adapter.d.ts.map +1 -0
  107. package/dist/types/components/MaxWidthSmoother/index.d.ts +2 -2
  108. package/dist/types/components/Navbar/Burger.d.ts +2 -2
  109. package/dist/types/components/Navbar/Burger.d.ts.map +1 -1
  110. package/dist/types/components/Navbar/DesktopNavbar.d.ts +2 -2
  111. package/dist/types/components/Navbar/MobileNavbar.d.ts +2 -2
  112. package/dist/types/components/Navbar/MobileNavbar.d.ts.map +1 -1
  113. package/dist/types/components/Navbar/index.d.ts +2 -2
  114. package/dist/types/components/Pagination/Pagination.d.ts +4 -4
  115. package/dist/types/components/Pagination/Pagination.d.ts.map +1 -1
  116. package/dist/types/components/Pagination/pagination.content.d.ts +11 -11
  117. package/dist/types/components/Popover/static.d.ts +11 -9
  118. package/dist/types/components/Popover/static.d.ts.map +1 -1
  119. package/dist/types/components/RightDrawer/index.d.ts +2 -2
  120. package/dist/types/components/RightDrawer/rightDrawer.content.d.ts +5 -5
  121. package/dist/types/components/RightDrawer/useRightDrawer.d.ts +22 -0
  122. package/dist/types/components/RightDrawer/useRightDrawer.d.ts.map +1 -0
  123. package/dist/types/components/Select/Select.d.ts +3 -3
  124. package/dist/types/components/Select/Select.d.ts.map +1 -1
  125. package/dist/types/components/SocialNetworks/index.d.ts +2 -2
  126. package/dist/types/components/SocialNetworks/index.d.ts.map +1 -1
  127. package/dist/types/components/SwitchSelector/index.d.ts +7 -7
  128. package/dist/types/components/SwitchSelector/index.d.ts.map +1 -1
  129. package/dist/types/components/Tab/Tab.d.ts +6 -6
  130. package/dist/types/components/Tab/Tab.d.ts.map +1 -1
  131. package/dist/types/components/Tab/TabContext.d.ts +2 -2
  132. package/dist/types/components/Tab/TabContext.d.ts.map +1 -1
  133. package/dist/types/components/TabSelector/TabSelector.d.ts +5 -5
  134. package/dist/types/components/TabSelector/TabSelector.d.ts.map +1 -1
  135. package/dist/types/components/Table/table.content.d.ts +3 -3
  136. package/dist/types/components/Tag/index.d.ts +5 -5
  137. package/dist/types/components/Terminal/terminal.content.d.ts +5 -5
  138. package/dist/types/components/Terminal/terminal.content.d.ts.map +1 -1
  139. package/dist/types/components/Toaster/Toast.d.ts +2 -2
  140. package/dist/types/components/Toaster/Toast.d.ts.map +1 -1
  141. package/dist/types/components/Toaster/Toaster.d.ts +2 -2
  142. package/dist/types/components/Toaster/Toaster.d.ts.map +1 -1
  143. package/dist/types/components/index.d.ts +3 -2
  144. package/dist/types/hooks/useDevice.d.ts.map +1 -1
  145. package/dist/types/hooks/useScrollBlockage/index.d.ts.map +1 -1
  146. package/dist/types/hooks/useScrollBlockage/useScrollBlockageStore.d.ts +14 -6
  147. package/dist/types/hooks/useScrollBlockage/useScrollBlockageStore.d.ts.map +1 -1
  148. package/package.json +21 -21
  149. package/dist/esm/components/RightDrawer/useRightDrawerStore.mjs +0 -87
  150. package/dist/esm/components/RightDrawer/useRightDrawerStore.mjs.map +0 -1
  151. package/dist/types/components/RightDrawer/useRightDrawerStore.d.ts +0 -116
  152. package/dist/types/components/RightDrawer/useRightDrawerStore.d.ts.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"MarkDownRender.mjs","names":[],"sources":["../../../../src/components/MarkDownRender/MarkDownRender.tsx"],"sourcesContent":["import type { LocalesValues } from '@intlayer/types';\nimport { cn } from '@utils/cn';\nimport type { ComponentProps, ComponentPropsWithoutRef, FC } from 'react';\nimport type { BundledLanguage } from 'shiki/bundle/web';\nimport { H1, H2, H3, H4, H5, H6 } from '../Headers';\nimport type { CodeCompAttributes } from '../IDE/Code';\nimport { Code } from '../IDE/Code';\nimport { CodeProvider } from '../IDE/CodeContext';\nimport { Link } from '../Link';\nimport { Tab } from '../Tab';\nimport { TabProvider } from '../Tab/TabContext';\nimport { Table } from '../Table';\nimport { MarkdownProcessor, type MarkdownProcessorOptions } from './processor';\n\ntype MarkdownRendererProps = {\n children: string;\n isDarkMode?: boolean;\n locale?: LocalesValues;\n options?: MarkdownProcessorOptions;\n};\n\n/**\n * Removes frontmatter from markdown content\n * Frontmatter is the YAML metadata block at the beginning of markdown files\n * delimited by --- at the start and end\n */\nconst stripFrontmatter = (markdown: string): string => {\n const lines = markdown.split(/\\r?\\n/);\n\n // Check if the very first non-empty line is the metadata start delimiter\n const firstNonEmptyLine = lines.find((line) => line.trim() !== '');\n\n if (!firstNonEmptyLine || firstNonEmptyLine.trim() !== '---') {\n // No frontmatter, return original content\n return markdown;\n }\n\n let inMetadataBlock = false;\n let endOfMetadataIndex = -1;\n\n for (let i = 0; i < lines.length; i++) {\n const trimmedLine = lines[i].trim();\n\n // Toggle metadata block on encountering the delimiter\n if (trimmedLine === '---') {\n if (!inMetadataBlock) {\n // Begin metadata block\n inMetadataBlock = true;\n } else {\n // End of metadata block\n endOfMetadataIndex = i;\n break;\n }\n }\n }\n\n if (endOfMetadataIndex > -1) {\n // Return content after the frontmatter\n return lines.slice(endOfMetadataIndex + 1).join('\\n');\n }\n\n // If we couldn't find the end delimiter, return original content\n return markdown;\n};\n\n/**\n * MarkdownRenderer Component\n *\n * A comprehensive markdown renderer that transforms markdown text into rich,\n * interactive HTML with custom styling and Intlayer integration. Supports\n * code syntax highlighting, responsive tables, internationalized links,\n * and automatic frontmatter stripping.\n *\n * @component\n * @example\n * Basic usage:\n * ```tsx\n * const markdownContent = `\n * # Hello World\n * This is **bold** and *italic* text.\n * `;\n *\n * <MarkdownRenderer>{markdownContent}</MarkdownRenderer>\n * ```\n *\n * @example\n * With dark mode:\n * ```tsx\n * const codeExample = `\n * # API Documentation\n * \\`\\`\\`javascript\n * const response = await fetch('/api/data');\n * const data = await response.json();\n * \\`\\`\\`\n * `;\n *\n * <MarkdownRenderer isDarkMode={true}>\n * {codeExample}\n * </MarkdownRenderer>\n * ```\n *\n * @example\n * With internationalized links:\n * ```tsx\n * const content = `\n * Visit our [documentation](/docs) for more information.\n * External link: [Google](https://google.com)\n * `;\n *\n * <MarkdownRenderer locale=\"fr\">\n * {content}\n * </MarkdownRenderer>\n * ```\n *\n * @example\n * With custom overrides:\n * ```tsx\n * const customOptions = {\n * overrides: {\n * h1: ({ children }) => (\n * <h1 className=\"custom-title\">{children}</h1>\n * ),\n * },\n * };\n *\n * <MarkdownRenderer options={customOptions}>\n * {markdownContent}\n * </MarkdownRenderer>\n * ```\n *\n * @example\n * With frontmatter (automatically stripped):\n * ```tsx\n * const blogPost = `\n * ---\n * title: \"My Blog Post\"\n * date: \"2023-12-01\"\n * author: \"John Doe\"\n * ---\n * # My Blog Post\n * This content will be rendered without the frontmatter.\n * `;\n *\n * <MarkdownRenderer>{blogPost}</MarkdownRenderer>\n * ```\n *\n * Features:\n * - Automatic frontmatter detection and removal\n * - Syntax-highlighted code blocks with theme support\n * - Clickable headers with anchor links\n * - Internationalized link handling with locale awareness\n * - Responsive tables with hover effects\n * - Custom blockquote, list, and image styling\n * - External link detection and security attributes\n * - Inline code with distinctive styling\n * - Lazy-loaded images with GitHub raw URL support\n * - Horizontal rules with custom styling\n *\n * Supported Markdown Elements:\n * - Headers (h1-h4) with click-to-anchor functionality\n * - Code blocks with language-specific syntax highlighting\n * - Inline code with background styling\n * - Blockquotes with custom border and padding\n * - Ordered and unordered lists with custom spacing\n * - Links (internal and external) with security attributes\n * - Images with lazy loading and responsive sizing\n * - Tables with hover effects and proper styling\n * - Horizontal rules with custom appearance\n * - All standard markdown formatting (bold, italic, etc.)\n *\n * Code Block Support:\n * - Language detection from code fence info\n * - Syntax highlighting through Code component\n * - Dark/light mode theme switching\n * - Line numbers and copy functionality (via Code component)\n * - Support for popular languages (JS, TS, Python, etc.)\n *\n * Link Handling:\n * - Automatic external link detection (starts with 'http')\n * - Security attributes for external links (rel=\"noopener noreferrer\")\n * - Locale-aware internal link routing\n * - Custom Link component integration\n * - Underlined styling for better visibility\n *\n * Image Processing:\n * - Automatic lazy loading for performance\n * - GitHub raw URL transformation for repository images\n * - Responsive sizing with max-width constraints\n * - Rounded corners for visual appeal\n *\n * Accessibility:\n * - Semantic HTML structure with proper heading hierarchy\n * - ARIA attributes through component integration\n * - Screen reader friendly link descriptions\n * - Keyboard navigation support\n * - High contrast styling options\n *\n * Performance:\n * - Lazy loading for images\n * - Efficient re-rendering with React memo patterns\n * - Code syntax highlighting with minimal bundle impact\n * - Optimized markdown parsing with markdown-to-jsx\n *\n * @param props - Component props\n * @param props.children - Raw markdown content to render\n * @param props.isDarkMode - Enable dark mode styling for code blocks\n * @param props.locale - Current locale for link internationalization\n * @param props.options - Additional markdown-to-jsx options\n * @param props.options.overrides - Custom component overrides for markdown elements\n *\n * @returns Rendered markdown content with custom styling and functionality\n */\nexport const MarkdownRenderer: FC<MarkdownRendererProps> = ({\n children,\n isDarkMode,\n locale,\n options,\n}) => {\n const { overrides, ...restOptions } = options ?? {};\n\n // Strip frontmatter from the markdown content before rendering\n const cleanMarkdown = stripFrontmatter(children);\n\n return (\n <CodeProvider>\n <TabProvider>\n <MarkdownProcessor\n options={{\n overrides: {\n h1: (props: ComponentProps<typeof H1>) => (\n <H1 isClickable={true} {...props} />\n ),\n h2: (props: ComponentProps<typeof H2>) => (\n <H2 isClickable={true} className=\"mt-16\" {...props} />\n ),\n h3: (props: ComponentProps<typeof H3>) => (\n <H3 isClickable={true} className=\"mt-5\" {...props} />\n ),\n h4: (props: ComponentProps<typeof H4>) => (\n <H4 isClickable={true} className=\"mt-3\" {...props} />\n ),\n h5: (props: ComponentProps<typeof H5>) => (\n <H5 isClickable={true} className=\"mt-3\" {...props} />\n ),\n h6: (props: ComponentProps<typeof H6>) => (\n <H6 isClickable={true} className=\"mt-3\" {...props} />\n ),\n\n code: (\n props: Omit<ComponentPropsWithoutRef<'code'>, 'children'> &\n Partial<CodeCompAttributes> & { children: string }\n ) =>\n !props.className ? (\n <strong className=\"rounded bg-card/60 box-decoration-clone px-1 py-0.5\">\n {props.children}\n </strong>\n ) : (\n <Code\n {...props}\n isDarkMode={isDarkMode}\n language={\n (props.className?.replace('lang-', '') ||\n 'plaintext') as BundledLanguage\n }\n fileName={props.fileName}\n showHeader={Boolean(\n props.fileName ||\n props.packageManager ||\n props.codeFormat ||\n props.contentDeclarationFormat\n )}\n />\n ),\n\n blockquote: ({\n className,\n ...props\n }: ComponentPropsWithoutRef<'blockquote'>) => (\n <blockquote\n className={cn(\n 'mt-5 gap-3 border-card border-l-4 pl-5 text-neutral',\n className\n )}\n {...props}\n />\n ),\n ul: ({ className, ...props }: ComponentPropsWithoutRef<'ul'>) => (\n <ul\n className={cn(\n 'mt-5 flex list-disc flex-col gap-3 pl-5',\n className\n )}\n {...props}\n />\n ),\n ol: ({ className, ...props }: ComponentPropsWithoutRef<'ol'>) => (\n <ol\n className={cn(\n 'mt-5 flex list-decimal flex-col gap-3 pl-5',\n className\n )}\n {...props}\n />\n ),\n img: ({\n className,\n ...props\n }: ComponentPropsWithoutRef<'img'>) => (\n <img\n {...props}\n loading=\"lazy\"\n className={cn(\n 'max-h-[80vh] max-w-full rounded-md',\n className\n )}\n src={`${props.src}?raw=true`}\n />\n ),\n a: (props: ComponentProps<typeof Link>) => (\n <Link\n color=\"neutral\"\n isExternalLink={props.href?.startsWith('http')}\n underlined={true}\n locale={locale}\n {...props}\n />\n ),\n pre: (props: ComponentPropsWithoutRef<'pre'>) => props.children,\n\n table: (props: ComponentProps<typeof Table>) => (\n <Table isRollable={true} {...props} />\n ),\n th: ({ className, ...props }: ComponentPropsWithoutRef<'th'>) => (\n <th\n className={cn(\n 'border-neutral border-b bg-neutral/10 p-4',\n className\n )}\n {...props}\n />\n ),\n tr: ({ className, ...props }: ComponentPropsWithoutRef<'tr'>) => (\n <tr\n className={cn('hover:/10 hover:bg-neutral/10', className)}\n {...props}\n />\n ),\n td: ({ className, ...props }: ComponentPropsWithoutRef<'td'>) => (\n <td\n className={cn(\n 'border-neutral-500/50 border-b p-4',\n className\n )}\n {...props}\n />\n ),\n hr: ({ className, ...props }: ComponentPropsWithoutRef<'hr'>) => (\n <hr\n className={cn('mx-6 mt-16 text-neutral', className)}\n {...props}\n />\n ),\n // Support both <Tab> and <Tabs> in markdown\n Tabs: (props: ComponentProps<typeof Tab>) => (\n <Tab\n {...props}\n headerClassName=\"sticky top-36 z-10 bg-background/70 backdrop-blur\"\n />\n ),\n Tab: (props: ComponentProps<typeof Tab>) => (\n <Tab\n {...props}\n headerClassName=\"sticky top-36 z-10 bg-background/70 backdrop-blur\"\n />\n ),\n TabItem: (props: ComponentProps<typeof Tab.Item>) => (\n <Tab.Item {...props} />\n ),\n Columns: ({\n className,\n ...props\n }: ComponentPropsWithoutRef<'div'>) => (\n <div\n className={cn('flex gap-4 max-md:flex-col', className)}\n {...props}\n />\n ),\n Column: ({\n className,\n ...props\n }: ComponentPropsWithoutRef<'div'>) => (\n <div className={cn('flex-1', className)} {...props} />\n ),\n ...overrides,\n },\n ...restOptions,\n }}\n >\n {cleanMarkdown ?? ''}\n </MarkdownProcessor>\n </TabProvider>\n </CodeProvider>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;AA0BA,MAAM,oBAAoB,aAA6B;CACrD,MAAM,QAAQ,SAAS,MAAM,QAAQ;CAGrC,MAAM,oBAAoB,MAAM,MAAM,SAAS,KAAK,MAAM,KAAK,GAAG;AAElE,KAAI,CAAC,qBAAqB,kBAAkB,MAAM,KAAK,MAErD,QAAO;CAGT,IAAI,kBAAkB;CACtB,IAAI,qBAAqB;AAEzB,MAAK,IAAI,IAAI,GAAG,IAAI,MAAM,QAAQ,IAIhC,KAHoB,MAAM,GAAG,MAAM,KAGf,MAClB,KAAI,CAAC,gBAEH,mBAAkB;MACb;AAEL,uBAAqB;AACrB;;AAKN,KAAI,qBAAqB,GAEvB,QAAO,MAAM,MAAM,qBAAqB,EAAE,CAAC,KAAK,KAAK;AAIvD,QAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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YAEH,oBAAC;KACC,GAAI;KACJ,SAAQ;KACR,WAAW,GACT,sCACA,UACD;KACD,KAAK,GAAG,MAAM,IAAI;MAClB;IAEJ,IAAI,UACF,oBAAC;KACC,OAAM;KACN,gBAAgB,MAAM,MAAM,WAAW,OAAO;KAC9C,YAAY;KACJ;KACR,GAAI;MACJ;IAEJ,MAAM,UAA2C,MAAM;IAEvD,QAAQ,UACN,oBAAC;KAAM,YAAY;KAAM,GAAI;MAAS;IAExC,KAAK,EAAE,WAAW,GAAG,YACnB,oBAAC;KACC,WAAW,GACT,6CACA,UACD;KACD,GAAI;MACJ;IAEJ,KAAK,EAAE,WAAW,GAAG,YACnB,oBAAC;KACC,WAAW,GAAG,iCAAiC,UAAU;KACzD,GAAI;MACJ;IAEJ,KAAK,EAAE,WAAW,GAAG,YACnB,oBAAC;KACC,WAAW,GACT,sCACA,UACD;KACD,GAAI;MACJ;IAEJ,KAAK,EAAE,WAAW,GAAG,YACnB,oBAAC;KACC,WAAW,GAAG,2BAA2B,UAAU;KACnD,GAAI;MACJ;IAGJ,OAAO,UACL,oBAAC;KACC,GAAI;KACJ,iBAAgB;MAChB;IAEJ,MAAM,UACJ,oBAAC;KACC,GAAI;KACJ,iBAAgB;MAChB;IAEJ,UAAU,UACR,oBAAC,IAAI,QAAK,GAAI,QAAS;IAEzB,UAAU,EACR,WACA,GAAG,YAEH,oBAAC;KACC,WAAW,GAAG,8BAA8B,UAAU;KACtD,GAAI;MACJ;IAEJ,SAAS,EACP,WACA,GAAG,YAEH,oBAAC;KAAI,WAAW,GAAG,UAAU,UAAU;KAAE,GAAI;MAAS;IAExD,GAAG;IACJ;GACD,GAAG;GACJ;YAEA,iBAAiB;GACA,GACR,GACD"}
1
+ {"version":3,"file":"MarkDownRender.mjs","names":[],"sources":["../../../../src/components/MarkDownRender/MarkDownRender.tsx"],"sourcesContent":["import type { LocalesValues } from '@intlayer/types';\nimport { cn } from '@utils/cn';\nimport type { ComponentProps, ComponentPropsWithoutRef, FC } from 'react';\nimport type { BundledLanguage } from 'shiki/bundle/web';\nimport { H1, H2, H3, H4, H5, H6 } from '../Headers';\nimport type { CodeCompAttributes } from '../IDE/Code';\nimport { Code } from '../IDE/Code';\nimport { CodeProvider } from '../IDE/CodeContext';\nimport { Link } from '../Link';\nimport { Tab } from '../Tab';\nimport { TabProvider } from '../Tab/TabContext';\nimport { Table } from '../Table';\nimport {\n MarkdownProcessor,\n type MarkdownProcessorOptions,\n} from './processor-adapter';\n\ntype MarkdownRendererProps = {\n children: string;\n isDarkMode?: boolean;\n locale?: LocalesValues;\n options?: MarkdownProcessorOptions;\n};\n\n/**\n * Removes frontmatter from markdown content\n * Frontmatter is the YAML metadata block at the beginning of markdown files\n * delimited by --- at the start and end\n */\nconst stripFrontmatter = (markdown: string): string => {\n const lines = markdown.split(/\\r?\\n/);\n\n // Check if the very first non-empty line is the metadata start delimiter\n const firstNonEmptyLine = lines.find((line) => line.trim() !== '');\n\n if (!firstNonEmptyLine || firstNonEmptyLine.trim() !== '---') {\n // No frontmatter, return original content\n return markdown;\n }\n\n let inMetadataBlock = false;\n let endOfMetadataIndex = -1;\n\n for (let i = 0; i < lines.length; i++) {\n const trimmedLine = lines[i].trim();\n\n // Toggle metadata block on encountering the delimiter\n if (trimmedLine === '---') {\n if (!inMetadataBlock) {\n // Begin metadata block\n inMetadataBlock = true;\n } else {\n // End of metadata block\n endOfMetadataIndex = i;\n break;\n }\n }\n }\n\n if (endOfMetadataIndex > -1) {\n // Return content after the frontmatter\n return lines.slice(endOfMetadataIndex + 1).join('\\n');\n }\n\n // If we couldn't find the end delimiter, return original content\n return markdown;\n};\n\n/**\n * MarkdownRenderer Component\n *\n * A comprehensive markdown renderer that transforms markdown text into rich,\n * interactive HTML with custom styling and Intlayer integration. Supports\n * code syntax highlighting, responsive tables, internationalized links,\n * and automatic frontmatter stripping.\n *\n * @component\n * @example\n * Basic usage:\n * ```tsx\n * const markdownContent = `\n * # Hello World\n * This is **bold** and *italic* text.\n * `;\n *\n * <MarkdownRenderer>{markdownContent}</MarkdownRenderer>\n * ```\n *\n * @example\n * With dark mode:\n * ```tsx\n * const codeExample = `\n * # API Documentation\n * \\`\\`\\`javascript\n * const response = await fetch('/api/data');\n * const data = await response.json();\n * \\`\\`\\`\n * `;\n *\n * <MarkdownRenderer isDarkMode={true}>\n * {codeExample}\n * </MarkdownRenderer>\n * ```\n *\n * @example\n * With internationalized links:\n * ```tsx\n * const content = `\n * Visit our [documentation](/docs) for more information.\n * External link: [Google](https://google.com)\n * `;\n *\n * <MarkdownRenderer locale=\"fr\">\n * {content}\n * </MarkdownRenderer>\n * ```\n *\n * @example\n * With custom overrides:\n * ```tsx\n * const customOptions = {\n * overrides: {\n * h1: ({ children }) => (\n * <h1 className=\"custom-title\">{children}</h1>\n * ),\n * },\n * };\n *\n * <MarkdownRenderer options={customOptions}>\n * {markdownContent}\n * </MarkdownRenderer>\n * ```\n *\n * @example\n * With frontmatter (automatically stripped):\n * ```tsx\n * const blogPost = `\n * ---\n * title: \"My Blog Post\"\n * date: \"2023-12-01\"\n * author: \"John Doe\"\n * ---\n * # My Blog Post\n * This content will be rendered without the frontmatter.\n * `;\n *\n * <MarkdownRenderer>{blogPost}</MarkdownRenderer>\n * ```\n *\n * Features:\n * - Automatic frontmatter detection and removal\n * - Syntax-highlighted code blocks with theme support\n * - Clickable headers with anchor links\n * - Internationalized link handling with locale awareness\n * - Responsive tables with hover effects\n * - Custom blockquote, list, and image styling\n * - External link detection and security attributes\n * - Inline code with distinctive styling\n * - Lazy-loaded images with GitHub raw URL support\n * - Horizontal rules with custom styling\n *\n * Supported Markdown Elements:\n * - Headers (h1-h4) with click-to-anchor functionality\n * - Code blocks with language-specific syntax highlighting\n * - Inline code with background styling\n * - Blockquotes with custom border and padding\n * - Ordered and unordered lists with custom spacing\n * - Links (internal and external) with security attributes\n * - Images with lazy loading and responsive sizing\n * - Tables with hover effects and proper styling\n * - Horizontal rules with custom appearance\n * - All standard markdown formatting (bold, italic, etc.)\n *\n * Code Block Support:\n * - Language detection from code fence info\n * - Syntax highlighting through Code component\n * - Dark/light mode theme switching\n * - Line numbers and copy functionality (via Code component)\n * - Support for popular languages (JS, TS, Python, etc.)\n *\n * Link Handling:\n * - Automatic external link detection (starts with 'http')\n * - Security attributes for external links (rel=\"noopener noreferrer\")\n * - Locale-aware internal link routing\n * - Custom Link component integration\n * - Underlined styling for better visibility\n *\n * Image Processing:\n * - Automatic lazy loading for performance\n * - GitHub raw URL transformation for repository images\n * - Responsive sizing with max-width constraints\n * - Rounded corners for visual appeal\n *\n * Accessibility:\n * - Semantic HTML structure with proper heading hierarchy\n * - ARIA attributes through component integration\n * - Screen reader friendly link descriptions\n * - Keyboard navigation support\n * - High contrast styling options\n *\n * Performance:\n * - Lazy loading for images\n * - Efficient re-rendering with React memo patterns\n * - Code syntax highlighting with minimal bundle impact\n * - Optimized markdown parsing with markdown-to-jsx\n *\n * @param props - Component props\n * @param props.children - Raw markdown content to render\n * @param props.isDarkMode - Enable dark mode styling for code blocks\n * @param props.locale - Current locale for link internationalization\n * @param props.options - Additional markdown-to-jsx options\n * @param props.options.overrides - Custom component overrides for markdown elements\n *\n * @returns Rendered markdown content with custom styling and functionality\n */\nexport const MarkdownRenderer: FC<MarkdownRendererProps> = ({\n children,\n isDarkMode,\n locale,\n options,\n}) => {\n const { overrides, ...restOptions } = options ?? {};\n\n // Strip frontmatter from the markdown content before rendering\n const cleanMarkdown = stripFrontmatter(children);\n\n return (\n <CodeProvider>\n <TabProvider>\n <MarkdownProcessor\n options={{\n overrides: {\n h1: (props: ComponentProps<typeof H1>) => (\n <H1 isClickable={true} {...props} />\n ),\n h2: (props: ComponentProps<typeof H2>) => (\n <H2 isClickable={true} className=\"mt-16\" {...props} />\n ),\n h3: (props: ComponentProps<typeof H3>) => (\n <H3 isClickable={true} className=\"mt-5\" {...props} />\n ),\n h4: (props: ComponentProps<typeof H4>) => (\n <H4 isClickable={true} className=\"mt-3\" {...props} />\n ),\n h5: (props: ComponentProps<typeof H5>) => (\n <H5 isClickable={true} className=\"mt-3\" {...props} />\n ),\n h6: (props: ComponentProps<typeof H6>) => (\n <H6 isClickable={true} className=\"mt-3\" {...props} />\n ),\n\n code: (\n props: Omit<ComponentPropsWithoutRef<'code'>, 'children'> &\n Partial<CodeCompAttributes> & { children: string }\n ) =>\n !props.className ? (\n <strong className=\"rounded bg-card/60 box-decoration-clone px-1 py-0.5\">\n {props.children}\n </strong>\n ) : (\n <Code\n {...props}\n isDarkMode={isDarkMode}\n language={\n (props.className?.replace('lang-', '') ||\n 'plaintext') as BundledLanguage\n }\n fileName={props.fileName}\n showHeader={Boolean(\n props.fileName ||\n props.packageManager ||\n props.codeFormat ||\n props.contentDeclarationFormat\n )}\n />\n ),\n\n blockquote: ({\n className,\n ...props\n }: ComponentPropsWithoutRef<'blockquote'>) => (\n <blockquote\n className={cn(\n 'mt-5 gap-3 border-card border-l-4 pl-5 text-neutral',\n className\n )}\n {...props}\n />\n ),\n ul: ({ className, ...props }: ComponentPropsWithoutRef<'ul'>) => (\n <ul\n className={cn(\n 'mt-5 flex list-disc flex-col gap-3 pl-5',\n className\n )}\n {...props}\n />\n ),\n ol: ({ className, ...props }: ComponentPropsWithoutRef<'ol'>) => (\n <ol\n className={cn(\n 'mt-5 flex list-decimal flex-col gap-3 pl-5',\n className\n )}\n {...props}\n />\n ),\n img: ({\n className,\n ...props\n }: ComponentPropsWithoutRef<'img'>) => (\n <img\n {...props}\n loading=\"lazy\"\n className={cn(\n 'max-h-[80vh] max-w-full rounded-md',\n className\n )}\n src={`${props.src}?raw=true`}\n />\n ),\n a: (props: ComponentProps<typeof Link>) => (\n <Link\n color=\"neutral\"\n isExternalLink={props.href?.startsWith('http')}\n underlined={true}\n locale={locale}\n {...props}\n />\n ),\n pre: (props: ComponentPropsWithoutRef<'pre'>) => props.children,\n\n table: (props: ComponentProps<typeof Table>) => (\n <Table isRollable={true} {...props} />\n ),\n th: ({ className, ...props }: ComponentPropsWithoutRef<'th'>) => (\n <th\n className={cn(\n 'border-neutral border-b bg-neutral/10 p-4',\n className\n )}\n {...props}\n />\n ),\n tr: ({ className, ...props }: ComponentPropsWithoutRef<'tr'>) => (\n <tr\n className={cn('hover:/10 hover:bg-neutral/10', className)}\n {...props}\n />\n ),\n td: ({ className, ...props }: ComponentPropsWithoutRef<'td'>) => (\n <td\n className={cn(\n 'border-neutral-500/50 border-b p-4',\n className\n )}\n {...props}\n />\n ),\n hr: ({ className, ...props }: ComponentPropsWithoutRef<'hr'>) => (\n <hr\n className={cn('mx-6 mt-16 text-neutral', className)}\n {...props}\n />\n ),\n // Support both <Tab> and <Tabs> in markdown\n Tabs: (props: ComponentProps<typeof Tab>) => (\n <Tab\n {...props}\n headerClassName=\"sticky top-36 z-10 bg-background/70 backdrop-blur\"\n />\n ),\n Tab: (props: ComponentProps<typeof Tab>) => (\n <Tab\n {...props}\n headerClassName=\"sticky top-36 z-10 bg-background/70 backdrop-blur\"\n />\n ),\n TabItem: (props: ComponentProps<typeof Tab.Item>) => (\n <Tab.Item {...props} />\n ),\n Columns: ({\n className,\n ...props\n }: ComponentPropsWithoutRef<'div'>) => (\n <div\n className={cn('flex gap-4 max-md:flex-col', className)}\n {...props}\n />\n ),\n Column: ({\n className,\n ...props\n }: ComponentPropsWithoutRef<'div'>) => (\n <div className={cn('flex-1', className)} {...props} />\n ),\n ...overrides,\n },\n ...restOptions,\n }}\n >\n {cleanMarkdown ?? ''}\n </MarkdownProcessor>\n </TabProvider>\n </CodeProvider>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;AA6BA,MAAM,oBAAoB,aAA6B;CACrD,MAAM,QAAQ,SAAS,MAAM,QAAQ;CAGrC,MAAM,oBAAoB,MAAM,MAAM,SAAS,KAAK,MAAM,KAAK,GAAG;AAElE,KAAI,CAAC,qBAAqB,kBAAkB,MAAM,KAAK,MAErD,QAAO;CAGT,IAAI,kBAAkB;CACtB,IAAI,qBAAqB;AAEzB,MAAK,IAAI,IAAI,GAAG,IAAI,M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,UAAU,UAAU;KAAE,GAAI;MAAS;IAExD,GAAG;IACJ;GACD,GAAG;GACJ;YAEA,iBAAiB;GACA,GACR,GACD"}
@@ -1,3 +1,4 @@
1
+ import { MarkdownProcessor, RuleType, compiler, sanitizer as defaultSanitizer, slugify as defaultSlugify } from "./processor-adapter.mjs";
1
2
  import { MarkdownRenderer } from "./MarkDownRender.mjs";
2
3
 
3
- export { MarkdownRenderer };
4
+ export { MarkdownProcessor, MarkdownRenderer, RuleType, compiler, defaultSanitizer as sanitizer, defaultSlugify as slugify };
@@ -0,0 +1,57 @@
1
+ import { Fragment, cloneElement, createElement } from "react";
2
+ import { RuleType, compile, sanitizer as defaultSanitizer, slugify as defaultSlugify } from "@intlayer/core";
3
+
4
+ //#region src/components/MarkDownRender/processor-adapter.tsx
5
+ /**
6
+ * Backward-compatible adapter for the markdown processor.
7
+ *
8
+ * This file re-exports the framework-agnostic markdown processor from @intlayer/core
9
+ * with React-specific bindings for backward compatibility with existing code.
10
+ *
11
+ * This is part of the Solution F (Hybrid AST + Callback Pattern) implementation
12
+ * for GitHub Issue #289: Adapt markdown parser in custom packages
13
+ */
14
+ /**
15
+ * Create the React runtime with optional custom createElement.
16
+ */
17
+ const createReactRuntime = (customCreateElement) => ({
18
+ createElement: customCreateElement ?? createElement,
19
+ cloneElement,
20
+ Fragment,
21
+ normalizeProps: (_tag, props) => props
22
+ });
23
+ /**
24
+ * Compile markdown to React elements.
25
+ * Maintains backward compatibility with the original API.
26
+ */
27
+ const compiler = (markdown = "", options = {}) => {
28
+ const { createElement: customCreateElement, disableAutoLink, disableParsingRawHTML, enforceAtxHeadings, forceBlock, forceInline, forceWrapper, namedCodesToUnicode, overrides, renderRule, sanitizer, slugify, wrapper } = options;
29
+ return compile(markdown, {
30
+ runtime: createReactRuntime(customCreateElement),
31
+ overrides,
32
+ namedCodesToUnicode,
33
+ sanitizer,
34
+ slugify
35
+ }, {
36
+ disableAutoLink,
37
+ disableParsingRawHTML,
38
+ enforceAtxHeadings,
39
+ forceBlock,
40
+ forceInline,
41
+ forceWrapper,
42
+ renderRule,
43
+ wrapper
44
+ });
45
+ };
46
+ /**
47
+ * React component that renders markdown to JSX.
48
+ * Backward compatible with the original MarkdownProcessor component.
49
+ */
50
+ const MarkdownProcessor = ({ children = "", options, ...props }) => {
51
+ if (process.env.NODE_ENV !== "production" && typeof children !== "string") console.error("intlayer: <Markdown> component only accepts a single string as a child, received:", children);
52
+ return cloneElement(compiler(children, options), props);
53
+ };
54
+
55
+ //#endregion
56
+ export { MarkdownProcessor, RuleType, compiler, defaultSanitizer as sanitizer, defaultSlugify as slugify };
57
+ //# sourceMappingURL=processor-adapter.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"processor-adapter.mjs","names":["coreCompile"],"sources":["../../../../src/components/MarkDownRender/processor-adapter.tsx"],"sourcesContent":["/**\n * Backward-compatible adapter for the markdown processor.\n *\n * This file re-exports the framework-agnostic markdown processor from @intlayer/core\n * with React-specific bindings for backward compatibility with existing code.\n *\n * This is part of the Solution F (Hybrid AST + Callback Pattern) implementation\n * for GitHub Issue #289: Adapt markdown parser in custom packages\n */\n\nimport {\n type Overrides as CoreOverrides,\n // Core compile function\n compile as coreCompile,\n sanitizer as defaultSanitizer,\n // Utilities\n slugify as defaultSlugify,\n // Types\n type MarkdownContext,\n type MarkdownOptions,\n type MarkdownRuntime,\n type ParserResult,\n type ParseState,\n type RenderRuleHook,\n type RuleOutput,\n // Constants\n RuleType,\n} from '@intlayer/core';\nimport {\n cloneElement,\n createElement,\n type FC,\n Fragment,\n type HTMLAttributes,\n type JSX,\n type ReactNode,\n} from 'react';\n\n// Re-export RuleType for backward compatibility\nexport { RuleType };\n\n// Re-export utilities for backward compatibility\nexport { defaultSlugify as slugify, defaultSanitizer as sanitizer };\n\n// ============================================================================\n// TYPES (backward compatible)\n// ============================================================================\n\ntype HTMLTags = keyof JSX.IntrinsicElements;\n\ntype State = ParseState;\n\n/**\n * Backward-compatible MarkdownProcessorOptions type.\n * Maps to the core library's options while maintaining the existing API.\n */\nexport type MarkdownProcessorOptions = 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 overrides: CoreOverrides;\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// ============================================================================\n// REACT RUNTIME\n// ============================================================================\n\n/**\n * Create the React runtime with optional custom createElement.\n */\nconst createReactRuntime = (\n customCreateElement?: MarkdownProcessorOptions['createElement']\n): MarkdownRuntime => ({\n createElement: customCreateElement ?? createElement,\n cloneElement,\n Fragment,\n // React uses className instead of class, htmlFor instead of for\n // The core library already handles this via ATTRIBUTE_TO_NODE_PROP_MAP\n normalizeProps: (_tag, props) => props,\n});\n\n// ============================================================================\n// COMPILER WRAPPER\n// ============================================================================\n\n/**\n * Compile markdown to React elements.\n * Maintains backward compatibility with the original API.\n */\nexport const compiler = (\n markdown: string = '',\n options: MarkdownProcessorOptions = {}\n): JSX.Element => {\n const {\n createElement: customCreateElement,\n disableAutoLink,\n disableParsingRawHTML,\n enforceAtxHeadings,\n forceBlock,\n forceInline,\n forceWrapper,\n namedCodesToUnicode,\n overrides,\n renderRule,\n sanitizer,\n slugify,\n wrapper,\n } = options;\n\n // Create React runtime\n const runtime = createReactRuntime(customCreateElement);\n\n // Build context\n const ctx: MarkdownContext = {\n runtime,\n overrides,\n namedCodesToUnicode,\n sanitizer,\n slugify,\n };\n\n // Build compiler options\n const compilerOptions: MarkdownOptions = {\n disableAutoLink,\n disableParsingRawHTML,\n enforceAtxHeadings,\n forceBlock,\n forceInline,\n forceWrapper,\n renderRule,\n wrapper,\n };\n\n // Compile and return\n return coreCompile(markdown, ctx, compilerOptions) as JSX.Element;\n};\n\n// ============================================================================\n// MARKDOWN PROCESSOR COMPONENT\n// ============================================================================\n\n/**\n * React component that renders markdown to JSX.\n * Backward compatible with the original MarkdownProcessor component.\n */\nexport const MarkdownProcessor: FC<\n Omit<HTMLAttributes<Element>, 'children'> & {\n children: string;\n options?: MarkdownProcessorOptions;\n }\n> = ({ children = '', options, ...props }) => {\n if (process.env.NODE_ENV !== 'production' && typeof children !== 'string') {\n console.error(\n 'intlayer: <Markdown> component only accepts a single string as a child, received:',\n children\n );\n }\n\n return cloneElement(\n compiler(children, options),\n props as JSX.IntrinsicAttributes\n );\n};\n\n// ============================================================================\n// TYPE EXPORTS (backward compatibility)\n// ============================================================================\n\nexport type {\n State,\n ParseState,\n ParserResult,\n RuleOutput,\n CoreOverrides as Overrides,\n};\n"],"mappings":";;;;;;;;;;;;;;;;AA0IA,MAAM,sBACJ,yBACqB;CACrB,eAAe,uBAAuB;CACtC;CACA;CAGA,iBAAiB,MAAM,UAAU;CAClC;;;;;AAUD,MAAa,YACX,WAAmB,IACnB,UAAoC,EAAE,KACtB;CAChB,MAAM,EACJ,eAAe,qBACf,iBACA,uBACA,oBACA,YACA,aACA,cACA,qBACA,WACA,YACA,WACA,SACA,YACE;AA2BJ,QAAOA,QAAY,UArBU;EAC3B,SAJc,mBAAmB,oBAAoB;EAKrD;EACA;EACA;EACA;EACD,EAGwC;EACvC;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACD,CAGiD;;;;;;AAWpD,MAAa,qBAKR,EAAE,WAAW,IAAI,SAAS,GAAG,YAAY;AAC5C,KAAI,QAAQ,IAAI,aAAa,gBAAgB,OAAO,aAAa,SAC/D,SAAQ,MACN,qFACA,SACD;AAGH,QAAO,aACL,SAAS,UAAU,QAAQ,EAC3B,MACD"}
@@ -59,7 +59,7 @@ const Priority = {
59
59
  MIN: 4
60
60
  };
61
61
  /** TODO: Drop for React 16? */
62
- const ATTRIBUTE_TO_JSX_PROP_MAP = [
62
+ const ATTRIBUTE_TO_NODE_PROP_MAP = [
63
63
  "allowFullScreen",
64
64
  "allowTransparency",
65
65
  "autoComplete",
@@ -575,7 +575,7 @@ const trimLeadingWhitespaceOutsideFences = (text, whitespace) => {
575
575
  if (duration > durationDelayTrigger) console.log(`trimLeadingWhitespaceOutsideFences: ${duration.toFixed(3)}ms, text length: ${text.length}, lines count: ${lines.length}`);
576
576
  return result;
577
577
  };
578
- const attributeValueToJSXPropValue = (tag, key, value, sanitizeUrlFn) => {
578
+ const attributeValueToNodePropValue = (tag, key, value, sanitizeUrlFn) => {
579
579
  if (key === "style") return parseStyleAttribute(value).reduce((styles, [key$1, value$1]) => {
580
580
  const camelCasedKey = key$1.replace(/(-[a-z])/g, (substr) => substr[1].toUpperCase());
581
581
  styles[camelCasedKey] = sanitizeUrlFn(value$1, tag, key$1);
@@ -919,12 +919,12 @@ const compiler = (markdown = "", options = {}) => {
919
919
  if (delimiterIdx !== -1) {
920
920
  const key = normalizeAttributeKey(raw.slice(0, delimiterIdx)).trim();
921
921
  const value = unquote(raw.slice(delimiterIdx + 1).trim());
922
- const mappedKey = ATTRIBUTE_TO_JSX_PROP_MAP[key] ?? key;
922
+ const mappedKey = ATTRIBUTE_TO_NODE_PROP_MAP[key] ?? key;
923
923
  if (mappedKey === "ref") return map;
924
- const normalizedValue = attributeValueToJSXPropValue(tag, key, value, sanitize);
924
+ const normalizedValue = attributeValueToNodePropValue(tag, key, value, sanitize);
925
925
  map[mappedKey] = normalizedValue;
926
926
  if (typeof normalizedValue === "string" && (HTML_BLOCK_ELEMENT_R.test(normalizedValue) || HTML_SELF_CLOSING_ELEMENT_R.test(normalizedValue))) map[mappedKey] = compile(normalizedValue.trim());
927
- } else if (raw !== "style") map[ATTRIBUTE_TO_JSX_PROP_MAP[raw] ?? raw] = true;
927
+ } else if (raw !== "style") map[ATTRIBUTE_TO_NODE_PROP_MAP[raw] ?? raw] = true;
928
928
  return map;
929
929
  }, {});
930
930
  const duration = performance.now() - start;