aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDocile-Alligator <25734209+Docile-Alligator@users.noreply.github.com>2024-03-08 22:46:46 +0000
committerDocile-Alligator <25734209+Docile-Alligator@users.noreply.github.com>2024-03-08 22:46:46 +0000
commit8ca2efa24445f8f1533f37b3e21afd3ea6218ccf (patch)
treee15f86fc77c2f43ecc79bc637fff3b386b9310ea
parent1a4a15d4572c0c0fa7144dba8a6df01b08b0a841 (diff)
downloadinfinity-for-reddit-8ca2efa24445f8f1533f37b3e21afd3ea6218ccf.tar
infinity-for-reddit-8ca2efa24445f8f1533f37b3e21afd3ea6218ccf.tar.gz
infinity-for-reddit-8ca2efa24445f8f1533f37b3e21afd3ea6218ccf.tar.bz2
infinity-for-reddit-8ca2efa24445f8f1533f37b3e21afd3ea6218ccf.tar.lz
infinity-for-reddit-8ca2efa24445f8f1533f37b3e21afd3ea6218ccf.tar.xz
infinity-for-reddit-8ca2efa24445f8f1533f37b3e21afd3ea6218ccf.tar.zst
infinity-for-reddit-8ca2efa24445f8f1533f37b3e21afd3ea6218ccf.zip
Superscript richtext_json. Still some issues though.
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/markdown/RichTextJSONConverter.java52
1 files changed, 39 insertions, 13 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/RichTextJSONConverter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/RichTextJSONConverter.java
index 13cec317..199e6f94 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/RichTextJSONConverter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/RichTextJSONConverter.java
@@ -123,6 +123,32 @@ public class RichTextJSONConverter implements Visitor {
return null;
}
+ @Nullable
+ private JSONArray getChildFormatArray(Node node) {
+ int formatNum = 0;
+ while (node != null && node.getFirstChild() != null) {
+ String className = node.getClass().getName();
+ if (formatMap.containsKey(className)) {
+ formatNum += formatMap.get(className);
+ node = node.getFirstChild();
+ }
+ }
+
+ if (node instanceof Text) {
+ int start = textSB.length();
+ textSB.append(((Text) node).getLiteral());
+ if (formatNum > 0) {
+ JSONArray format = new JSONArray();
+ format.put(formatNum);
+ format.put(start);
+ format.put(((Text) node).getLiteral().length());
+ return format;
+ }
+ }
+
+ return null;
+ }
+
@Override
public void visit(BlockQuote blockQuote) {
@@ -326,20 +352,20 @@ public class RichTextJSONConverter implements Visitor {
@Override
public void visit(CustomNode customNode) {
+ /*
+ Superscript can still has inline spans, thus checking children's next node until the end.
+ Superscript must use ^(), not ^ right now.
+ */
+ Node child = customNode.getFirstChild();
+ while (child != null) {
+ JSONArray format = getFormatArray(customNode);
+ if (format != null) {
+ formats.add(format);
+ }
- }
-
- public void visit(Strikethrough strikethrough) {
- JSONArray format = getFormatArray(strikethrough);
- if (format != null) {
- formats.add(format);
- }
- }
-
- public void visit(Superscript superscript) {
- JSONArray format = getFormatArray(superscript);
- if (format != null) {
- formats.add(format);
+ Node next = child.getNext();
+ child.unlink();
+ child = next;
}
}
}