diff --git a/examples/normal/.dumi/theme/builtins/Identity.tsx b/examples/normal/.dumi/theme/builtins/Identity.tsx new file mode 100644 index 0000000000..4cc1a705ef --- /dev/null +++ b/examples/normal/.dumi/theme/builtins/Identity.tsx @@ -0,0 +1,19 @@ +import * as React from 'react'; + +export interface IdentityProps { + [key: string]: React.ReactNode; +} + +function Identity(props: React.PropsWithChildren) { + const { children, ...restProps } = props; + return ( + + ); +} + +export default Identity; diff --git a/examples/normal/docs/hello/index.md b/examples/normal/docs/hello/index.md index fc5b6fd790..259c8bf6d3 100644 --- a/examples/normal/docs/hello/index.md +++ b/examples/normal/docs/hello/index.md @@ -6,3 +6,53 @@ group: 测试分组 ## This is hello/index.md 约定式导航、分组测试 + +## Issue 1836 + +> debug https://github.com/umijs/dumi/issues/1836 + +### case 01 + +Hello Dumi! + +```tsx | pure +Hello Dumi! +``` + +### case 02 + + + +```tsx | pure + +``` + +### case 03 + + + +```tsx | pure + +``` + +### case 04 + + + Hello Dumi! + + + + Awesome Children + + + +```tsx | pure + + Hello Dumi! + + + + Awesome Children + + +``` diff --git a/src/loaders/markdown/transformer/__snapshots__/rehypeRaw.test.ts.snap b/src/loaders/markdown/transformer/__snapshots__/rehypeRaw.test.ts.snap new file mode 100644 index 0000000000..fbd4f12c78 --- /dev/null +++ b/src/loaders/markdown/transformer/__snapshots__/rehypeRaw.test.ts.snap @@ -0,0 +1,17 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`rehypeRaw > addCustomPropsToMatchingJSX > should match nested jsx components 1`] = ` +" +\\" /> +\\"> +\\">bar +\\"> +\\" /> +\\"> +\\">bar +\\"> +\\" /> +\\"> +\\">bar +\\">bar" +`; diff --git a/src/loaders/markdown/transformer/rehypeRaw.test.ts b/src/loaders/markdown/transformer/rehypeRaw.test.ts new file mode 100644 index 0000000000..a67a6bf6f0 --- /dev/null +++ b/src/loaders/markdown/transformer/rehypeRaw.test.ts @@ -0,0 +1,69 @@ +import { __private__ } from './rehypeRaw'; + +const { addCustomPropsToMatchingJSX } = __private__; + +describe('rehypeRaw', () => { + describe('addCustomPropsToMatchingJSX', () => { + it('should return the original string when there are no jsx fragments to match', () => { + const input = 'foo bar'; + expect(addCustomPropsToMatchingJSX(input)).toBe(input); + }); + + it('should match jsx fragments without children', () => { + const input = ''; + expect(addCustomPropsToMatchingJSX(input)).toMatchInlineSnapshot( + '""', + ); + }); + + it('should match jsx fragments that contain children', () => { + const input = 'bar'; + expect(addCustomPropsToMatchingJSX(input)).toMatchInlineSnapshot( + '"bar"', + ); + }); + + it('should match multiple jsx fragments', () => { + const input = ` +bar +foo +