Skip to content

Commit c4a9b41

Browse files
committed
chore: tweak
1 parent 90ab25f commit c4a9b41

File tree

9 files changed

+169
-90
lines changed

9 files changed

+169
-90
lines changed

docs/plugins/markdown/prismjs.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ body > div {
405405
- Type: `boolean | CodeBlockTitleRender`
406406

407407
```ts
408-
type CodeBlockTitleRender = (title: string) => string
408+
type CodeBlockTitleRender = (title: string, code: string) => string
409409
```
410410
411411
- Default: `true`
@@ -419,14 +419,14 @@ body > div {
419419
**Input:**
420420
421421
````md {1}
422-
```ts title="Code Block Title"
422+
```ts title="foo/baz.js"
423423
console.log('hello')
424424
```
425425
````
426426
427427
**Output:**
428428
429-
```ts title="Code Block Title"
429+
```ts title="foo/baz.js"
430430
console.log('hello')
431431
```
432432

docs/plugins/markdown/shiki.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ body > div {
399399
- Type: `boolean | CodeBlockTitleRender`
400400

401401
```ts
402-
type CodeBlockTitleRender = (title: string) => string
402+
type CodeBlockTitleRender = (title: string, code: string) => string
403403
```
404404
405405
- Default: `true`
@@ -413,14 +413,14 @@ body > div {
413413
**Input:**
414414
415415
````md {1}
416-
```ts title="Code Block Title"
416+
```ts title="foo/baz.js"
417417
console.log('hello')
418418
```
419419
````
420420
421421
**Output:**
422422
423-
```ts title="Code Block Title"
423+
```ts title="foo/baz.js"
424424
console.log('hello')
425425
```
426426

docs/zh/plugins/markdown/prismjs.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ body > div {
405405
- 类型:`boolean | CodeBlockTitleRender`
406406

407407
```ts
408-
type CodeBlockTitleRender = (title: string) => string
408+
type CodeBlockTitleRender = (title: string, code: string) => string
409409
```
410410
411411
- 默认值:`true`
@@ -419,14 +419,14 @@ body > div {
419419
**输入:**
420420
421421
````md {1}
422-
```ts title="代码块标题"
422+
```ts title="foo/baz.js"
423423
console.log('hello')
424424
```
425425
````
426426
427427
**输出:**
428428
429-
```ts title="代码块标题"
429+
```ts title="foo/baz.js"
430430
console.log('hello')
431431
```
432432

docs/zh/plugins/markdown/shiki.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ body > div {
401401
- 类型:`boolean | CodeBlockTitleRender`
402402

403403
```ts
404-
type CodeBlockTitleRender = (title: string) => string
404+
type CodeBlockTitleRender = (title: string, code: string) => string
405405
```
406406
407407
- 默认值:`true`
@@ -415,14 +415,14 @@ body > div {
415415
**输入:**
416416
417417
````md {1}
418-
```ts title="代码块标题"
418+
```ts title="foo/baz.js"
419419
console.log('hello')
420420
```
421421
````
422422
423423
**输出:**
424424
425-
```ts title="代码块标题"
425+
```ts title="foo/baz.js"
426426
console.log('hello')
427427
```
428428

plugins/markdown/plugin-prismjs/tests/__snapshots__/prismjs-preWrapper.spec.ts.snap

Lines changed: 70 additions & 20 deletions
Large diffs are not rendered by default.

plugins/markdown/plugin-shiki/tests/__snapshots__/shiki-preWrapper.spec.ts.snap

Lines changed: 70 additions & 20 deletions
Large diffs are not rendered by default.
Lines changed: 8 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
:root {
2-
--code-title-c-text: var(--vp-c-text);
3-
--code-title-c-bg: var(--code-c-highlight-bg);
4-
--code-title-bar-c-bg: var(--code-c-bg);
5-
}
6-
7-
[data-theme='dark'] {
8-
--code-title-c-bg: #181819;
2+
--code-title-c-text: var(--vp-c-text-mute);
3+
--code-title-c-bg: var(--code-c-bg);
4+
--code-title-divider: var(--code-c-highlight-bg, var(--code-c-text));
95
}
106

117
.code-block-title {
@@ -18,11 +14,11 @@
1814
overflow-x: auto;
1915

2016
margin: 0.75rem 0 -0.75rem;
21-
padding: 0;
17+
padding: 0 12px;
18+
border-bottom: solid 1px var(--code-title-divider);
2219
border-radius: 6px 6px 0 0;
2320

2421
background: var(--code-title-c-bg);
25-
list-style: none;
2622

2723
white-space: nowrap;
2824

@@ -38,38 +34,16 @@
3834

3935
display: inline-block;
4036

41-
min-width: 3rem;
4237
margin: 0;
43-
padding: 6px 12px;
44-
border-width: 0;
45-
border-radius: 6px 6px 0 0;
38+
padding: 8px 12px;
4639

47-
background: var(--code-title-bar-c-bg);
4840
color: var(--code-title-c-text);
4941

50-
font-weight: 600;
42+
font-weight: 500;
5143
font-size: 0.875em;
52-
line-height: 1.4;
44+
line-height: 1.7;
5345

5446
transition: background var(--vp-t-color);
55-
56-
&::after {
57-
content: ' ';
58-
59-
position: absolute;
60-
bottom: 0;
61-
left: 100%;
62-
z-index: 1;
63-
64-
width: 6px;
65-
height: 6px;
66-
67-
background: radial-gradient(
68-
12px at right top,
69-
transparent 50%,
70-
var(--code-c-bg) 50%
71-
);
72-
}
7347
}
7448
}
7549
}

tools/highlighter-helper/src/node/codeBlockTitle/options.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export type CodeBlockTitleRender = (title: string) => string
1+
export type CodeBlockTitleRender = (title: string, code: string) => string
22

33
export interface MarkdownItCodeBlockTitleOptions {
44
/**

tools/highlighter-helper/src/node/codeBlockTitle/plugin.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,13 @@ import type {
55
MarkdownItCodeBlockTitleOptions,
66
} from './options.js'
77

8-
const defaultTitleRender: CodeBlockTitleRender = (title: string) =>
9-
`<div class="code-block-title-bar"><span class="title">${title}</span></div>`
8+
const defaultTitleRender: CodeBlockTitleRender = (title, code) =>
9+
`<div class="code-block-title">
10+
<div class="code-block-title-bar">
11+
<span class="title" data-title="${title}">${title}</span>
12+
</div>
13+
${code}
14+
</div>`
1015

1116
export const codeBlockTitle = (
1217
md: Markdown,
@@ -31,6 +36,6 @@ export const codeBlockTitle = (
3136

3237
if (!title) return rawCode
3338

34-
return `<div class="code-block-title">${titleRender(title)}${rawCode}</div>`
39+
return titleRender(title, rawCode)
3540
}
3641
}

0 commit comments

Comments
 (0)