Skip to content

Commit 14e94d5

Browse files
committed
Fix keyword linker math functions
- Open external urls in the new tab - Fix for some math functions
1 parent df42550 commit 14e94d5

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

web/public/mta-keyword_linker.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,18 @@ function extractFunctions(tmLanguage, textContent) {
2828
matches.forEach(m => {
2929
const lib = m[1];
3030
const funcs = m[2].split("|");
31-
funcs.forEach(fn => result.add(`${lib}.${fn}`));
31+
32+
funcs.forEach(fn => {
33+
if (lib === "math" && fn.endsWith("?")) { // cosh?|sinh?|atan2?
34+
const base = fn.slice(0, -1);
35+
const baseWithoutLastLetter = fn.slice(0, -2);
36+
37+
result.add(`${lib}.${base}`); // sinh|cosh|atan2
38+
result.add(`${lib}.${baseWithoutLastLetter}`); // sin|cos|atan
39+
} else {
40+
result.add(`${lib}.${fn}`);
41+
}
42+
});
3243
});
3344
return;
3445
} else {
@@ -58,7 +69,9 @@ function initKeywordLinker() {
5869
url = `https://www.lua.org/manual/5.1/manual.html#pdf-${text}`;
5970
}
6071

61-
span.innerHTML = `<a href="${url}" class="mta-keyword-link">${text}</a>`;
72+
const isExternalURL = url.startsWith("https://www.");
73+
74+
span.innerHTML = `<a href="${url}" class="mta-keyword-link" ${isExternalURL ? 'target="_blank" rel="noopener noreferrer"' : ""}>${text}</a>`;
6275
}
6376
});
6477
}

0 commit comments

Comments
 (0)