vitepress-allyouneed 0.5.4 → 0.5.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/CHANGELOG.md CHANGED
@@ -2,9 +2,20 @@
2
2
 
3
3
  本项目遵循 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.1.0/);版本号遵循 [SemVer](https://semver.org/lang/zh-CN/)。
4
4
 
5
+
5
6
  ## [Unreleased]
6
7
 
7
8
  ### Fixed
9
+ - **`==highlight==` 在 CJK、粗体、链接或公式旁跨段错配**:高亮规则不再套用为 `*`/`_` 设计的 delimiter flanking 语义,改为原子解析成对 `==` 并递归解析内部 Markdown。`指==**重点**运行==的`、连续多个粗体高亮及高亮内公式/链接现在稳定输出 `<mark>`,不再残留原始 `==`。
10
+
11
+ ## [0.5.5] - 2026-06-20
12
+
13
+ ### Added
14
+ - **目录可由 dirIndex 排序**:`index.md`、`README.md` 或同名目录页现在是该文件夹 group 的排序锚点。默认 `sortBy: 'order-then-title'` 下,给目录页写 `order: 1` 即可控制目录位置;嵌套目录、`per-folder` 根侧栏和 `autoNav` 均一致生效,无需给文件夹名添加数字前缀。顶级 `groupOrder` 仍具有最高优先级。
15
+
16
+ ### Fixed
17
+ - **嵌套 `index.md` 生成错误的无尾斜杠 URL**:`cleanUrls: true` 下目录页现在输出 `/guide/` 而不是 `/guide`;与 VitePress 的 `guide/index.html` 路由及 dead-link validator 保持一致。
18
+ - **`scanWikilinks` 把合法 `[[folder/]]` 误报为死链**:启动预扫不再维护遗漏 `folderLinkOrder` 的简化解析器,改为与渲染阶段共用 `resolveWikilink`;目录 index、相对路径、自引用锚点和冲突策略现在只有一套解析语义。
8
19
  - **同名页面跨 locale / 区域解析错误**:`[[Gravitationsphysik]]` 这类 basename-only Wikilink 不再直接使用全局 `onConflict`。解析器现在先按源页面的同目录和最长共同路径前缀收窄候选(例如 `zh/themen/*` 优先于 `zh/selfcheck/*`,二者都优先于其它 locale),仍有歧义时才执行 `shortest` / `first` / `error`。
9
20
  - 强化当前源页面定位:relativePath 精确匹配先于后缀兜底,且后缀存在多个 locale 命中时不再取扫描顺序中的第一个。
10
21
 
package/dist/index.cjs CHANGED
@@ -594,7 +594,8 @@ function computeUrl(rel, options) {
594
594
  } else if (!options.cleanUrls) {
595
595
  segments.push("index.html");
596
596
  }
597
- return buildUrl("/", segments);
597
+ const url = buildUrl("/", segments);
598
+ return isIndex && options.cleanUrls ? url + "/" : url;
598
599
  }
