4a531df8bd
Release APK / build (push) Has been cancelled
The previous stripHtml decoded </> after the regex pass, so content stored as <p>text</p> was never stripped. Now entities are decoded first, then all tags are removed. Also strip HTML when prefilling compose from an existing post (Edit/Repost) so the text field shows clean content, not raw markup. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
20 lines
593 B
TypeScript
20 lines
593 B
TypeScript
export function stripHtml(html: string): string {
|
|
// Decode entities first so encoded tags like <p> are also stripped
|
|
let s = html
|
|
.replace(/&/g, "&")
|
|
.replace(/</g, "<")
|
|
.replace(/>/g, ">")
|
|
.replace(/"/g, '"')
|
|
.replace(/'/g, "'")
|
|
.replace(/ /g, " ");
|
|
// Block-level tags → newlines
|
|
s = s
|
|
.replace(/<br\s*\/?>/gi, "\n")
|
|
.replace(/<\/p>/gi, "\n")
|
|
.replace(/<\/div>/gi, "\n")
|
|
.replace(/<\/li>/gi, "\n");
|
|
// Strip all remaining tags
|
|
s = s.replace(/<[^>]+>/g, "");
|
|
return s.replace(/\n{3,}/g, "\n\n").trim();
|
|
}
|