Skip to content

Commit a646b3f

Browse files
committed
1 parent dc85c64 commit a646b3f

File tree

3 files changed

+157
-0
lines changed

3 files changed

+157
-0
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@
55
crowdin.yaml @FabricMC/developers
66
netlify.toml @FabricMC/developers
77
package.json @FabricMC/developers
8+
patches @FabricMC/developers
89
pnpm-*.yaml @FabricMC/developers

patches/vitepress.patch

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
diff --git a/dist/node/chunk-3d7P_gGE.js b/dist/node/chunk-3d7P_gGE.js
2+
index 2970286cac137f7c15d531954cca600407fdbedd..9b7624e1152bdcb48c62c654c7e7d3861dfe4258 100644
3+
--- a/dist/node/chunk-3d7P_gGE.js
4+
+++ b/dist/node/chunk-3d7P_gGE.js
5+
@@ -36951,32 +36951,41 @@ const markers = [
6+
end: /^\s*\(\*\s*#endregion\b\s*(.*?)\s*\*\)/
7+
}
8+
];
9+
-function findRegion(lines, regionName) {
10+
- let chosen = null;
11+
- for (let i = 0; i < lines.length; i++) {
12+
- for (const re of markers) {
13+
- if (re.start.exec(lines[i])?.[1] === regionName) {
14+
- chosen = { re, start: i + 1 };
15+
- break;
16+
+function findRegions(lines, regionName) {
17+
+ const returned = [];
18+
+ for (const re of markers) {
19+
+ let nestedCounter = 0;
20+
+ let start = null;
21+
+ for (let i = 0; i < lines.length; i++) {
22+
+ const startMatch = re.start.exec(lines[i]);
23+
+ if (startMatch?.[1] === regionName) {
24+
+ if (nestedCounter === 0) start = i + 1;
25+
+ nestedCounter++;
26+
+ continue;
27+
+ }
28+
+ if (nestedCounter === 0) continue;
29+
+ const endMatch = re.end.exec(lines[i]);
30+
+ if (endMatch?.[1] === regionName || endMatch?.[1] === "") {
31+
+ nestedCounter--;
32+
+ if (nestedCounter === 0 && start != null) {
33+
+ returned.push({ re, start, end: i });
34+
+ start = null;
35+
+ }
36+
}
37+
}
38+
- if (chosen) break;
39+
- }
40+
- if (!chosen) return null;
41+
- let counter = 1;
42+
- for (let i = chosen.start; i < lines.length; i++) {
43+
- if (chosen.re.start.exec(lines[i])?.[1] === regionName) {
44+
- counter++;
45+
- continue;
46+
- }
47+
- const endRegion = chosen.re.end.exec(lines[i])?.[1];
48+
- if (endRegion === regionName || endRegion === "") {
49+
- if (--counter === 0) return { ...chosen, end: i };
50+
- }
51+
+ if (returned.length > 0) break;
52+
}
53+
- return null;
54+
+ return returned;
55+
}
56+
const snippetPlugin = (md, srcDir) => {
57+
+ function stripMarkers(lines) {
58+
+ return lines.filter((l) => {
59+
+ for (const m of markers) {
60+
+ if (m.start.test(l) || m.end.test(l)) return false;
61+
+ }
62+
+ return true;
63+
+ }).join("\n");
64+
+ }
65+
const parser = (state, startLine, endLine, silent) => {
66+
const CH = "<".charCodeAt(0);
67+
const pos = state.bMarks[startLine] + state.tShift[startLine];
68+
@@ -37009,26 +37018,40 @@ const snippetPlugin = (md, srcDir) => {
69+
md.renderer.rules.fence = (...args) => {
70+
const [tokens, idx, , { includes }] = args;
71+
const token = tokens[idx];
72+
- const [src, regionName] = token.src ?? [];
73+
+ const [src, region] = token.src ?? [];
74+
if (!src) return fence(...args);
75+
if (includes) {
76+
includes.push(src);
77+
}
78+
- const isAFile = fs.statSync(src).isFile();
79+
- if (!fs.existsSync(src) || !isAFile) {
80+
- token.content = isAFile ? `Code snippet path not found: ${src}` : `Invalid code snippet option`;
81+
+ if (!fs.existsSync(src)) {
82+
+ token.content = `Code snippet path not found: ${src}`;
83+
+ token.info = "";
84+
+ return fence(...args);
85+
+ }
86+
+ if (!fs.statSync(src).isFile()) {
87+
+ token.content = `Invalid code snippet option`;
88+
token.info = "";
89+
return fence(...args);
90+
}
91+
let content = fs.readFileSync(src, "utf8").replace(/\r\n/g, "\n");
92+
- if (regionName) {
93+
+ if (region) {
94+
const lines = content.split("\n");
95+
- const region = findRegion(lines, regionName);
96+
- if (region) {
97+
+ const regions = findRegions(lines, region);
98+
+ if (regions.length > 0) {
99+
content = dedent(
100+
- lines.slice(region.start, region.end).filter((l) => !(region.re.start.test(l) || region.re.end.test(l))).join("\n")
101+
+ stripMarkers(
102+
+ regions.flatMap(
103+
+ (r) => lines.slice(r.start, r.end).filter((l) => !(r.re.start.test(l) || r.re.end.test(l)))
104+
+ )
105+
+ )
106+
);
107+
+ } else {
108+
+ token.content = `No region #${region} found in path: ${src}`;
109+
+ token.info = "";
110+
+ return fence(...args);
111+
}
112+
+ } else {
113+
+ content = stripMarkers(content.split("\n"));
114+
}
115+
token.content = content;
116+
return fence(...args);
117+
@@ -37918,8 +37941,8 @@ function processIncludes(md, srcDir, src, file, includes, cleanUrls) {
118+
if (region) {
119+
const [regionName] = region;
120+
const lines = content.split(/\r?\n/);
121+
- let { start, end } = findRegion(lines, regionName.slice(1)) ?? {};
122+
- if (start === void 0) {
123+
+ let regions = findRegions(lines, regionName.slice(1)) ?? {};
124+
+ if (regions.length === 0) {
125+
const tokens = md.parse(content, {
126+
path: includePath,
127+
relativePath: slash(path$1.relative(srcDir, includePath)),
128+
@@ -37930,17 +37953,23 @@ function processIncludes(md, srcDir, src, file, includes, cleanUrls) {
129+
);
130+
const token = tokens[idx];
131+
if (token) {
132+
- start = token.map[1];
133+
+ const start = token.map[1];
134+
const level = parseInt(token.tag.slice(1));
135+
+ let end = void 0;
136+
for (let i = idx + 1; i < tokens.length; i++) {
137+
if (parseInt(tokens[i].tag.slice(1)) <= level) {
138+
end = tokens[i].map[0];
139+
break;
140+
}
141+
}
142+
+ regions.push({ start, end });
143+
}
144+
}
145+
- content = lines.slice(start, end).join("\n");
146+
+ if (regions.length > 0) {
147+
+ content = regions.flatMap((region2) => lines.slice(region2.start, region2.end)).join("\n");
148+
+ } else {
149+
+ content = `No region or heading #${region} found in path: ${includePath}`;
150+
+ }
151+
}
152+
if (range) {
153+
const [, startLine, endLine] = range;

pnpm-workspace.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@ onlyBuiltDependencies:
77
overrides:
88
vite: npm:rolldown-vite@7.1.17
99
vitepress: ^2.0.0-alpha.12
10+
11+
patchedDependencies:
12+
vitepress: patches/vitepress.patch

0 commit comments

Comments
 (0)