599
600
  function pushToArrayMap(m, k, v) {
600
601
  const arr = m.get(k);
@@ -1784,79 +1785,49 @@ function registerCallouts(md) {
1784
1785
 
1785
1786
  // src/modules/highlight/rule.ts
1786
1787
  var EQ = 61;
1787
- function tokenize(state, silent) {
1788
- if (silent) return false;
1789
- const start = state.pos;
1790
- const marker = state.src.charCodeAt(start);
1791
- if (marker !== EQ) return false;
1792
- const scanned = state.scanDelims(state.pos, true);
1793
- let len = scanned.length;
1794
- const ch = String.fromCharCode(marker);
1795
- if (len < 2) return false;
1796
- let token;
1797
- if (len % 2) {
1798
- token = state.push("text", "", 0);
1799
- token.content = ch;
1800
- len -= 1;
1801
- }
1802
- for (let i = 0; i < len; i += 2) {
1803
- token = state.push("text", "", 0);
1804
- token.content = ch + ch;
1805
- const delims = state.delimiters;
1806
- delims.push({
1807
- marker,
1808
- length: 0,
1809
- // 关掉 emphasis 用的 "rule of 3"
1810
- jump: i / 2,
1811
- // 1 delimiter = 2 chars
1812
- token: state.tokens.length - 1,
1813
- end: -1,
1814
- open: scanned.can_open,
1815
- close: scanned.can_close
1816
- });
1788
+ var BACKSLASH = 92;
1789
+ function findClosingMarker(src, from) {
1790
+ for (let pos = from; pos < src.length - 1; pos += 1) {
1791
+ if (src.charCodeAt(pos) === BACKSLASH) {
1792
+ pos += 1;
1793
+ continue;
1794
+ }
1795
+ if (src.charCodeAt(pos) === EQ && src.charCodeAt(pos + 1) === EQ) {
1796
+ return pos;
1797
+ }
1817
1798
  }
1818
- state.pos += scanned.length;
1819
- return true;
1799
+ return -1;
1820
1800
  }
1821
- function postProcess(state) {
1822
- const delimiters = state.delimiters;
1823
- const loneMarkers = [];
1824
- const max = delimiters.length;
1825
- for (let i = 0; i < max; i++) {
1826
- const startDelim = delimiters[i];
1827
- if (startDelim.marker !== EQ) continue;
1828
- if (startDelim.end === -1) continue;
1829
- const endDelim = delimiters[startDelim.end];
1830
- let token = state.tokens[startDelim.token];
1831
- token.type = "mark_open";
1832
- token.tag = "mark";
1833
- token.nesting = 1;
1834
- token.markup = "==";
1835
- token.content = "";
1836
- token = state.tokens[endDelim.token];
1837
- token.type = "mark_close";
1838
- token.tag = "mark";
1839
- token.nesting = -1;
1840
- token.markup = "==";
1841
- token.content = "";
1842
- const prev = state.tokens[endDelim.token - 1];
1843
- if (prev && prev.type === "text" && prev.content === "=") {
1844
- loneMarkers.push(endDelim.token - 1);
1845
- }
1801
+ function tokenize(state, silent) {
1802
+ const start = state.pos;
1803
+ if (state.src.charCodeAt(start) !== EQ || state.src.charCodeAt(start + 1) !== EQ) {
1804
+ return false;
1846
1805
  }
1847
- while (loneMarkers.length > 0) {
1848
- const i = loneMarkers.pop();
1849
- let j = i + 1;
1850
- while (j < state.tokens.length && state.tokens[j].type === "mark_close") {
1851
- j += 1;
1852
- }
1853
- j -= 1;
1854
- if (i !== j) {
1855
- const tmp = state.tokens[j];
1856
- state.tokens[j] = state.tokens[i];
1857
- state.tokens[i] = tmp;
1858
- }
1806
+ const close = findClosingMarker(state.src, start + 2);
1807
+ if (close < 0 || close === start + 2) return false;
1808
+ const end = close + 2;
1809
+ if (silent) {
1810
+ state.pos = end;
1811
+ return true;
1859
1812
  }
1813
+ const open = state.push("mark_open", "mark", 1);
1814
+ open.markup = "==";
1815
+ const inner = [];
1816
+ state.md.inline.parse(
1817
+ state.src.slice(start + 2, close),
1818
+ state.md,
1819
+ state.env,
1820
+ inner
1821
+ );
1822
+ const levelOffset = state.level;
1823
+ for (const token of inner) {
1824
+ token.level += levelOffset;
1825
+ state.tokens.push(token);
1826
+ }
1827
+ const closeToken = state.push("mark_close", "mark", -1);
1828
+ closeToken.markup = "==";
1829
+ state.pos = end;
1830
+ return true;
1860
1831
  }
1861
1832
  function registerHighlightInline(md) {
1862
1833
  try {
@@ -1864,27 +1835,6 @@ function registerHighlightInline(md) {
1864
1835
  } catch {
1865
1836
  md.inline.ruler.before("emphasis", "allyouneed_highlight", tokenize);
1866
1837
  }
1867
- md.inline.ruler2.before(
1868
- "emphasis",
1869
- "allyouneed_highlight",
1870
- function highlightPostProcess(state) {
1871
- const tokens_meta = state.tokens_meta;
1872
- const curr = state.delimiters;
1873
- if (curr) postProcess(state);
1874
- if (tokens_meta) {
1875
- for (const m of tokens_meta) {
1876
- if (m && m.delimiters) {
1877
- const proxy = {
1878
- ...state,
1879
- delimiters: m.delimiters
1880
- };
1881
- postProcess(proxy);
1882
- }
1883
- }
1884
- }
1885
- return false;
1886
- }
1887
- );
1888
1838
  }
1889
1839
 
1890
1840
  // src/modules/highlight/index.ts
@@ -2401,7 +2351,7 @@ function renderTemplate(v) {
2401
2351
  // src/core/views/generate-data.ts
2402
2352
  var import_node_fs6 = __toESM(require("fs"), 1);
2403
2353
  var import_node_path6 = __toESM(require("path"), 1);
2404
- var PLUGIN_VERSION = true ? "0.5.4" : "0.0.0-dev";
2354
+ var PLUGIN_VERSION = true ? "0.5.6" : "0.0.0-dev";
2405
2355
  var WIKILINK_RE = /(!?)\[\[([^\]\n]+)\]\]/g;
2406
2356
  var DEFAULT_BODY_TAG_RE = /(?:^|[\s([{,;。,;])#([\p{L}_][\p{L}\p{N}_/-]*)/gu;
2407
2357
  function buildBodyTagRe(userPattern) {
@@ -3453,8 +3403,27 @@ function shouldLinkGroup(opts, isTopLevel) {
3453
3403
  }
3454
3404
  function sortChildKeys(node, opts, isTopLevel) {
3455
3405
  const keys = [...node.children.keys()];
3406
+ const collateOpts = { numeric: true, sensitivity: "base" };
3407
+ const compareFolderKeys = (a, b) => {
3408
+ const aNode = node.children.get(a);
3409
+ const bNode = node.children.get(b);
3410
+ const aAnchor = pickTitleSourceCandidate(aNode);
3411
+ const bAnchor = pickTitleSourceCandidate(bNode);
3412
+ if (opts.sortBy === "mtime-desc") {
3413
+ const am = aAnchor?.mtime ?? Number.NEGATIVE_INFINITY;
3414
+ const bm = bAnchor?.mtime ?? Number.NEGATIVE_INFINITY;
3415
+ if (am !== bm) return bm - am;
3416
+ } else if (opts.sortBy === "order-then-title") {
3417
+ const ao = aAnchor ? readOrder(aAnchor, opts.orderKey) : Number.POSITIVE_INFINITY;
3418
+ const bo = bAnchor ? readOrder(bAnchor, opts.orderKey) : Number.POSITIVE_INFINITY;
3419
+ if (ao !== bo) return ao - bo;
3420
+ }
3421
+ const at = computeGroupText(aNode.path, aAnchor, opts);
3422
+ const bt = computeGroupText(bNode.path, bAnchor, opts);
3423
+ return at.localeCompare(bt, void 0, collateOpts);
3424
+ };
3456
3425
  if (!isTopLevel || opts.groupOrder.length === 0) {
3457
- return keys.sort();
3426
+ return keys.sort(compareFolderKeys);
3458
3427
  }
3459
3428
  const orderMap = /* @__PURE__ */ new Map();
3460
3429
  opts.groupOrder.forEach((name, i) => {
@@ -3490,7 +3459,7 @@ function sortChildKeys(node, opts, isTopLevel) {
3490
3459
  const ob = orderMap.has(b) ? orderMap.get(b) : orderMap.get(tb);
3491
3460
  return oa - ob;
3492
3461
  });
3493
- rest.sort();
3462
+ rest.sort(compareFolderKeys);
3494
3463
  return [...indexed, ...rest];
3495
3464
  }
3496
3465
  function toFlatSidebar(root, opts) {
@@ -3540,7 +3509,12 @@ function toPerFolderSidebar(root, opts, options, index) {
3540
3509
  for (const f of sortedRootFiles) {
3541
3510
  rootItems.push({ text: opts.formatItemTitle(f), link: f.url });
3542
3511
  }
3543
- const topKeys = [...root.children.keys()].sort();
3512
+ const topKeys = sortChildKeys(
3513
+ root,
3514
+ opts,
3515
+ /* isTopLevel */
3516
+ true
3517
+ );
3544
3518
  for (const key of topKeys) {
3545
3519
  const child = root.children.get(key);
3546
3520
  const childWinner = resolveFolderLink(
@@ -3617,7 +3591,12 @@ function generateNav(index, options, autoOptions = {}) {
3617
3591
  const root = buildTree2(visible);
3618
3592
  const base = options.base.endsWith("/") ? options.base : options.base + "/";
3619
3593
  const out = [{ text: opts.homeNavText, link: "/" }];
3620
- const topKeys = [...root.children.keys()].sort();
3594
+ const topKeys = sortChildKeys(
3595
+ root,
3596
+ opts,
3597
+ /* isTopLevel */
3598
+ true
3599
+ );
3621
3600
  for (const key of topKeys) {
3622
3601
  const child = root.children.get(key);
3623
3602
  const winner = resolveFolderLink(
@@ -3909,9 +3888,14 @@ function scanWikilinks(index, options) {
3909
3888
  if (isAsset) continue;
3910
3889
  }
3911
3890
  }
3912
- const isSelfAnchor = !rawTarget && !!headingPart;
3913
- const found = isSelfAnchor || resolveSimple(rawTarget, index, options, f.relativePath);
3914
- if (!found) {
3891
+ const resolved = resolveWikilink(
3892
+ rawTargetFull,
3893
+ index,
3894
+ options,
3895
+ isEmbed ? "transclusion" : "page",
3896
+ f.absolutePath
3897
+ );
3898
+ if (resolved.isDead) {
3915
3899
  dead.push({
3916
3900
  source: f.relativePath,
3917
3901
  target: rawTarget,
@@ -3920,7 +3904,7 @@ function scanWikilinks(index, options) {
3920
3904
  continue;
3921
3905
  }
3922
3906
  if (scanAmbig && headingPart) {
3923
- const targetEntry = isSelfAnchor ? f : resolveSimpleEntry(rawTarget, index, options, f.relativePath);
3907
+ const targetEntry = resolved.target;
3924
3908
  if (!targetEntry) continue;
3925
3909
  const matches2 = findAmbiguousLeadingNumberMatches(targetEntry, headingPart);
3926
3910
  if (matches2.length > 1) {
@@ -3942,27 +3926,6 @@ function scanWikilinks(index, options) {
3942
3926
  }
3943
3927
  return { total, dead, ambiguous };
3944
3928
  }
3945
- function resolveSimpleEntry(raw, index, options, currentSourceRel) {
3946
- const target = stripMarkdownExt(toPosix(raw));
3947
- if (!target) return void 0;
3948
- if (target.includes("/")) {
3949
- const e = index.byRelativePath.get(target) ?? index.byRelativePath.get(target + ".md") ?? index.byRelativePath.get(target + ".markdown");
3950
- if (e) return e;
3951
- if (currentSourceRel) {
3952
- const curDir = currentSourceRel.split("/").slice(0, -1).join("/");
3953
- if (curDir) {
3954
- return index.byRelativePath.get(`${curDir}/${target}`) ?? index.byRelativePath.get(`${curDir}/${target}.md`) ?? index.byRelativePath.get(`${curDir}/${target}.markdown`);
3955
- }
3956
- }
3957
- return void 0;
3958
- }
3959
- const aliasKey = options.caseSensitive ? target : target.toLowerCase();
3960
- const aliased = index.byAlias.get(aliasKey);
3961
- if (aliased) return aliased;
3962
- const map = options.caseSensitive ? index.byBasename : index.byBasenameLower;
3963
- const key = options.caseSensitive ? target : target.toLowerCase();
3964
- return map.get(key)?.[0];
3965
- }
3966
3929
  function logDeadLinks(report, deadLink) {
3967
3930
  if (deadLink === "silent") return;
3968
3931
  if (report.dead.length > 0) {
@@ -4011,27 +3974,6 @@ function extractExt3(target) {
4011
3974
  if (dot <= 0) return "";
4012
3975
  return cleaned.slice(dot + 1).toLowerCase();
4013
3976
  }
4014
- function resolveSimple(raw, index, options, currentSourceRel) {
4015
- const target = stripMarkdownExt(toPosix(raw));
4016
- if (!target) return false;
4017
- if (target.includes("/")) {
4018
- if (index.byRelativePath.has(target) || index.byRelativePath.has(target + ".md") || index.byRelativePath.has(target + ".markdown")) {
4019
- return true;
4020
- }
4021
- if (currentSourceRel) {
4022
- const curDir = currentSourceRel.split("/").slice(0, -1).join("/");
4023
- if (curDir) {
4024
- return index.byRelativePath.has(`${curDir}/${target}`) || index.byRelativePath.has(`${curDir}/${target}.md`) || index.byRelativePath.has(`${curDir}/${target}.markdown`);
4025
- }
4026
- }
4027
- return false;
4028
- }
4029
- const aliasKey = options.caseSensitive ? target : target.toLowerCase();
4030
- if (index.byAlias.has(aliasKey)) return true;
4031
- const map = options.caseSensitive ? index.byBasename : index.byBasenameLower;
4032
- const key = options.caseSensitive ? target : target.toLowerCase();
4033
- return (map.get(key)?.length ?? 0) > 0;
4034
- }
4035
3977
 
4036
3978
  // src/vitepress.ts
4037
3979
  var autoFolderIndexWarned = false;