Skip to content

Commit

Permalink
Fix url parsing on web (#176)
Browse files Browse the repository at this point in the history
  • Loading branch information
tiffany352 authored May 12, 2024
1 parent 4123b75 commit dce8c4d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 3 additions & 3 deletions web/repl/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { ExecuteRes, HelloReq, HelloRes, RinkResponse, SpanOrList } from ".

// Taken from https://stackoverflow.com/a/3809435
const urlRegex =
/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/g;
/(?:<|&lt;)([^<>]*)(?:>|&gt;)|(https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*))/g;
const powRegex = /\^(\-?\d+)/g;

function buildInline(parent: HTMLElement, text: string) {
Expand All @@ -12,7 +12,7 @@ function buildInline(parent: HTMLElement, text: string) {
// apply the regexes
text = text.replace(
urlRegex,
(match) => `<a href="${match}" rel="nofollow">${match}</a>`,
(_match, g1, g2) => `<a href="${g1 || g2}" rel="nofollow">${g1 || g2}</a>`,
);
text = text.replace(powRegex, (_match, rest) => `<sup>${rest}</sup>`);
parent.innerHTML = text;
Expand Down Expand Up @@ -245,7 +245,7 @@ Promise.all([wasmBlob, currency]).then(([buffer, currencyDataRes]) => {
JSON.stringify(history),
);
} catch (error) {
pushError(error);
pushError(error as any);
p.remove();
}
}
Expand Down
6 changes: 5 additions & 1 deletion web/repl/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{
"compilerOptions": {
"lib": "es2017"
"target": "es2020",
"module": "es2020",
"moduleResolution": "nodeNext",
"forceConsistentCasingInFileNames": true,
"strict": true
}
}

0 comments on commit dce8c4d

Please sign in to comment.