mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-31 18:12:20 +01:00 
			
		
		
		
	Enable the [same paste features](https://github.com/github/paste-markdown#paste-markdown-objects) that GitHub has, notably the ability to paste text containing HTML links and have them automatically turn into Markdown links. As far as I can tell, previous paste features all work as expected. --------- Signed-off-by: silverwind <me@silverwind.io>
		
			
				
	
	
		
			20 lines
		
	
	
		
			752 B
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			20 lines
		
	
	
		
			752 B
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
| export function pathEscapeSegments(s: string): string {
 | |
|   return s.split('/').map(encodeURIComponent).join('/');
 | |
| }
 | |
| 
 | |
| /** Convert an absolute or relative URL to an absolute URL with the current origin. It only
 | |
|  *  processes absolute HTTP/HTTPS URLs or relative URLs like '/xxx' or '//host/xxx'. */
 | |
| export function toOriginUrl(urlStr: string) {
 | |
|   try {
 | |
|     if (urlStr.startsWith('http://') || urlStr.startsWith('https://') || urlStr.startsWith('/')) {
 | |
|       const {origin, protocol, hostname, port} = window.location;
 | |
|       const url = new URL(urlStr, origin);
 | |
|       url.protocol = protocol;
 | |
|       url.hostname = hostname;
 | |
|       url.port = port || (protocol === 'https:' ? '443' : '80');
 | |
|       return url.toString();
 | |
|     }
 | |
|   } catch {}
 | |
|   return urlStr;
 | |
| }
 |