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

fix: unnecessary trailing line break for read-only source code #2033

Merged
merged 3 commits into from
Mar 21, 2024
Merged
Changes from 1 commit
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 src/client/theme-default/builtins/SourceCode/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const SourceCode: FC<SourceCodeProps> = (props) => {
const code = (
<Highlight
{...defaultProps}
code={children}
code={children.trim()}
Copy link
Member

Choose a reason for hiding this comment

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

加在这里应该会影响 live demo 的编辑态,尾部新增空行会没有反应,在 antd 官网调用 SourceCode 的地方 trim 一下?类似这样:

{files[activeKey][1].value.trim()}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

我看antd 也没怎么用<SourceCode />, antd 使用的 <LiveCode /> 实际上是用的是 dumiSourceCodeEditor 这里是antd的代码

我看直接使用markdown 写法,也会出问题。
https://ant.design/docs/react/introduce-cn#%E7%A4%BA%E4%BE%8B 对应antd源码地址 本质上还是调用SourceCode

我的解决思路是:

我在SourceCode 中 判断是否有 textarea 属性如果有表示的是可以编辑的LiveCode 那么不应该trim, 否则应该trim?

下面这里表示的是可以编辑的代码

Copy link
Contributor

Choose a reason for hiding this comment

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

是这里改坏的 ant-design/ant-design#47347 ,看上去这个修复是对的。

Copy link
Member

Choose a reason for hiding this comment

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

我在SourceCode 中 判断是否有 textarea 属性如果有表示的是可以编辑的LiveCode 那么不应该trim, 否则应该trim?

合理的,那就按这个思路👍

language={SIMILAR_DSL[lang] || lang}
theme={undefined}
>
Expand Down
Loading