@oversk7/pi-web-dsh-style 1.3.0 → 1.3.1
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/package.json +1 -1
- package/server.ts +7 -1
- package/web/app.js +7 -4
- package/web/assets/markdown.js +8 -8
- package/web/markdown.ts +11 -3
package/web/markdown.ts
CHANGED
|
@@ -6,7 +6,7 @@ import powershell from "highlight.js/lib/languages/powershell";
|
|
|
6
6
|
hljs.registerLanguage("dockerfile", dockerfile);
|
|
7
7
|
hljs.registerLanguage("powershell", powershell);
|
|
8
8
|
|
|
9
|
-
function localFileLink(target: string) {
|
|
9
|
+
function localFileLink(target: string, workspace = false) {
|
|
10
10
|
let value = target.trim();
|
|
11
11
|
let line: number | null = null;
|
|
12
12
|
const location = /#L(\d+)(?:C\d+)?$/i.exec(value) || /:(\d+)(?::\d+)?$/.exec(value);
|
|
@@ -22,7 +22,15 @@ function localFileLink(target: string) {
|
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
value = value.replace(/^\/([A-Za-z]:[\\/])/, "$1");
|
|
25
|
-
if (!/^[A-Za-z]:[\\/]/.test(value) && !/^\\\\[^\\]+\\[^\\]+/.test(value))
|
|
25
|
+
if (!/^[A-Za-z]:[\\/]/.test(value) && !/^\\\\[^\\]+\\[^\\]+/.test(value)) {
|
|
26
|
+
if (!workspace || /^[a-z][a-z\d+.-]*:|^\/\//i.test(value) || /[?#]/.test(value)) return null;
|
|
27
|
+
if (!/\.(?:md|markdown|mdx|txt|html?|css|[cm]?[jt]sx?|json|ya?ml|toml|py|rs|go|java|c|cpp|h|hpp|cs|sh|ps1|sql|xml|csv)$/i.test(value)) return null;
|
|
28
|
+
try {
|
|
29
|
+
value = decodeURIComponent(value).replace(/^\/+/, "");
|
|
30
|
+
} catch {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
26
34
|
const href = `/api/fs/view?path=${encodeURIComponent(value)}${line ? `#L${line}` : ""}`;
|
|
27
35
|
return { path: value, line, href };
|
|
28
36
|
}
|
|
@@ -52,7 +60,7 @@ parser.validateLink = (target) => Boolean(localFileLink(target)) || validateLink
|
|
|
52
60
|
parser.renderer.rules.link_open = (tokens, index, options, env, renderer) => {
|
|
53
61
|
const token = tokens[index];
|
|
54
62
|
const target = String(token.attrGet("href") || "");
|
|
55
|
-
const local = localFileLink(target);
|
|
63
|
+
const local = localFileLink(target, true);
|
|
56
64
|
if (local) {
|
|
57
65
|
token.attrSet("href", local.href);
|
|
58
66
|
token.attrJoin("class", "md-local-file");
|