vitepress 2.0.0-alpha.5 → 2.0.0-alpha.7

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.
@@ -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 = /language-(shellscript|shell|bash|sh|zsh)/.test(parent.className);
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
- .querySelectorAll(ignoredNodes.join(','))
19
- .forEach((node) => node.remove());
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();
@@ -222,7 +222,7 @@ function normalizeHref(href) {
222
222
  }
223
223
  return url.pathname + url.search + url.hash;
224
224
  }
225
- async function changeRoute(href, { smoothScroll = false, initialLoad = false } = {}) {
225
+ async function changeRoute(href, { smoothScroll = false, initialLoad = false, replace = false } = {}) {
226
226
  const loc = normalizeHref(location.href);
227
227
  const nextUrl = new URL(href, location.origin);
228
228
  const currentUrl = new URL(loc, location.origin);
@@ -233,9 +233,14 @@ async function changeRoute(href, { smoothScroll = false, initialLoad = false } =
233
233
  }
234
234
  }
235
235
  else {
236
- // save scroll position before changing URL
237
- history.replaceState({ scrollPosition: window.scrollY }, '');
238
- history.pushState({}, '', href);
236
+ if (replace) {
237
+ history.replaceState({}, '', href);
238
+ }
239
+ else {
240
+ // save scroll position before changing URL
241
+ history.replaceState({ scrollPosition: window.scrollY }, '');
242
+ history.pushState({}, '', href);
243
+ }
239
244
  if (nextUrl.pathname === currentUrl.pathname) {
240
245
  // scroll between hash anchors on the same page, avoid duplicate entries
241
246
  if (nextUrl.hash !== currentUrl.hash) {
@@ -27,6 +27,7 @@ interface Router {
27
27
  go: (to: string, options?: {
28
28
  initialLoad?: boolean;
29
29
  smoothScroll?: boolean;
30
+ replace?: boolean;
30
31
  }) => Promise<void>;
31
32
  /**
32
33
  * Called before the route changes. Return `false` to cancel the navigation.
@@ -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) {
@@ -663,6 +663,10 @@ function onMouseMove(e: MouseEvent) {
663
663
  width: 100%;
664
664
  }
665
665
 
666
+ .search-input::-webkit-search-cancel-button {
667
+ display: none;
668
+ }
669
+
666
670
  @media (max-width: 767px) {
667
671
  .search-input {
668
672
  padding: 6px 4px;
@@ -53,7 +53,7 @@ onMounted(() => {
53
53
 
54
54
  const handleSearchHotKey = (event: KeyboardEvent) => {
55
55
  if (
56
- (event.key.toLowerCase() === 'k' && (event.metaKey || event.ctrlKey)) ||
56
+ (event.key?.toLowerCase() === 'k' && (event.metaKey || event.ctrlKey)) ||
57
57
  (!isEditingContent(event) && event.key === '/')
58
58
  ) {
59
59
  event.preventDefault()
@@ -317,6 +317,8 @@
317
317
  padding: 20px 0;
318
318
  background: transparent;
319
319
  overflow-x: auto;
320
+ /*rtl:ignore*/
321
+ text-align: left;
320
322
  }
321
323
 
322
324
  .vp-doc [class*='language-'] code {