Skip to content

Commit e7b933d

Browse files
committed
Fix hackage urls for documentation and source.
- Changed the regex so it only matches the last /*.html. - Hard code the src directory in the hackage url.
1 parent c59ae94 commit e7b933d

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

src/docsBrowser.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -145,21 +145,25 @@ export namespace DocsBrowser {
145145
function processLink(ms: MarkdownString | MarkedString): string | MarkdownString {
146146
function transform(s: string): string {
147147
return s.replace(
148-
/\[(.+)\]\((file:.+\/doc\/(?:.*html\/libraries\/)?([^\/]+)\/(src\/)?(.+\.html#?.*))\)/gi,
149-
(all, title, localPath, packageName, maybeSrcDir, fileAndAnchor) => {
148+
/\[(.+)\]\((file:.+\/doc\/(?:.*html\/libraries\/)?([^\/]+)\/(?:.*\/)?(.+\.html#?.*))\)/gi,
149+
(all, title, localPath, packageName, fileAndAnchor) => {
150150
let hackageUri: string;
151-
if (!maybeSrcDir) {
151+
if (title == 'Documentation') {
152152
hackageUri = `https://hackage.haskell.org/package/${packageName}/docs/${fileAndAnchor}`;
153-
} else {
154-
hackageUri = `https://hackage.haskell.org/package/${packageName}/docs/${maybeSrcDir}${fileAndAnchor.replace(
153+
const encoded = encodeURIComponent(JSON.stringify({ title, localPath, hackageUri }));
154+
const cmd = 'command:haskell.showDocumentation?' + encoded;
155+
return `[${title}](${cmd})`;
156+
} else if (title == 'Source') {
157+
hackageUri = `https://hackage.haskell.org/package/${packageName}/docs/src/${fileAndAnchor.replace(
155158
/-/gi,
156159
'.'
157160
)}`;
161+
const encoded = encodeURIComponent(JSON.stringify({ title, localPath, hackageUri }));
162+
const cmd = 'command:haskell.showDocumentation?' + encoded;
163+
return `[${title}](${cmd})`;
164+
} else {
165+
return s;
158166
}
159-
160-
const encoded = encodeURIComponent(JSON.stringify({ title, localPath, hackageUri }));
161-
const cmd = 'command:haskell.showDocumentation?' + encoded;
162-
return `[${title}](${cmd})`;
163167
}
164168
);
165169
}

0 commit comments

Comments
 (0)