Docile-Alligator 2023-02-20 21:36:38 -05:00
parent 9db90a0431
commit efcfa0ae71

View File

@ -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();