forked from abi/screenshot-to-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improve preview for videos by showing the streaming response as it co…
…mes in
- Loading branch information
Showing
1 changed file
with
14 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,16 @@ | ||
// Not robust enough to support <html lang='en'> for instance | ||
export function extractHtml(code: string): string { | ||
const htmlStartIndex = code.indexOf("<html>"); | ||
return htmlStartIndex !== -1 ? code.slice(htmlStartIndex) : ""; | ||
const lastHtmlStartIndex = code.lastIndexOf("<html>"); | ||
let htmlEndIndex = code.indexOf("</html>", lastHtmlStartIndex); | ||
|
||
if (lastHtmlStartIndex !== -1) { | ||
// If "</html>" is found, adjust htmlEndIndex to include the "</html>" tag | ||
if (htmlEndIndex !== -1) { | ||
htmlEndIndex += "</html>".length; | ||
return code.slice(lastHtmlStartIndex, htmlEndIndex); | ||
} | ||
// If "</html>" is not found, return the rest of the string starting from the last "<html>" | ||
return code.slice(lastHtmlStartIndex); | ||
} | ||
return ""; | ||
} |