Refactor stripHtmlKeepLines to utilize convertBrToNewlines for improved HTML handling

This commit is contained in:
mic 2025-06-18 23:22:05 +02:00
parent c90ee66fb4
commit 4b9631db47

View file

@ -192,7 +192,7 @@ export function sanitizeHtml(input) {
export function stripHtmlKeepLines(htmlString) {
// Replaces <p> tags with a newline at the beginning
// and removes all other HTML tags
return htmlString
return convertBrToNewlines(htmlString)
.replace(/<p>/gi, '') // removes <p> tags
.replace(/<\/p>/gi, '\n') // replaces </p> tags with newline
.replace(/<[^>]*>/g, '') // removes any other HTML tags
@ -203,6 +203,10 @@ export function convertNewlinesToBr(text) {
return text.replace(/\n/g, '<br>');
}
function convertBrToNewlines(html) {
return html.replace(/<br\s*\/?>/gi, '\n');
}
// This method is used to convert the model string id used in the URL
// to the model string used in the webpage
export function getGPTWebModelString(model) {