diff --git a/front/text/plain/convert.go b/front/text/plain/convert.go index 586478a5..78eabb3a 100644 --- a/front/text/plain/convert.go +++ b/front/text/plain/convert.go @@ -32,7 +32,8 @@ var ( mentionTags = regexp.MustCompile(`]*>`) invisibleSpanTags = regexp.MustCompile(``) ellipsisSpanTags = regexp.MustCompile(`[^<]*`) - brTags = regexp.MustCompile(`<(?:br\s*\/*|\/p|\/h\d+)>`) + pTags = regexp.MustCompile(`<(?:/p|\/h\d+)>`) + brTags = regexp.MustCompile(``) openTags = regexp.MustCompile(`(?:<[a-zA-Z0-9]+\s*[^>]*>)+`) closeTags = regexp.MustCompile(`(?:<\/[a-zA-Z0-9]+\s*[^>]*>)+`) urlRegex = regexp.MustCompile(`\b(https|http|gemini|gopher|gophers):\/\/\S+\b`) @@ -46,10 +47,14 @@ func FromHTML(text string) (string, data.OrderedMap[string, string]) { res = strings.Replace(res, m, "", 1) } - for _, m := range brTags.FindAllString(res, -1) { + for _, m := range pTags.FindAllString(res, -1) { res = strings.Replace(res, m, "\n\n", 1) } + for _, m := range brTags.FindAllString(res, -1) { + res = strings.Replace(res, m, "\n", 1) + } + for _, m := range invisibleSpanTags.FindAllString(res, -1) { res = strings.Replace(res, m, "", 1) } diff --git a/front/text/plain/convert_test.go b/front/text/plain/convert_test.go index e44f5136..801411c3 100644 --- a/front/text/plain/convert_test.go +++ b/front/text/plain/convert_test.go @@ -84,7 +84,7 @@ func TestFromHTML_TitleParagraphSubtitleAndParagraph(t *testing.T) { func TestFromHTML_LineBreak(t *testing.T) { post := `

this is a line
this is another line

` - expected := "this is a line\n\nthis is another line" + expected := "this is a line\nthis is another line" expectedLinks := data.OrderedMap[string, string]{} raw, links := FromHTML(post)