1
1
import type { ReactNode } from 'react'
2
2
import type { Components as MarkdownComponents } from 'react-markdown'
3
-
4
3
import { CustomImage , SakuraIcon } from '@/components/ui'
5
4
import { generateHierarchicalSlug , slugPrefix } from '@/services/utils'
6
-
7
- import Link from 'next/link'
8
5
import { isValidElement } from 'react'
9
-
10
6
import { KEY_ICONS } from './keyboardIcons'
11
7
import CodeBlock from './renderCodeBlock'
12
8
import renderFriendLinks from './renderFriendLinks'
@@ -143,6 +139,26 @@ const createMarkdownComponents = (translation: Translation, autoSlug: boolean =
143
139
{ children }
144
140
</ mark >
145
141
) ,
142
+ // Checkbox related [x] or [ ]
143
+ input : ( { children, ...props } ) => (
144
+ < label className = "relative inline-flex items-center text-center" >
145
+ < input
146
+ type = "checkbox"
147
+ className = "peer form-tick appearance-none h-4 w-4 border border-gray-300 rounded-md checked:bg-primary-400 checked:border-transparent focus:outline-none focus:ring-2 focus:ring-primary-400 focus:ring-opacity-50"
148
+ { ...props }
149
+ />
150
+ < span className = "absolute inset-0 flex items-center justify-center pointer-events-none opacity-0 peer-checked:opacity-100" >
151
+ < svg
152
+ className = "h-4 w-4 text-white"
153
+ fill = "none"
154
+ viewBox = "0 0 24 24"
155
+ stroke = "currentColor"
156
+ >
157
+ < path strokeLinecap = "round" strokeLinejoin = "round" strokeWidth = { 2 } d = "M5 13l4 4L19 7" />
158
+ </ svg >
159
+ </ span >
160
+ </ label >
161
+ ) ,
146
162
147
163
// List related
148
164
ul : ( { children } ) => (
@@ -169,7 +185,7 @@ const createMarkdownComponents = (translation: Translation, autoSlug: boolean =
169
185
a : ( { href = '#' , children, ...props } : { href ?: string , children ?: ReactNode } ) => {
170
186
const isInternalLink = typeof href === 'string' && ( href . startsWith ( '/' ) || href . startsWith ( '#' ) )
171
187
return (
172
- < Link
188
+ < a
173
189
href = { href }
174
190
target = { isInternalLink ? '_self' : '_blank' }
175
191
rel = "noopener noreferrer"
@@ -178,12 +194,11 @@ const createMarkdownComponents = (translation: Translation, autoSlug: boolean =
178
194
? undefined
179
195
: `${ translation . newTab } ${ children ?. toString ( ) ?? 'link' } `
180
196
}
181
- prefetch = { false }
182
197
className = "text-hover-primary underline-interactive mx-1 break-words font-semibold text-secondary-500"
183
198
{ ...( props as Record < string , unknown > ) }
184
199
>
185
200
{ children }
186
- </ Link >
201
+ </ a >
187
202
)
188
203
} ,
189
204
@@ -195,7 +210,7 @@ const createMarkdownComponents = (translation: Translation, autoSlug: boolean =
195
210
width = { 500 }
196
211
height = { 700 }
197
212
priority = { false }
198
- className = "relative mx-auto my-6 h-auto max-h-[500px] min-h-[200px] w-auto min-w-[200px] max-w-full rounded-xs object-contain shadow-md lg:max-h-[700px] lg:min-h-[300px] lg:min- w-[300px] xl:max-h-[800px] xl:min-h-[400px ] xl:min-w-[400px]"
213
+ className = "relative mx-auto my-6 h-auto max-h-[500px] w-auto min-w-[200px] max-w-full rounded-xs object-contain shadow-md lg:max-h-[700px] lg:min-w-[300px] xl:max-h-[800px] xl:min-w-[400px]"
199
214
{ ...( props as Record < string , unknown > ) }
200
215
/>
201
216
) ,
0 commit comments