Skip to content

Commit 9c2432a

Browse files
committed
docs: deno.com-ish styling and URL normalization
1 parent 62c8820 commit 9c2432a

3 files changed

Lines changed: 200 additions & 138 deletions

File tree

docs/app.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -333,14 +333,29 @@ const scheduleExtract = () => {
333333
const normalizeUrl = (raw) => {
334334
let s = raw.trim();
335335
if (!s) return null;
336+
337+
// Remove invisible/annoying whitespace that trim() won't catch.
338+
s = s.replaceAll(/[\u200B-\u200D\uFEFF]/g, "");
339+
340+
// If the user pasted a markdown link or an entire sentence, try to
341+
// extract the first URL-looking substring.
342+
const m = /(https?:\/\/\S+|\/\/\S+)/.exec(s);
343+
if (m) s = m[1];
344+
345+
// Drop surrounding punctuation frequently included when copy/pasting.
336346
s = s.replace(/^<+|>+$/g, "");
337347
s = s.replace(/^\"+|\"+$/g, "");
338348
s = s.replace(/^'+|'+$/g, "");
349+
s = s.replace(/^[([{\s]+|[)\]}.,;:\s]+$/g, "");
350+
351+
// Collapse internal whitespace (e.g. pasted with line breaks).
352+
s = s.replaceAll(/\s+/g, "");
353+
354+
// Accept protocol-relative URLs: //example.com/path
355+
if (s.startsWith("//")) s = `https:${s}`;
339356

340357
// Accept "en.wikipedia.org/wiki/..." by assuming https://.
341-
if (!/^[a-zA-Z][a-zA-Z0-9+.-]*:\/\//.test(s)) {
342-
s = `https://${s}`;
343-
}
358+
if (!/^[a-zA-Z][a-zA-Z0-9+.-]*:\/\//.test(s)) s = `https://${s}`;
344359
try {
345360
const u = new URL(s);
346361
return u.toString();

docs/index.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88
name="description"
99
content="Parse text into structured entities using ts-duckling. Runs fully in your browser."
1010
/>
11+
<link rel="preconnect" href="https://fonts.googleapis.com" />
12+
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
13+
<link
14+
href="https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;600;700&family=IBM+Plex+Mono:wght@400;500;600&display=swap"
15+
rel="stylesheet"
16+
/>
1117
<link rel="stylesheet" href="./style.css" />
1218
<script type="importmap">
1319
{

0 commit comments

Comments
 (0)