aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDocile-Alligator <25734209+Docile-Alligator@users.noreply.github.com>2024-03-09 23:10:34 +0000
committerDocile-Alligator <25734209+Docile-Alligator@users.noreply.github.com>2024-03-09 23:10:34 +0000
commitec380b2c079cc9df76284b4a5a876fa2b010b961 (patch)
tree93900271736aa54f3a41b794f95712d55184fb71
parent9afcb05eb534595d30791fce21e3b865a4beda8c (diff)
downloadinfinity-for-reddit-ec380b2c079cc9df76284b4a5a876fa2b010b961.tar
infinity-for-reddit-ec380b2c079cc9df76284b4a5a876fa2b010b961.tar.gz
infinity-for-reddit-ec380b2c079cc9df76284b4a5a876fa2b010b961.tar.bz2
infinity-for-reddit-ec380b2c079cc9df76284b4a5a876fa2b010b961.tar.lz
infinity-for-reddit-ec380b2c079cc9df76284b4a5a876fa2b010b961.tar.xz
infinity-for-reddit-ec380b2c079cc9df76284b4a5a876fa2b010b961.tar.zst
infinity-for-reddit-ec380b2c079cc9df76284b4a5a876fa2b010b961.zip
FencedCodeBlock and IndentedCodeBlock richtext_json.
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/markdown/RichTextJSONConverter.java42
1 files changed, 40 insertions, 2 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 5b9fa29d..71e9f416 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/RichTextJSONConverter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/RichTextJSONConverter.java
@@ -208,7 +208,26 @@ public class RichTextJSONConverter implements Visitor {
@Override
public void visit(FencedCodeBlock fencedCodeBlock) {
+ try {
+ JSONObject nodeJSON = new JSONObject();
+ nodeJSON.put(TYPE, CODE_BLOCK_E);
+
+ JSONArray cArray = new JSONArray();
+ String codeLiteral = fencedCodeBlock.getLiteral();
+ String[] codeLines = codeLiteral.split("\n");
+ for (String c : codeLines) {
+ JSONObject contentJSONObject = new JSONObject();
+ contentJSONObject.put(TYPE, RAW_E);
+ contentJSONObject.put(TEXT, c);
+ cArray.put(contentJSONObject);
+ }
+
+ nodeJSON.put(CONTENT, cArray);
+ contentArrayStack.peek().put(nodeJSON);
+ } catch (JSONException e) {
+ throw new RuntimeException(e);
+ }
}
@Override
@@ -259,12 +278,12 @@ public class RichTextJSONConverter implements Visitor {
@Override
public void visit(HtmlInline htmlInline) {
-
+ //Not supported by Reddit
}
@Override
public void visit(HtmlBlock htmlBlock) {
-
+ //Not supported by Reddit
}
@Override
@@ -274,7 +293,26 @@ public class RichTextJSONConverter implements Visitor {
@Override
public void visit(IndentedCodeBlock indentedCodeBlock) {
+ try {
+ JSONObject nodeJSON = new JSONObject();
+ nodeJSON.put(TYPE, CODE_BLOCK_E);
+
+ JSONArray cArray = new JSONArray();
+ String codeLiteral = indentedCodeBlock.getLiteral();
+
+ String[] codeLines = codeLiteral.split("\n");
+ for (String c : codeLines) {
+ JSONObject contentJSONObject = new JSONObject();
+ contentJSONObject.put(TYPE, RAW_E);
+ contentJSONObject.put(TEXT, c);
+ cArray.put(contentJSONObject);
+ }
+ nodeJSON.put(CONTENT, cArray);
+ contentArrayStack.peek().put(nodeJSON);
+ } catch (JSONException e) {
+ throw new RuntimeException(e);
+ }
}
@Override