From f09b4c7808988452a089a6c2af03c2bf095a765c Mon Sep 17 00:00:00 2001 From: Abi Raja Date: Fri, 8 Mar 2024 12:37:37 -0500 Subject: [PATCH] improve preview for videos by showing the streaming response as it comes in --- frontend/src/components/preview/extractHtml.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/frontend/src/components/preview/extractHtml.ts b/frontend/src/components/preview/extractHtml.ts index f33b206..6e9c9ff 100644 --- a/frontend/src/components/preview/extractHtml.ts +++ b/frontend/src/components/preview/extractHtml.ts @@ -1,4 +1,16 @@ +// Not robust enough to support for instance export function extractHtml(code: string): string { - const htmlStartIndex = code.indexOf(""); - return htmlStartIndex !== -1 ? code.slice(htmlStartIndex) : ""; + const lastHtmlStartIndex = code.lastIndexOf(""); + let htmlEndIndex = code.indexOf("", lastHtmlStartIndex); + + if (lastHtmlStartIndex !== -1) { + // If "" is found, adjust htmlEndIndex to include the "" tag + if (htmlEndIndex !== -1) { + htmlEndIndex += "".length; + return code.slice(lastHtmlStartIndex, htmlEndIndex); + } + // If "" is not found, return the rest of the string starting from the last "" + return code.slice(lastHtmlStartIndex); + } + return ""; }