Skip to content

Commit 9e0db7c

Browse files
committed
Add class parmeter to mark annotation
1 parent a18de24 commit 9e0db7c

File tree

3 files changed

+33
-19
lines changed

3 files changed

+33
-19
lines changed

packages/mdx/dev/content/comment-annotations.mdx

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Same with other annotations like `mark` and `box`.
2525
```js
2626
// mark(1:2)
2727
function foo() {
28-
// box[6:9]
28+
// mark[6:9] mark-box
2929
console.log("hover me")
3030
return 8
3131
}
@@ -35,7 +35,7 @@ You can pass a string parameter to comment annotations. For `mark` and `box`, it
3535

3636
```js index.js
3737
function lorem(ipsum, dolor = 1) {
38-
// mark(1:3) linear-gradient(90deg, #020024 0%, #090979 35%, #00d4ff 100%)
38+
// mark(1:3) mark-red-background
3939
const sit = ipsum == null && 0
4040
dolor = sit - amet(dolor)
4141
return sit ? consectetur(ipsum) : []
@@ -47,7 +47,7 @@ function lorem(ipsum, dolor = 1) {
4747
// å
4848
function adipiscing(...elit) {
4949
console.log(elit)
50-
// box[19:36] aqua
50+
// mark[19:36]
5151
return elit.map(ipsum => ipsum.sit)
5252
}
5353
```
@@ -85,7 +85,7 @@ def lorem(ipsum, dolor = 1):
8585
```bash
8686
function lorem(ipsum, dolor = 1) {
8787
# focus(1:3)
88-
# box[3:7]
88+
# mark[3:7]
8989
local sit=0
9090
# label something something
9191
dolor=$((sit - amet(dolor)))

packages/mdx/pages/styles.css

+16
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,19 @@ div#__next > div {
3636
.annotation-class span {
3737
text-decoration: line-through;
3838
}
39+
40+
.mark-red-background {
41+
background: #550000 !important;
42+
}
43+
44+
.mark-red-background .ch-code-multiline-mark-border {
45+
background: #bb0000 !important;
46+
}
47+
48+
.mark-box {
49+
background: #000 !important;
50+
}
51+
52+
.mark-box * {
53+
color: #0f0 !important;
54+
}

packages/mdx/src/mdx-client/annotations.tsx

+13-15
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,11 @@ function MultilineMark({
3636
style?: React.CSSProperties
3737
theme?: any
3838
}) {
39-
const bg =
40-
data ||
41-
getColor(theme, ColorName.RangeHighlightBackground)
39+
const className = `ch-code-multiline-mark ` + (data ?? "")
40+
const bg = getColor(
41+
theme,
42+
ColorName.RangeHighlightBackground
43+
)
4244
const border = getColor(
4345
theme,
4446
ColorName.EditorInfoForeground
@@ -47,7 +49,7 @@ function MultilineMark({
4749
return (
4850
<div
4951
style={{ ...style, background: bg }}
50-
className="ch-code-multiline-mark"
52+
className={className}
5153
>
5254
<span
5355
className="ch-code-multiline-mark-border"
@@ -68,19 +70,15 @@ function InlineMark({
6870
theme: any
6971
}) {
7072
const bg =
71-
data && typeof data === "string"
72-
? data
73-
: tryGuessColor(children) ||
74-
transparent(
75-
getColor(theme, ColorName.CodeForeground),
76-
0.2
77-
)
73+
tryGuessColor(children) ||
74+
transparent(
75+
getColor(theme, ColorName.CodeForeground),
76+
0.2
77+
)
7878

79+
const className = "ch-code-inline-mark " + (data ?? "")
7980
return (
80-
<span
81-
className="ch-code-inline-mark"
82-
style={{ background: bg }}
83-
>
81+
<span className={className} style={{ background: bg }}>
8482
{children}
8583
</span>
8684
)

0 commit comments

Comments
 (0)