vitepress 2.0.0-alpha.5 → 2.0.0-alpha.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/app/composables/copyCode.js +8 -6
- package/dist/client/shared.js +1 -1
- package/dist/client/theme-default/components/VPLocalSearchBox.vue +4 -0
- package/dist/client/theme-default/components/VPNavBarSearch.vue +1 -1
- package/dist/client/theme-default/styles/components/vp-doc.css +2 -0
- package/dist/node/{chunk-CJIxUApD.js → chunk-cyL7XSn2.js} +653 -656
- package/dist/node/cli.js +3 -2
- package/dist/node/index.d.ts +18 -13
- package/dist/node/index.js +4 -3
- package/package.json +33 -28
- package/types/shared.d.ts +1 -1
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { inBrowser } from 'vitepress';
|
|
2
|
+
const shellRE = /language-(shellscript|shell|bash|sh|zsh)/;
|
|
3
|
+
const ignoredNodes = ['.vp-copy-ignore', '.diff.remove'].join(', ');
|
|
2
4
|
export function useCopyCode() {
|
|
3
5
|
if (inBrowser) {
|
|
4
6
|
const timeoutIdMap = new WeakMap();
|
|
@@ -6,17 +8,17 @@ export function useCopyCode() {
|
|
|
6
8
|
const el = e.target;
|
|
7
9
|
if (el.matches('div[class*="language-"] > button.copy')) {
|
|
8
10
|
const parent = el.parentElement;
|
|
9
|
-
const sibling = el.nextElementSibling?.nextElementSibling;
|
|
11
|
+
const sibling = el.nextElementSibling?.nextElementSibling; // <pre> tag
|
|
10
12
|
if (!parent || !sibling) {
|
|
11
13
|
return;
|
|
12
14
|
}
|
|
13
|
-
const isShell =
|
|
14
|
-
const ignoredNodes = ['.vp-copy-ignore', '.diff.remove'];
|
|
15
|
+
const isShell = shellRE.test(parent.className);
|
|
15
16
|
// Clone the node and remove the ignored nodes
|
|
16
17
|
const clone = sibling.cloneNode(true);
|
|
17
|
-
clone
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
clone.querySelectorAll(ignoredNodes).forEach((node) => node.remove());
|
|
19
|
+
// remove extra newlines left after removing ignored nodes (affecting textContent because it is inside `<pre>`)
|
|
20
|
+
// doesn't affect the newlines already in the code because they are rendered as `\n<span class="line"></span>`
|
|
21
|
+
clone.innerHTML = clone.innerHTML.replace(/\n+/g, '\n');
|
|
20
22
|
let text = clone.textContent || '';
|
|
21
23
|
if (isShell) {
|
|
22
24
|
text = text.replace(/^ *(\$|>) /gm, '').trim();
|
package/dist/client/shared.js
CHANGED
|
@@ -171,7 +171,7 @@ function resolveAdditionalConfig({ additionalConfig }, path) {
|
|
|
171
171
|
if (additionalConfig === undefined)
|
|
172
172
|
return [];
|
|
173
173
|
if (typeof additionalConfig === 'function')
|
|
174
|
-
return additionalConfig(path);
|
|
174
|
+
return additionalConfig(path) ?? [];
|
|
175
175
|
const configs = [];
|
|
176
176
|
const segments = path.split('/').slice(0, -1); // remove file name
|
|
177
177
|
while (segments.length) {
|
|
@@ -53,7 +53,7 @@ onMounted(() => {
|
|
|
53
53
|
|
|
54
54
|
const handleSearchHotKey = (event: KeyboardEvent) => {
|
|
55
55
|
if (
|
|
56
|
-
(event.key
|
|
56
|
+
(event.key?.toLowerCase() === 'k' && (event.metaKey || event.ctrlKey)) ||
|
|
57
57
|
(!isEditingContent(event) && event.key === '/')
|
|
58
58
|
) {
|
|
59
59
|
event.preventDefault()
|