diff --git a/app/src/main/java/app/fedilab/android/mastodon/client/entities/app/MarkdownConverter.java b/app/src/main/java/app/fedilab/android/mastodon/client/entities/app/MarkdownConverter.java index cc074fb6d..5fb0489d7 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/client/entities/app/MarkdownConverter.java +++ b/app/src/main/java/app/fedilab/android/mastodon/client/entities/app/MarkdownConverter.java @@ -40,10 +40,12 @@ public class MarkdownConverter { public int regexPosition(List 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; } diff --git a/app/src/main/java/app/fedilab/android/mastodon/helper/SpannableHelper.java b/app/src/main/java/app/fedilab/android/mastodon/helper/SpannableHelper.java index 0f3ade01e..3869b1bd2 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/helper/SpannableHelper.java +++ b/app/src/main/java/app/fedilab/android/mastodon/helper/SpannableHelper.java @@ -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()) {