Skip to content

Commit

Permalink
fix: post editing in BBCode (paragraphs, mentions, hashtags and group…
Browse files Browse the repository at this point in the history
… references) (#783)

* fix: remove unnecessary [p] from BBCode editing

* fix: remove links from mentions, hashtags and group references
  • Loading branch information
AkesiSeli authored Feb 1, 2025
1 parent 06f9cbb commit 422e87d
Showing 1 changed file with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ internal class DefaultBBCodeConverter : BBCodeConverter {
"ul" -> builder.append("[ul]")
"ol" -> builder.append("[ol]")
"li" -> builder.append("[li]")
"p" -> builder.append("[p]")
"code" -> builder.append("[code]")
"blockquote" -> builder.append("[quote]")
"q" -> builder.append("[quote]")
Expand Down Expand Up @@ -102,7 +101,7 @@ internal class DefaultBBCodeConverter : BBCodeConverter {
"u" -> builder.append("[/u]")
"i", "em" -> builder.append("[/i]")
"s" -> builder.append("[/s]")
"p" -> builder.append("[/p]")
"p" -> builder.append("\n\n")
"code" -> builder.append("[/code]")
"a" -> builder.append("[/url]")
"ul" -> builder.append("[/ul]")
Expand All @@ -121,7 +120,28 @@ internal class DefaultBBCodeConverter : BBCodeConverter {
end()
}

return builder.toString()
// fix hashtags, mentions and group references removing links
val result =
builder
.toString()
.let { stepResult ->
Regex("!" + ContentRegexes.BBCODE_URL.pattern).substituteAllOccurrences(stepResult) { match ->
val anchor = match.groups["anchor"]?.value.orEmpty()
append("!$anchor")
}
}.let { stepResult ->
Regex("@" + ContentRegexes.BBCODE_URL.pattern).substituteAllOccurrences(stepResult) { match ->
val anchor = match.groups["anchor"]?.value.orEmpty()
append("@$anchor")
}
}.let { stepResult ->
Regex("#" + ContentRegexes.BBCODE_URL.pattern).substituteAllOccurrences(stepResult) { match ->
val anchor = match.groups["anchor"]?.value.orEmpty()
append("#$anchor")
}
}

return result
}
}

Expand Down

0 comments on commit 422e87d

Please sign in to comment.