Skip to content

Commit e575aa7

Browse files
committed
feat: add demo
Signed-off-by: Innei <[email protected]>
1 parent e672da5 commit e575aa7

File tree

6 files changed

+52
-30
lines changed

6 files changed

+52
-30
lines changed

src/components/ui/markdown/Markdown.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import { Gallery } from '../gallery'
1616
import { FixedZoomedImage } from '../image'
1717
import { LinkCard } from '../link-card'
1818
import styles from './markdown.module.css'
19-
import { CommentAtRule } from './parsers/comment-at'
2019
import { ContainerRule } from './parsers/container'
2120
import { InsertRule } from './parsers/ins'
2221
import { KateXRule } from './parsers/katex'
@@ -210,7 +209,7 @@ export const Markdown: FC<MdProps & MarkdownToJSX.Options & PropsWithChildren> =
210209
additionalParserRules: {
211210
spoilder: SpoilderRule,
212211
mention: MentionRule,
213-
commentAt: CommentAtRule,
212+
214213
mark: MarkRule,
215214
ins: InsertRule,
216215
kateX: KateXRule,

src/components/ui/markdown/customize.md

+32
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,35 @@
1+
## Token
2+
3+
This is a ||Spoiler||
4+
5+
A `code`.
6+
7+
==mark== it.
8+
9+
++Something Insert++
10+
11+
## Latex
12+
13+
$ c = \pm\sqrt{a^2 + b^2} $
14+
15+
## Container
16+
17+
::: warning
18+
_here be dragons_
19+
:::
20+
21+
::: banner {error}
22+
_here be dragons_
23+
:::
24+
25+
26+
::: gallery
27+
https://loremflickr.com/640/480/city?1
28+
https://loremflickr.com/640/480/city?2
29+
https://loremflickr.com/640/480/city?3
30+
![](https://loremflickr.com/640/480/city?4 "Image")
31+
:::
32+
133
## Rich Link
234

335
```

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292
@apply cursor-not-allowed;
9393
}
9494

95-
code {
95+
:not(pre) code {
9696
@apply bg-zinc-200 font-mono dark:bg-neutral-800;
9797
}
9898

src/components/ui/markdown/parsers/comment-at.tsx

-23
This file was deleted.

src/components/ui/markdown/parsers/mark.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import type { MarkdownToJSX } from 'markdown-to-jsx'
1+
import React from 'react'
22
import {
3-
Priority,
43
parseCaptureInline,
4+
Priority,
55
simpleInlineRegex,
66
} from 'markdown-to-jsx'
7-
import React from 'react'
7+
import type { MarkdownToJSX } from 'markdown-to-jsx'
88

99
// ==Mark==
1010
export const MarkRule: MarkdownToJSX.Rule = {
@@ -15,7 +15,7 @@ export const MarkRule: MarkdownToJSX.Rule = {
1515
return (
1616
<mark
1717
key={state?.key}
18-
className="!bg-always-yellow-200 !rounded-lg !bg-opacity-80 !bg-none !text-black"
18+
className="rounded-md bg-always-yellow-400 bg-opacity-80 px-1 text-black"
1919
>
2020
{output(node.content, state!)}
2121
</mark>

src/components/ui/markdown/utils/image.ts

+14
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ export const pickImagesFromMarkdown = (md: string) => {
1212
const res: MImageType[] = []
1313

1414
for (const line of lines) {
15+
if (!line.startsWith('!') && isRawImageUrl(line)) {
16+
res.push({ url: line, name: line })
17+
continue
18+
}
19+
1520
const match = regexp.exec(line)
1621
if (!match) {
1722
continue
@@ -23,3 +28,12 @@ export const pickImagesFromMarkdown = (md: string) => {
2328

2429
return res
2530
}
31+
32+
const isRawImageUrl = (url: string) => {
33+
try {
34+
new URL(url)
35+
} catch (e) {
36+
return false
37+
}
38+
return true
39+
}

0 commit comments

Comments
 (0)