mirror of
https://github.com/tnypxl/rollup.git
synced 2025-12-15 23:13:22 +00:00
fix: remove indentation while preserving HTML structure in ExtractContentWithCSS
This commit is contained in:
@@ -564,13 +564,20 @@ func ExtractContentWithCSS(content, includeSelector string, excludeSelectors []s
|
|||||||
return "", fmt.Errorf("error extracting content with CSS selector: %v", err)
|
return "", fmt.Errorf("error extracting content with CSS selector: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Trim leading and trailing whitespace, but preserve internal newlines
|
// Trim leading and trailing whitespace
|
||||||
selectedContent = strings.TrimSpace(selectedContent)
|
selectedContent = strings.TrimSpace(selectedContent)
|
||||||
|
|
||||||
// Normalize newlines
|
// Normalize newlines
|
||||||
selectedContent = strings.ReplaceAll(selectedContent, "\r\n", "\n")
|
selectedContent = strings.ReplaceAll(selectedContent, "\r\n", "\n")
|
||||||
selectedContent = strings.ReplaceAll(selectedContent, "\r", "\n")
|
selectedContent = strings.ReplaceAll(selectedContent, "\r", "\n")
|
||||||
|
|
||||||
|
// Remove indentation while preserving structure
|
||||||
|
lines := strings.Split(selectedContent, "\n")
|
||||||
|
for i, line := range lines {
|
||||||
|
lines[i] = strings.TrimSpace(line)
|
||||||
|
}
|
||||||
|
selectedContent = strings.Join(lines, "\n")
|
||||||
|
|
||||||
// Remove any leading or trailing newlines
|
// Remove any leading or trailing newlines
|
||||||
selectedContent = strings.Trim(selectedContent, "\n")
|
selectedContent = strings.Trim(selectedContent, "\n")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user