File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -333,14 +333,29 @@ const scheduleExtract = () => {
333333const 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 = / ( h t t p s ? : \/ \/ \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 - z A - Z ] [ a - z A - Z 0 - 9 + . - ] * : \/ \/ / . test ( s ) ) {
342- s = `https://${ s } ` ;
343- }
358+ if ( ! / ^ [ a - z A - Z ] [ a - z A - Z 0 - 9 + . - ] * : \/ \/ / . test ( s ) ) s = `https://${ s } ` ;
344359 try {
345360 const u = new URL ( s ) ;
346361 return u . toString ( ) ;
Original file line number Diff line number Diff line change 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 {
You can’t perform that action at this time.
0 commit comments