Skip to content

Commit

Permalink
fix: missing quote in email parser, duplicating imagemaps despite dif…
Browse files Browse the repository at this point in the history
…ferent images (#40)
  • Loading branch information
lenforiee authored Dec 30, 2023
1 parent eff876f commit 14f21bd
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions externals/bbcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func parseEmail(text string) string {
text = regex.ReplaceAllString(text, "<a rel='nofollow' href='mailto:$1'>$1</a>")

regex2 := regexp.MustCompile(`\[email=(([^[]+)@([^[]+))\]`)
text = regex2.ReplaceAllString(text, "<a rel='nofollow' href='mailto:$1>")
text = regex2.ReplaceAllString(text, "<a rel='nofollow' href='mailto:$1'>")
text = strings.Replace(text, "[/email]", "</a>", -1)

return text
Expand Down Expand Up @@ -258,9 +258,12 @@ func parseList(text string) string {

func parseImagemap(text string) string {
regex := regexp.MustCompile(`(?s)\[imagemap\]\s+(?P<image_url>.+?)(?P<lines>(?:\s+.+?)\s+)+\[\/imagemap\]\n?`)
matches := regex.FindStringSubmatch(text)

if matches != nil {
text = ReplaceAllStringSubmatchFunc(regex, text, func(matches []string, _ string) string {
if matches == nil {
return ""
}

pseudoHtml := fmt.Sprintf(
"<div class='bbcode-imagemap'><img src='%s' class='bbcode-imagemap-image' loading='lazy'>",
matches[regex.SubexpIndex("image_url")],
Expand Down Expand Up @@ -322,12 +325,11 @@ func parseImagemap(text string) string {
pseudoHtml += "</div>"
pseudoHtml = strings.Replace(pseudoHtml, "\n", "", -1)

text = regex.ReplaceAllString(text, pseudoHtml)
}
return pseudoHtml
})

return text
}

func parseBox(text string) string {
regex := regexp.MustCompile(`\[box=((\\\[\[\]]|[^][]|\[(\\\[\[\]]|[^][]|(.*?))*\])*?)\]\n*`)

Expand Down

0 comments on commit 14f21bd

Please sign in to comment.