CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/next/lib/share/url-transform.ts
Views: 687
1
import { join } from "path";
2
import rawURL from "./raw-url";
3
4
interface Options {
5
id: string;
6
path: string;
7
relativePath: string;
8
}
9
10
// NOTE: there is a similar function in frontend/project/page/url-transform.ts
11
export default function getUrlTransform({
12
id,
13
path,
14
relativePath, // relative path of the directory containing the file we are rendering.
15
}: Options): (href: string, tag: string) => string | undefined {
16
return (href: string, tag: string) => {
17
if (href.startsWith("data:")) return; // never change data: urls in any way.
18
if (tag == "a" || href.includes("://")) {
19
// Don't modify anything non-local, i.e., like https://...
20
// Also don't modify a tags at all.
21
return;
22
}
23
return rawURL({ id, path, relativePath: join(relativePath, href) });
24
};
25
}
26
27