Files
orca/src/shared/html-file-url.ts
T
Jinjing 524fa0039b Preview HTML files by default (#31575)
* Preview HTML files by default across file-opening flows

* Centralize workspace file opening and HTML preview routing

- Preserve source, diff, and host-safety behavior across all entry points
- Reuse previews within the requested editor group and support branch HTML files

* Respect working tree state when opening HTML previews

* Route HTML links through owning workspaces and editors

* Preserve HTML preview state and refresh changed local files

* Resolve HTML preview hosts from workspace ownership

* Update file-opening tests for HTML preview routing
2026-10-21 13:31:50 -07:00

23 lines
688 B
TypeScript

import { fileUriToFilesystemPath } from './file-uri-path'
export function isHtmlFilePath(filePath: string): boolean {
return /\.html?$/i.test(filePath)
}
/** File authorities name this machine, never an Orca SSH target. */
export function htmlFilePathFromUrl(input: string): string | null {
if (!/^file:\/\//i.test(input) || /[?#\p{Cc}]|%2f|%5c/iu.test(input)) {
return null
}
try {
const url = new URL(input)
if (url.hostname || url.pathname.startsWith('//')) {
return null
}
const filePath = fileUriToFilesystemPath(url)
return filePath && isHtmlFilePath(filePath) && !/\p{Cc}/u.test(filePath) ? filePath : null
} catch {
return null
}
}