Skip to content

Commit bcd83b0

Browse files
committed
feat: md 图片拓展
1 parent 232859c commit bcd83b0

File tree

4 files changed

+19
-13
lines changed

4 files changed

+19
-13
lines changed

src/app/(app)/notes/[nid]/test.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
这是详细的内容,可以在点击时展开。
2727
</details>
2828

29-
3029
效仿 Hexo 采用纯前端,文章编写删除编译都在本地运行,对前端工程师更友好。
3130
Nextjs 同时也支持全栈开发。简单的 sql 语句也能够对文章进行增删改查。
3231

src/components/ui/markdown/Markdown.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { memo, Suspense, useMemo, useRef } from 'react';
1010

1111
import { MParagraph } from './renderbers/paragraph';
1212
import { MHeader } from './renderbers/heading';
13+
import { MarkdownImage } from './renderbers/images';
1314

1415
export interface MdProps {
1516
value?: string;
@@ -56,6 +57,7 @@ export const Markdown: FC<MdProps & MarkdownToJSX.Options & PropsWithChildren &
5657
wrapper: null,
5758
overrides: {
5859
p: MParagraph,
60+
img: MarkdownImage,
5961
script: allowsScript ? Script : undefined,
6062
...overrides,
6163
},
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export const MarkdownImage = (props: { src: string; alt?: string }) => {
2+
return (
3+
<span className="flex w-full flex-col items-center border-none mdImg">
4+
<img src={props.src} alt={props.alt} loading="lazy" className="mx-auto w-[50%] rounded-md" />
5+
<span className=" w-full">居中文本</span>
6+
</span>
7+
);
8+
};

src/styles/mdContainer.css

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,21 @@
1111
:global .paragraph:first-child {
1212
margin-bottom: 4rem;
1313
}
14-
.with-indent ul span,
15-
.with-indent .paragraph span {
16-
border-bottom: 1px solid;
17-
/* @apply border-accent/20 dark:border-accent/20; */
18-
@apply border-accent/10; /* Tailwind CSS特性,需要替换为具体的CSS */
19-
}
20-
@media print {
21-
.with-indent ul span,
22-
.with-indent .paragraph span {
23-
@apply border-none; /* Tailwind CSS特性,需要替换为具体的CSS */
24-
}
25-
}
14+
2615
.with-indent blockquote::before {
2716
display: none !important;
2817
}
2918
.with-indent blockquote .paragraph > span {
3019
margin-left: 0 !important;
3120
}
21+
.mdImg span {
22+
display: inline-block !important;
23+
margin-left: 0 !important;
24+
margin-right: 0 auto;
25+
padding: 0;
26+
text-align: center;
27+
}
28+
3229
.with-indent blockquote .paragraph:first-child::first-letter {
3330
float: none !important;
3431
font-size: inherit !important;

0 commit comments

Comments
 (0)