Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: supplement demo.cols #2063

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/guide/page-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ demo:
<!-- 其他 Markdown 内容 -->
```

配置 `demo.cols` 后,以下多个 demo 完将会被渲染为双栏布局
配置 `demo.cols` 后,以下用**单个换行符**分隔的 code 标签 demo 会被渲染为双栏布局

```md
<code src="./demos/cols.tsx">分栏 1</code>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default () => 'demo';
61 changes: 61 additions & 0 deletions src/loaders/markdown/transformer/fixtures/demo/cols/expect.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import type { IMdTransformerResult } from '../../..';

export default (ret: IMdTransformerResult) => {
expect(ret.content).toMatchInlineSnapshot(`
"<><DumiDemoGrid items={[{
\\"demo\\": {
\\"id\\": \\"demo-foo\\"
},
\\"previewerProps\\": {
\\"id\\": \\"foo\\",
\\"title\\": \\"分栏 1\\",
\\"filename\\": \\"demo.jsx\\"
}
}, {
\\"demo\\": {
\\"id\\": \\"demo-bar\\"
},
\\"previewerProps\\": {
\\"id\\": \\"bar\\",
\\"title\\": \\"分栏 2\\",
\\"filename\\": \\"demo.jsx\\"
}
}, {
\\"demo\\": {
\\"id\\": \\"demo-baz\\"
},
\\"previewerProps\\": {
\\"id\\": \\"baz\\",
\\"title\\": \\"分栏 3\\",
\\"filename\\": \\"demo.jsx\\"
}
}, {
\\"demo\\": {
\\"id\\": \\"demo-other\\"
},
\\"previewerProps\\": {
\\"id\\": \\"other\\",
\\"title\\": \\"分栏 4\\",
\\"filename\\": \\"demo.jsx\\"
}
}]} /><DumiDemo {...{
\\"demo\\": {
\\"id\\": \\"demo-bad-1\\"
},
\\"previewerProps\\": {
\\"id\\": \\"bad-1\\",
\\"title\\": \\"bad 分栏 1\\",
\\"filename\\": \\"demo.jsx\\"
}
}} /><DumiDemo {...{
\\"demo\\": {
\\"id\\": \\"demo-bad-2\\"
},
\\"previewerProps\\": {
\\"id\\": \\"bad-2\\",
\\"title\\": \\"bad 分栏 2\\",
\\"filename\\": \\"demo.jsx\\"
}
}} /></>"
`);
};
17 changes: 17 additions & 0 deletions src/loaders/markdown/transformer/fixtures/demo/cols/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
demo:
cols: 2
---

<!-- good ✅ -->

<code id="foo" src="./demo.jsx">分栏 1</code>
<code id="bar" src="./demo.jsx">分栏 2</code>
<code id="baz" src="./demo.jsx">分栏 3</code>
<code id="other" src="./demo.jsx">分栏 4</code>

<!-- bad ❌ -->

<code id="bad-1" src="./demo.jsx">bad 分栏 1</code>

<code id="bad-2" src="./demo.jsx">bad 分栏 2</code>
7 changes: 2 additions & 5 deletions src/loaders/markdown/transformer/rehypeDemo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,11 +319,8 @@ export default function rehypeDemo(
) {
const startLine = node.position?.start.line;
const suffix = startLine ? `:${startLine}` : '';

logger.warn(
`Duplicate demo id found due to filename conflicts, please consider adding a unique id to code tag to resolve this.
at ${opts.fileAbsPath}${suffix}`,
);
// prettier-ignore
logger.warn(`Duplicate demo id found due to filename conflicts, please consider adding a unique id to code tag to resolve this. at ${opts.fileAbsPath}${suffix}`);
Comment on lines -322 to +323
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
Expand Down
Loading