1
0
mirror of https://codeberg.org/tom79/Fedilab synced 2024-12-16 05:17:50 +01:00

Improve link side effect with Markdown

This commit is contained in:
Thomas 2023-08-09 17:56:47 +02:00
parent c9a86aae01
commit 5a804fd892
2 changed files with 9 additions and 2 deletions

View File

@ -40,10 +40,12 @@ public class MarkdownConverter {
public int regexPosition(List<MarkdownItem> markdownItems) {
int position = 0;
int loopedPosition = 0;
for (MarkdownItem markdownItem : markdownItems) {
if (markdownItem.code.equals(code) && position <= this.position) {
if (markdownItem.code.equals(code) && loopedPosition <= this.position) {
position++;
}
loopedPosition++;
}
return position;
}

View File

@ -191,8 +191,13 @@ public class SpannableHelper {
final Spanned markdown = markwon.toMarkdown(initialContent.toString());
content = new SpannableStringBuilder(markdown);
position = 0;
for (MarkdownConverter.MarkdownItem markdownItem : markdownConverter.markdownItems) {
Pattern p = Pattern.compile("(" + Pattern.quote(markdownItem.code) + ")", Pattern.CASE_INSENSITIVE);
String sb = Pattern.compile("\\A[A-Za-z0-9_]").matcher(markdownItem.code).find() ? "\\b" : "";
String eb = Pattern.compile("[A-Za-z0-9_]\\z").matcher(markdownItem.code).find() ? "\\b" : "\\B";
Pattern p = Pattern.compile(sb + "(" + Pattern.quote(markdownItem.code) + ")" + eb, Pattern.CASE_INSENSITIVE);
Matcher m = p.matcher(content);
int fetchPosition = 1;
while (m.find()) {