diff options
author | Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> | 2023-02-21 02:36:38 +0000 |
---|---|---|
committer | Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> | 2023-02-21 02:36:38 +0000 |
commit | efcfa0ae71c90796b1995737d4feac46fe3542b1 (patch) | |
tree | ae6e335b476efd3c32f490334a1bed02cecceedf /app/src | |
parent | 9db90a04317dcdcc5cce6b0954371b62084153a8 (diff) | |
download | infinity-for-reddit-efcfa0ae71c90796b1995737d4feac46fe3542b1.tar infinity-for-reddit-efcfa0ae71c90796b1995737d4feac46fe3542b1.tar.gz infinity-for-reddit-efcfa0ae71c90796b1995737d4feac46fe3542b1.tar.bz2 infinity-for-reddit-efcfa0ae71c90796b1995737d4feac46fe3542b1.tar.lz infinity-for-reddit-efcfa0ae71c90796b1995737d4feac46fe3542b1.tar.xz infinity-for-reddit-efcfa0ae71c90796b1995737d4feac46fe3542b1.tar.zst infinity-for-reddit-efcfa0ae71c90796b1995737d4feac46fe3542b1.zip |
Fix https://github.com/Docile-Alligator/Infinity-For-Reddit/issues/1367
Diffstat (limited to '')
-rw-r--r-- | app/src/main/java/ml/docilealligator/infinityforreddit/markdown/SuperscriptPlugin.java | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/SuperscriptPlugin.java b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/SuperscriptPlugin.java index 1a5f3526..796ca870 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/SuperscriptPlugin.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/SuperscriptPlugin.java @@ -7,8 +7,10 @@ import android.widget.TextView; import androidx.annotation.NonNull; import org.commonmark.ext.gfm.tables.TableCell; +import org.commonmark.node.Link; import org.commonmark.node.Node; import org.commonmark.node.Paragraph; +import org.commonmark.node.Text; import java.util.ArrayList; import java.util.List; @@ -95,6 +97,10 @@ public class SuperscriptPlugin extends AbstractMarkwonPlugin { public void visit(@NonNull MarkwonVisitor visitor, @NonNull Superscript superscript) { int start = visitor.length(); + if (!notEmptySuperscript(superscript)) { + return; + } + if (!superscript.isBracketed()) { visitor.builder().setSpan(new SuperscriptSpan(false), start, start + 1); // Workaround for Table Plugin superscriptOpeningList.add(new SuperscriptOpening(superscript, start)); @@ -123,6 +129,54 @@ public class SuperscriptPlugin extends AbstractMarkwonPlugin { }); } + private boolean notEmptyLink(Link link) { + Node next = link.getFirstChild(); + while (next != null) { + if (next instanceof Text) { + return true; + } else if (next instanceof Superscript) { + if (notEmptySuperscript((Superscript) next)) { + return true; + } + } else if (next instanceof Link) { + if (notEmptyLink((Link) next)) { + return true; + } + } else { + return true; + } + next = next.getNext(); + } + + return false; + } + + private boolean notEmptySuperscript(Superscript superscript) { + Node next; + if (superscript.isBracketed()) { + next = superscript.getFirstChild(); + } else { + next = superscript.getNext(); + } + + while (next != null) { + if (next instanceof Link) { + if (notEmptyLink((Link) next)) { + return true; + } + } else if (!(next instanceof Superscript)) { + return true; + } else { + if (notEmptySuperscript((Superscript) next)) { + return true; + } + } + next = next.getNext(); + } + + return false; + } + @Override public void afterRender(@NonNull Node node, @NonNull MarkwonVisitor visitor) { superscriptOpeningBracketStorage.clear(); |