Skip to content

Commit 65d4618

Browse files
committed
feat: comment markdown improve
Signed-off-by: Innei <[email protected]>
1 parent acc815e commit 65d4618

File tree

5 files changed

+39
-26
lines changed

5 files changed

+39
-26
lines changed

src/components/modules/comment/Comment.tsx

+2-22
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ import { createPortal } from 'react-dom'
1010
import clsx from 'clsx'
1111
import { m } from 'framer-motion'
1212
import { atom, useAtomValue } from 'jotai'
13-
import Markdown from 'markdown-to-jsx'
1413
import type { CommentModel } from '@mx-space/api-client'
15-
import type { MarkdownToJSX } from 'markdown-to-jsx'
1614
import type { PropsWithChildren } from 'react'
1715

1816
import { Avatar } from '~/components/ui/avatar'
@@ -25,6 +23,7 @@ import { softSpringPreset } from '~/constants/spring'
2523
import { jotaiStore } from '~/lib/store'
2624

2725
import styles from './Comment.module.css'
26+
import { CommentMarkdown } from './CommentMarkdown'
2827
import { CommentPinButton, OcticonGistSecret } from './CommentPinButton'
2928
import { CommentReplyButton } from './CommentReplyButton'
3029

@@ -150,15 +149,7 @@ export const Comment: Component<{
150149
'max-w-[calc(100%-3rem)]',
151150
)}
152151
>
153-
<Markdown
154-
options={{
155-
disabledTypes,
156-
disableParsingRawHTML: true,
157-
forceBlock: true,
158-
}}
159-
>
160-
{text}
161-
</Markdown>
152+
<CommentMarkdown>{text}</CommentMarkdown>
162153
<CommentReplyButton commentId={comment.id} />
163154
</div>
164155
</div>
@@ -200,14 +191,3 @@ export const CommentBoxHolderPortal = (props: PropsWithChildren) => {
200191

201192
return createPortal(props.children, portalElement)
202193
}
203-
204-
const disabledTypes = [
205-
'footnote',
206-
'footnoteReference',
207-
208-
'image',
209-
210-
'htmlComment',
211-
'htmlSelfClosing',
212-
'htmlBlock',
213-
] as MarkdownToJSX.RuleName[]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import type { MarkdownToJSX } from '~/components/ui/markdown'
2+
import type { FC } from 'react'
3+
4+
import { Markdown } from '~/components/ui/markdown'
5+
6+
const disabledTypes = [
7+
'footnote',
8+
'footnoteReference',
9+
10+
'image',
11+
12+
'htmlComment',
13+
'htmlSelfClosing',
14+
'htmlBlock',
15+
] as MarkdownToJSX.RuleName[]
16+
17+
export const CommentMarkdown: FC<{
18+
children: string
19+
}> = ({ children }) => {
20+
return (
21+
<Markdown
22+
disabledTypes={disabledTypes}
23+
disableParsingRawHTML
24+
forceBlock
25+
value={children}
26+
/>
27+
)
28+
}

src/components/modules/dashboard/comments/CommentContentCell.tsx

+7-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { EllipsisHorizontalTextWithTooltip } from '~/components/ui/typography'
88
import { clsxm } from '~/lib/helper'
99
import { apiClient } from '~/lib/request'
1010

11+
import { CommentMarkdown } from '../../comment/CommentMarkdown'
1112
import { CommentAction } from './CommentAction'
1213
import { CommentDataContext } from './CommentContext'
1314
import { CommentUrlRender } from './UrlRender'
@@ -57,7 +58,9 @@ export const CommentContentCell: Component<{ comment: CommentModel }> = (
5758
<RelativeTime date={created} />{TitleEl}
5859
</div>
5960

60-
<p className="break-words">{text}</p>
61+
<div className="break-words">
62+
<CommentMarkdown>{text}</CommentMarkdown>
63+
</div>
6164

6265
{parentComment && typeof parentComment !== 'string' && (
6366
<div className="relative mt-2 break-words">
@@ -69,7 +72,9 @@ export const CommentContentCell: Component<{ comment: CommentModel }> = (
6972
/>{' '}
7073
<RelativeTime date={parentComment.created} /> 说:
7174
</div>
72-
<p className="mt-2">{parentComment.text}</p>
75+
<div className="mt-2">
76+
<CommentMarkdown>{parentComment.text}</CommentMarkdown>
77+
</div>
7378
</blockquote>
7479
</div>
7580
)}

src/components/modules/dashboard/comments/CommentDesktopTable.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ const CommentCheckBox: FC<{
5959
}
6060
const CommentItem = ({ comment }: { comment: CommentModel }) => {
6161
return (
62-
<div className="grid grid-cols-[40px_300px_auto] gap-8">
62+
<div className="mx-auto grid w-[100rem] max-w-full grid-cols-[40px_300px_auto] gap-8">
6363
<div className="ml-2 mt-[18px]">
6464
<CommentCheckBox id={comment.id} />
6565
</div>

src/components/ui/markdown/markdown.module.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898
}
9999

100100
:not(pre) code {
101-
@apply bg-zinc-200 font-mono dark:bg-neutral-800;
101+
@apply rounded-md bg-zinc-200 px-2 font-mono dark:bg-neutral-800;
102102
}
103103

104104
pre {

0 commit comments

Comments
 (0)