2025-05-03 19:50:03 +08:00
|
|
|
/* 代码块容器样式 - 简化背景和阴影 */
|
|
|
|
.code-block-container {
|
2025-05-05 19:40:03 +08:00
|
|
|
margin: 0.75rem 0;
|
|
|
|
border-radius: 0.4rem;
|
2025-05-03 19:50:03 +08:00
|
|
|
overflow: hidden;
|
|
|
|
border: 1px solid #e2e8f0;
|
|
|
|
background-color: transparent;
|
|
|
|
position: relative;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 代码块标题栏 */
|
|
|
|
.code-block-header {
|
|
|
|
display: flex;
|
|
|
|
justify-content: space-between;
|
|
|
|
align-items: center;
|
2025-05-05 19:40:03 +08:00
|
|
|
padding: 0.3rem 0.6rem;
|
2025-05-03 19:50:03 +08:00
|
|
|
background-color: #f1f5f9;
|
|
|
|
border-bottom: 1px solid #e2e8f0;
|
|
|
|
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
|
2025-05-05 19:40:03 +08:00
|
|
|
font-size: 0.8rem;
|
2025-05-03 19:50:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* 代码语言标签 */
|
|
|
|
.code-block-lang {
|
|
|
|
font-weight: 600;
|
|
|
|
color: #475569;
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
gap: 0.5rem;
|
|
|
|
}
|
|
|
|
|
|
|
|
.code-block-lang svg {
|
|
|
|
width: 1rem;
|
|
|
|
height: 1rem;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 复制按钮 */
|
|
|
|
.code-block-copy {
|
|
|
|
background: transparent;
|
|
|
|
border: none;
|
|
|
|
cursor: pointer;
|
|
|
|
color: #475569;
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
2025-05-05 19:40:03 +08:00
|
|
|
gap: 0.2rem;
|
|
|
|
padding: 0.2rem 0.4rem;
|
2025-05-03 19:50:03 +08:00
|
|
|
border-radius: 0.25rem;
|
2025-05-05 19:40:03 +08:00
|
|
|
font-size: 0.7rem;
|
2025-05-03 19:50:03 +08:00
|
|
|
transition: all 0.2s ease;
|
|
|
|
}
|
|
|
|
|
|
|
|
.code-block-copy:hover {
|
|
|
|
background-color: #e2e8f0;
|
|
|
|
}
|
|
|
|
|
|
|
|
.code-block-copy.copied {
|
|
|
|
color: #10b981;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 代码内容容器 - 移除背景 */
|
|
|
|
.code-block-content {
|
|
|
|
position: relative;
|
|
|
|
overflow-x: auto;
|
|
|
|
background-color: transparent;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 基础代码块样式 - 减小内边距 */
|
|
|
|
pre {
|
|
|
|
margin: 0;
|
2025-05-05 19:40:03 +08:00
|
|
|
padding: 0.15rem 0;
|
2025-05-03 19:50:03 +08:00
|
|
|
overflow-x: auto;
|
|
|
|
}
|
|
|
|
|
|
|
|
pre code {
|
|
|
|
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
|
2025-05-05 19:40:03 +08:00
|
|
|
font-size: 0.9rem;
|
|
|
|
line-height: 1.4rem;
|
2025-05-03 19:50:03 +08:00
|
|
|
padding: 0;
|
|
|
|
display: block;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 行号样式 - 缩小间距 */
|
|
|
|
.line-numbers {
|
|
|
|
counter-reset: line;
|
|
|
|
position: relative;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 行号背景条 - 减小宽度 */
|
|
|
|
.line-numbers::before {
|
|
|
|
content: "";
|
|
|
|
position: absolute;
|
|
|
|
left: 0;
|
|
|
|
top: 0;
|
|
|
|
bottom: 0;
|
2025-05-05 19:40:03 +08:00
|
|
|
width: 2.5rem;
|
2025-05-03 19:50:03 +08:00
|
|
|
background-color: #f1f5f9;
|
|
|
|
border-right: 1px solid #e2e8f0;
|
|
|
|
z-index: 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 行样式 - 进一步减小行间距和缩进 */
|
|
|
|
.line-numbers .line {
|
|
|
|
position: relative;
|
|
|
|
counter-increment: line;
|
2025-05-05 19:40:03 +08:00
|
|
|
padding-left: 3rem;
|
|
|
|
padding-right: 0.4rem;
|
|
|
|
min-height: 1.4rem;
|
2025-05-03 19:50:03 +08:00
|
|
|
white-space: pre;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 行号 - 调整位置 */
|
|
|
|
.line-numbers .line::before {
|
|
|
|
content: counter(line);
|
|
|
|
position: absolute;
|
|
|
|
left: 0;
|
|
|
|
top: 0;
|
2025-05-05 19:40:03 +08:00
|
|
|
width: 2.5rem;
|
2025-05-03 19:50:03 +08:00
|
|
|
height: 100%;
|
|
|
|
text-align: center;
|
|
|
|
color: #94a3b8;
|
2025-05-05 19:40:03 +08:00
|
|
|
font-size: 0.85rem;
|
2025-05-03 19:50:03 +08:00
|
|
|
user-select: none;
|
|
|
|
z-index: 2;
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: center;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 暗色模式 */
|
|
|
|
[data-theme='dark'] .code-block-container {
|
|
|
|
border-color: #334155;
|
|
|
|
background-color: transparent;
|
|
|
|
}
|
|
|
|
|
|
|
|
[data-theme='dark'] .code-block-header {
|
|
|
|
background-color: #1e293b;
|
|
|
|
border-bottom-color: #334155;
|
|
|
|
}
|
|
|
|
|
|
|
|
[data-theme='dark'] .code-block-lang {
|
|
|
|
color: #e2e8f0;
|
|
|
|
}
|
|
|
|
|
|
|
|
[data-theme='dark'] .code-block-copy {
|
|
|
|
color: #e2e8f0;
|
|
|
|
}
|
|
|
|
|
|
|
|
[data-theme='dark'] .code-block-copy:hover {
|
|
|
|
background-color: #334155;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 移除代码内容区域的黑暗模式背景 */
|
|
|
|
[data-theme='dark'] .code-block-content {
|
|
|
|
background-color: transparent;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 暗色模式行号样式 */
|
|
|
|
[data-theme='dark'] .line-numbers::before {
|
|
|
|
background-color: #1e293b;
|
|
|
|
border-right-color: #334155;
|
|
|
|
}
|
|
|
|
|
|
|
|
[data-theme='dark'] .line-numbers .line::before {
|
|
|
|
color: #64748b;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* 确保所有代码元素没有背景 */
|
|
|
|
code, pre, .code-block-content,
|
|
|
|
.code-block-content pre.shiki,
|
|
|
|
.code-block-content pre.astro-code,
|
|
|
|
.code-block-content pre code,
|
|
|
|
.code-block-content pre code span,
|
|
|
|
pre.shiki, pre.astro-code,
|
|
|
|
.line, .line span {
|
|
|
|
background-color: transparent !important;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 高亮行样式 - 仅保留边框而不添加背景 */
|
|
|
|
.line.highlighted {
|
|
|
|
border-left: 2px solid #eab308;
|
|
|
|
}
|
|
|
|
|
|
|
|
[data-theme='dark'] .line.highlighted {
|
|
|
|
border-left: 2px solid #fbbf24;
|
|
|
|
background-color: transparent !important;
|
2025-05-04 03:44:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* 暗黑主题样式 */
|
|
|
|
[data-theme='dark'] .astro-code {
|
|
|
|
color: var(--shiki-dark) !important;
|
|
|
|
background-color: var(--shiki-dark-bg) !important;
|
|
|
|
}
|
|
|
|
|
|
|
|
[data-theme='dark'] .astro-code span {
|
|
|
|
color: var(--shiki-dark) !important;
|
|
|
|
}
|
|
|
|
|
2025-05-05 19:40:03 +08:00
|
|
|
/* 行内代码块样式 */
|
|
|
|
:not(pre) > code {
|
|
|
|
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
|
|
|
|
font-size: 0.875rem;
|
|
|
|
color: var(--color-primary-700);
|
|
|
|
background-color: var(--color-primary-50);
|
|
|
|
padding: 0.2rem 0.4rem;
|
|
|
|
margin: 0 0.2rem;
|
|
|
|
border-radius: 0.3rem;
|
|
|
|
border: 1px solid var(--color-primary-100);
|
|
|
|
white-space: normal;
|
|
|
|
word-wrap: break-word;
|
|
|
|
overflow-wrap: break-word;
|
|
|
|
word-break: break-all;
|
|
|
|
max-width: 100%;
|
|
|
|
display: inline-block;
|
|
|
|
vertical-align: middle;
|
|
|
|
line-height: 1.4;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 行内代码块黑暗模式样式 */
|
|
|
|
[data-theme='dark'] :not(pre) > code {
|
|
|
|
color: var(--color-primary-300);
|
|
|
|
background-color: rgba(75, 107, 255, 0.1);
|
|
|
|
border-color: var(--color-primary-700);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 长路径的行内代码块样式特殊处理 */
|
|
|
|
:not(pre) > code:has(path),
|
|
|
|
:not(pre) > code.file-path {
|
|
|
|
white-space: pre-wrap; /* 保留空格但允许换行 */
|
|
|
|
overflow-wrap: break-word; /* 允许在任何地方断行 */
|
|
|
|
word-break: break-all; /* 允许在任何字符间断行 */
|
|
|
|
max-width: 100%;
|
|
|
|
display: inline-block;
|
|
|
|
font-size: 0.85rem; /* 略微减小字体尺寸 */
|
|
|
|
padding: 0.2rem 0.4rem;
|
|
|
|
line-height: 1.4;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 针对文件路径的特殊样式 - 适用于Windows路径 */
|
|
|
|
:not(pre) > code.file-path {
|
|
|
|
color: var(--color-gray-700);
|
|
|
|
background-color: var(--color-gray-100);
|
|
|
|
border-color: var(--color-gray-200);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 针对文件路径的特殊样式 - 黑暗模式 */
|
|
|
|
[data-theme='dark'] :not(pre) > code.file-path {
|
|
|
|
color: var(--color-gray-300);
|
|
|
|
background-color: var(--color-gray-800);
|
|
|
|
border-color: var(--color-gray-700);
|
|
|
|
}
|
|
|
|
|