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:
parent
c9a86aae01
commit
5a804fd892
@ -40,10 +40,12 @@ public class MarkdownConverter {
|
|||||||
|
|
||||||
public int regexPosition(List<MarkdownItem> markdownItems) {
|
public int regexPosition(List<MarkdownItem> markdownItems) {
|
||||||
int position = 0;
|
int position = 0;
|
||||||
|
int loopedPosition = 0;
|
||||||
for (MarkdownItem markdownItem : markdownItems) {
|
for (MarkdownItem markdownItem : markdownItems) {
|
||||||
if (markdownItem.code.equals(code) && position <= this.position) {
|
if (markdownItem.code.equals(code) && loopedPosition <= this.position) {
|
||||||
position++;
|
position++;
|
||||||
}
|
}
|
||||||
|
loopedPosition++;
|
||||||
}
|
}
|
||||||
return position;
|
return position;
|
||||||
}
|
}
|
||||||
|
@ -191,8 +191,13 @@ public class SpannableHelper {
|
|||||||
final Spanned markdown = markwon.toMarkdown(initialContent.toString());
|
final Spanned markdown = markwon.toMarkdown(initialContent.toString());
|
||||||
content = new SpannableStringBuilder(markdown);
|
content = new SpannableStringBuilder(markdown);
|
||||||
position = 0;
|
position = 0;
|
||||||
|
|
||||||
for (MarkdownConverter.MarkdownItem markdownItem : markdownConverter.markdownItems) {
|
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);
|
Matcher m = p.matcher(content);
|
||||||
int fetchPosition = 1;
|
int fetchPosition = 1;
|
||||||
while (m.find()) {
|
while (m.find()) {
|
||||||
|
Loading…
Reference in New Issue
Block a user