Merge branch 'main' into main

pull/4718/head
froQ 3 weeks ago committed by GitHub
commit d71169512c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -308,20 +308,20 @@ server {
index index.html;
location / {
# content location
# 内容位置
root /app;
# exact matches -> reverse clean urls -> folders -> not found
# 完全匹配 -> 反向清理 url -> 文件夹 -> 没有发现
try_files $uri $uri.html $uri/ =404;
# non existent pages
# 不存在的页面
error_page 404 /404.html;
# a folder without index.html raises 403 in this setup
# 在此设置中,如果文件夹没有 index.html就会引发 403 错误
error_page 403 /404.html;
# adjust caching headers
# files in the assets folder have hashes filenames
# 调整缓存标头
# assets 文件夹中的文件都有哈希文件名
location ~* ^/assets/ {
expires 1y;
add_header Cache-Control "public, immutable";

@ -55,8 +55,8 @@ export default DefaultTheme
```css
/* .vitepress/theme/my-fonts.css */
:root {
--vp-font-family-base: /* normal text font */
--vp-font-family-mono: /* code font */
--vp-font-family-base: /* 普通文本字体 */
--vp-font-family-mono: /* 代码字体 */
}
```

@ -1,6 +1,6 @@
import { inBrowser } from 'vitepress'
import { isShell } from '../../shared'
const shellRE = /language-(shellscript|shell|bash|sh|zsh)/
const ignoredNodes = ['.vp-copy-ignore', '.diff.remove'].join(', ')
export function useCopyCode() {
@ -15,8 +15,6 @@ export function useCopyCode() {
return
}
const isShell = shellRE.test(parent.className)
// Clone the node and remove the ignored nodes
const clone = sibling.cloneNode(true) as HTMLElement
clone.querySelectorAll(ignoredNodes).forEach((node) => node.remove())
@ -26,7 +24,10 @@ export function useCopyCode() {
let text = clone.textContent || ''
if (isShell) {
// NOTE: Any changes to this the code here may also need to update
// `transformerDisableShellSymbolSelect` in `src/node/markdown/plugins/highlight.ts`
const lang = /language-(\w+)/.exec(parent.className)?.[1] || ''
if (isShell(lang)) {
text = text.replace(/^ *(\$|>) /gm, '').trim()
}

@ -119,7 +119,7 @@ watch(
@media (min-width: 960px) {
.curtain {
position: sticky;
top: -64px;
top: calc(var(--vp-nav-height) * -1);
left: 0;
z-index: 1;
margin-top: calc(var(--vp-nav-height) * -1);

@ -10,10 +10,45 @@ import c from 'picocolors'
import type { BundledLanguage, ShikiTransformer } from 'shiki'
import { createHighlighter, guessEmbeddedLanguages, isSpecialLang } from 'shiki'
import type { Logger } from 'vite'
import { isShell } from '../../shared'
import type { MarkdownOptions, ThemeOptions } from '../markdown'
const nanoid = customAlphabet('abcdefghijklmnopqrstuvwxyz', 10)
/**
* Prevents the leading '$' symbol etc from being selectable/copyable. Also
* normalizes its syntax so there's no leading spaces, and only a single
* trailing space.
*
* NOTE: Any changes to this function may also need to update
* `src/client/app/composables/copyCode.ts`
*/
function transformerDisableShellSymbolSelect(): ShikiTransformer {
return {
name: 'vitepress:disable-shell-symbol-select',
tokens(tokensByLine) {
if (!isShell(this.options.lang)) return
for (const tokens of tokensByLine) {
if (tokens.length < 2) continue
// The first token should only be a symbol token
const firstTokenText = tokens[0].content.trim()
if (firstTokenText !== '$' && firstTokenText !== '>') continue
// The second token must have a leading space (separates the symbol)
if (tokens[1].content[0] !== ' ') continue
tokens[0].content = firstTokenText + ' '
tokens[0].htmlStyle ??= {}
tokens[0].htmlStyle['user-select'] = 'none'
tokens[0].htmlStyle['-webkit-user-select'] = 'none'
tokens[1].content = tokens[1].content.slice(1)
}
}
}
}
export async function highlight(
theme: ThemeOptions,
options: MarkdownOptions,
@ -51,6 +86,7 @@ export async function highlight(
}),
transformerNotationHighlight(),
transformerNotationErrorLevel(),
transformerDisableShellSymbolSelect(),
{
name: 'vitepress:add-dir',
pre(node) {

@ -353,3 +353,8 @@ type ObjectType = Record<PropertyKey, any>
export function isObject(value: unknown): value is ObjectType {
return Object.prototype.toString.call(value) === '[object Object]'
}
const shellLangs = ['shellscript', 'shell', 'bash', 'sh', 'zsh']
export function isShell(lang: string): boolean {
return shellLangs.includes(lang)
}

Loading…
Cancel
Save