From ec380b2c079cc9df76284b4a5a876fa2b010b961 Mon Sep 17 00:00:00 2001 From: Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> Date: Sat, 9 Mar 2024 18:10:34 -0500 Subject: FencedCodeBlock and IndentedCodeBlock richtext_json. --- .../markdown/RichTextJSONConverter.java | 42 ++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) (limited to 'app/src/main') 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 -- cgit v1.2.3