Skip to content

Commit

Permalink
improve preview for videos by showing the streaming response as it co…
Browse files Browse the repository at this point in the history
…mes in
  • Loading branch information
abi committed Mar 8, 2024
1 parent cacf78a commit f09b4c7
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions frontend/src/components/preview/extractHtml.ts
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 "";
}

0 comments on commit f09b4c7

Please sign in to comment.