From 1960bb5ea14c153b688a5f0fedb8c05998af2bd7 Mon Sep 17 00:00:00 2001 From: scria1000 <91804886+scria1000@users.noreply.github.com> Date: Fri, 12 Nov 2021 01:51:54 +0300 Subject: [PATCH] Add custom superscript processor --- app/build.gradle | 1 + .../activities/CommentActivity.java | 14 ++++++ .../activities/FullMarkdownActivity.java | 12 ++++- .../activities/WikiActivity.java | 12 ++++- .../CommentsListingRecyclerViewAdapter.java | 12 ++++- .../adapters/CommentsRecyclerViewAdapter.java | 15 +++++- .../adapters/MessageRecyclerViewAdapter.java | 11 +++++ .../PostDetailRecyclerViewAdapter.java | 12 ++++- ...vateMessagesDetailRecyclerViewAdapter.java | 9 ++++ .../adapters/RulesRecyclerViewAdapter.java | 9 ++++ .../CopyTextBottomSheetFragment.java | 4 +- .../fragments/SidebarFragment.java | 9 ++++ .../utils/ProcessRedditSuperscript.java | 46 +++++++++++++++++++ .../utils/SuperscriptInlineProcessor.java | 32 +++++++++++++ .../infinityforreddit/utils/Utils.java | 5 +- 15 files changed, 196 insertions(+), 7 deletions(-) create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/utils/ProcessRedditSuperscript.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/utils/SuperscriptInlineProcessor.java diff --git a/app/build.gradle b/app/build.gradle index 10429eeb..9026ab5c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -153,6 +153,7 @@ dependencies { implementation "io.noties.markwon:linkify:$markwonVersion" implementation "io.noties.markwon:recycler-table:$markwonVersion" implementation "io.noties.markwon:simple-ext:$markwonVersion" + implementation "io.noties.markwon:html:$markwonVersion" implementation "io.noties.markwon:inline-parser:$markwonVersion" implementation 'com.atlassian.commonmark:commonmark-ext-gfm-tables:0.14.0' implementation 'me.saket:better-link-movement-method:2.2.0' diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java index db2353dc..2ffa10e7 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java @@ -50,6 +50,8 @@ import io.noties.markwon.Markwon; import io.noties.markwon.MarkwonConfiguration; import io.noties.markwon.core.MarkwonTheme; import io.noties.markwon.ext.strikethrough.StrikethroughPlugin; +import io.noties.markwon.html.HtmlPlugin; +import io.noties.markwon.html.tag.SuperScriptHandler; import io.noties.markwon.inlineparser.HtmlInlineProcessor; import io.noties.markwon.inlineparser.MarkwonInlineParserPlugin; import io.noties.markwon.linkify.LinkifyPlugin; @@ -68,7 +70,9 @@ import ml.docilealligator.infinityforreddit.comment.SendComment; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed; import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent; +import ml.docilealligator.infinityforreddit.utils.ProcessRedditSuperscript; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; +import ml.docilealligator.infinityforreddit.utils.SuperscriptInlineProcessor; import ml.docilealligator.infinityforreddit.utils.Utils; import retrofit2.Retrofit; @@ -163,7 +167,12 @@ public class CommentActivity extends BaseActivity implements UploadImageEnabledA Markwon markwon = Markwon.builder(this) .usePlugin(MarkwonInlineParserPlugin.create(plugin -> { plugin.excludeInlineProcessor(HtmlInlineProcessor.class); + plugin.addInlineProcessor(new SuperscriptInlineProcessor()); })) + .usePlugin(HtmlPlugin.create(plugin -> { + plugin.excludeDefaults(true).addHandler(new SuperScriptHandler()); + })) + .usePlugin(new ProcessRedditSuperscript()) .usePlugin(new AbstractMarkwonPlugin() { @Override public void configureConfiguration(@NonNull MarkwonConfiguration.Builder builder) { @@ -206,7 +215,12 @@ public class CommentActivity extends BaseActivity implements UploadImageEnabledA Markwon postBodyMarkwon = Markwon.builder(this) .usePlugin(MarkwonInlineParserPlugin.create(plugin -> { plugin.excludeInlineProcessor(HtmlInlineProcessor.class); + plugin.addInlineProcessor(new SuperscriptInlineProcessor()); })) + .usePlugin(HtmlPlugin.create(plugin -> { + plugin.excludeDefaults(true).addHandler(new SuperScriptHandler()); + })) + .usePlugin(new ProcessRedditSuperscript()) .usePlugin(new AbstractMarkwonPlugin() { @Override public void beforeSetText(@NonNull TextView textView, @NonNull Spanned markdown) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FullMarkdownActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FullMarkdownActivity.java index 7a54b5d1..92bd1ec8 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FullMarkdownActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FullMarkdownActivity.java @@ -47,6 +47,8 @@ import io.noties.markwon.Markwon; import io.noties.markwon.MarkwonConfiguration; import io.noties.markwon.core.MarkwonTheme; import io.noties.markwon.ext.strikethrough.StrikethroughPlugin; +import io.noties.markwon.html.HtmlPlugin; +import io.noties.markwon.html.tag.SuperScriptHandler; import io.noties.markwon.inlineparser.HtmlInlineProcessor; import io.noties.markwon.inlineparser.MarkwonInlineParserPlugin; import io.noties.markwon.linkify.LinkifyPlugin; @@ -59,7 +61,9 @@ import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed; import ml.docilealligator.infinityforreddit.customviews.MarkwonLinearLayoutManager; import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent; +import ml.docilealligator.infinityforreddit.utils.ProcessRedditSuperscript; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; +import ml.docilealligator.infinityforreddit.utils.SuperscriptInlineProcessor; public class FullMarkdownActivity extends BaseActivity { @@ -134,8 +138,14 @@ public class FullMarkdownActivity extends BaseActivity { Markwon markwon = Markwon.builder(this) .usePlugin(MarkwonInlineParserPlugin.create(plugin -> { plugin.excludeInlineProcessor(HtmlInlineProcessor.class); + plugin.addInlineProcessor(new SuperscriptInlineProcessor()); })) + .usePlugin(HtmlPlugin.create(plugin -> { + plugin.excludeDefaults(true).addHandler(new SuperScriptHandler()); + })) + .usePlugin(new ProcessRedditSuperscript()) .usePlugin(new AbstractMarkwonPlugin() { + /* @NonNull @Override public String processMarkdown(@NonNull String markdown) { @@ -151,7 +161,7 @@ public class FullMarkdownActivity extends BaseActivity { } return super.processMarkdown(markdownStringBuilder.toString()); } - + */ @Override public void afterSetText(@NonNull TextView textView) { textView.setHighlightColor(Color.TRANSPARENT); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WikiActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WikiActivity.java index d5c8cb61..644ac4b5 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WikiActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WikiActivity.java @@ -51,6 +51,8 @@ import io.noties.markwon.Markwon; import io.noties.markwon.MarkwonConfiguration; import io.noties.markwon.core.MarkwonTheme; import io.noties.markwon.ext.strikethrough.StrikethroughPlugin; +import io.noties.markwon.html.HtmlPlugin; +import io.noties.markwon.html.tag.SuperScriptHandler; import io.noties.markwon.inlineparser.HtmlInlineProcessor; import io.noties.markwon.inlineparser.MarkwonInlineParserPlugin; import io.noties.markwon.linkify.LinkifyPlugin; @@ -65,7 +67,9 @@ import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFi import ml.docilealligator.infinityforreddit.customviews.MarkwonLinearLayoutManager; import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent; import ml.docilealligator.infinityforreddit.utils.JSONUtils; +import ml.docilealligator.infinityforreddit.utils.ProcessRedditSuperscript; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; +import ml.docilealligator.infinityforreddit.utils.SuperscriptInlineProcessor; import retrofit2.Call; import retrofit2.Callback; import retrofit2.Response; @@ -159,8 +163,14 @@ public class WikiActivity extends BaseActivity { markwon = Markwon.builder(this) .usePlugin(MarkwonInlineParserPlugin.create(plugin -> { plugin.excludeInlineProcessor(HtmlInlineProcessor.class); + plugin.addInlineProcessor(new SuperscriptInlineProcessor()); })) + .usePlugin(HtmlPlugin.create(plugin -> { + plugin.excludeDefaults(true).addHandler(new SuperScriptHandler()); + })) + .usePlugin(new ProcessRedditSuperscript()) .usePlugin(new AbstractMarkwonPlugin() { + /* @NonNull @Override public String processMarkdown(@NonNull String markdown) { @@ -176,7 +186,7 @@ public class WikiActivity extends BaseActivity { } return super.processMarkdown(markdownStringBuilder.toString()); } - + */ @Override public void afterSetText(@NonNull TextView textView) { textView.setHighlightColor(Color.TRANSPARENT); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java index cc0e640d..1a3fb7ac 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java @@ -42,6 +42,8 @@ import io.noties.markwon.Markwon; import io.noties.markwon.MarkwonConfiguration; import io.noties.markwon.core.MarkwonTheme; import io.noties.markwon.ext.strikethrough.StrikethroughPlugin; +import io.noties.markwon.html.HtmlPlugin; +import io.noties.markwon.html.tag.SuperScriptHandler; import io.noties.markwon.inlineparser.HtmlInlineProcessor; import io.noties.markwon.inlineparser.MarkwonInlineParserPlugin; import io.noties.markwon.linkify.LinkifyPlugin; @@ -61,7 +63,9 @@ import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.customviews.CommentIndentationView; import ml.docilealligator.infinityforreddit.customviews.SpoilerOnClickTextView; import ml.docilealligator.infinityforreddit.utils.APIUtils; +import ml.docilealligator.infinityforreddit.utils.ProcessRedditSuperscript; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; +import ml.docilealligator.infinityforreddit.utils.SuperscriptInlineProcessor; import ml.docilealligator.infinityforreddit.utils.Utils; import retrofit2.Retrofit; @@ -119,8 +123,14 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter { plugin.excludeInlineProcessor(HtmlInlineProcessor.class); + plugin.addInlineProcessor(new SuperscriptInlineProcessor()); })) + .usePlugin(HtmlPlugin.create(plugin -> { + plugin.excludeDefaults(true).addHandler(new SuperScriptHandler()); + })) + .usePlugin(new ProcessRedditSuperscript()) .usePlugin(new AbstractMarkwonPlugin() { + /* @NonNull @Override public String processMarkdown(@NonNull String markdown) { @@ -136,7 +146,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter { plugin.excludeInlineProcessor(HtmlInlineProcessor.class); + plugin.addInlineProcessor(new SuperscriptInlineProcessor()); })) + .usePlugin(HtmlPlugin.create(plugin -> { + plugin.excludeDefaults(true).addHandler(new SuperScriptHandler()); + })) + .usePlugin(new ProcessRedditSuperscript()) .usePlugin(new AbstractMarkwonPlugin() { + /* @NonNull @Override public String processMarkdown(@NonNull String markdown) { @@ -180,7 +193,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter { @@ -102,8 +106,14 @@ public class MessageRecyclerViewAdapter extends PagedListAdapter { plugin.excludeInlineProcessor(HtmlInlineProcessor.class); + plugin.addInlineProcessor(new SuperscriptInlineProcessor()); })) + .usePlugin(HtmlPlugin.create(plugin -> { + plugin.excludeDefaults(true).addHandler(new SuperScriptHandler()); + })) + .usePlugin(new ProcessRedditSuperscript()) .usePlugin(new AbstractMarkwonPlugin() { + /* @NonNull @Override public String processMarkdown(@NonNull String markdown) { @@ -119,6 +129,7 @@ public class MessageRecyclerViewAdapter extends PagedListAdapter { plugin.excludeInlineProcessor(HtmlInlineProcessor.class); + plugin.addInlineProcessor(new SuperscriptInlineProcessor()); })) + .usePlugin(HtmlPlugin.create(plugin -> { + plugin.excludeDefaults(true).addHandler(new SuperScriptHandler()); + })) + .usePlugin(new ProcessRedditSuperscript()) .usePlugin(new AbstractMarkwonPlugin() { + /* @NonNull @Override public String processMarkdown(@NonNull String markdown) { @@ -246,7 +256,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter { @@ -69,7 +73,12 @@ public class PrivateMessagesDetailRecyclerViewAdapter extends RecyclerView.Adapt mMarkwon = Markwon.builder(viewPrivateMessagesActivity) .usePlugin(MarkwonInlineParserPlugin.create(plugin -> { plugin.excludeInlineProcessor(HtmlInlineProcessor.class); + plugin.addInlineProcessor(new SuperscriptInlineProcessor()); })) + .usePlugin(HtmlPlugin.create(plugin -> { + plugin.excludeDefaults(true).addHandler(new SuperScriptHandler()); + })) + .usePlugin(new ProcessRedditSuperscript()) .usePlugin(new AbstractMarkwonPlugin() { @Override public void configureConfiguration(@NonNull MarkwonConfiguration.Builder builder) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RulesRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RulesRecyclerViewAdapter.java index 6cf4ee07..4eb9d5d8 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RulesRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RulesRecyclerViewAdapter.java @@ -22,6 +22,8 @@ import io.noties.markwon.Markwon; import io.noties.markwon.MarkwonConfiguration; import io.noties.markwon.core.MarkwonTheme; import io.noties.markwon.ext.strikethrough.StrikethroughPlugin; +import io.noties.markwon.html.HtmlPlugin; +import io.noties.markwon.html.tag.SuperScriptHandler; import io.noties.markwon.inlineparser.HtmlInlineProcessor; import io.noties.markwon.inlineparser.MarkwonInlineParserPlugin; import io.noties.markwon.linkify.LinkifyPlugin; @@ -32,6 +34,8 @@ import ml.docilealligator.infinityforreddit.Rule; import ml.docilealligator.infinityforreddit.activities.LinkResolverActivity; import ml.docilealligator.infinityforreddit.bottomsheetfragments.UrlMenuBottomSheetFragment; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; +import ml.docilealligator.infinityforreddit.utils.ProcessRedditSuperscript; +import ml.docilealligator.infinityforreddit.utils.SuperscriptInlineProcessor; public class RulesRecyclerViewAdapter extends RecyclerView.Adapter { private Markwon markwon; @@ -43,7 +47,12 @@ public class RulesRecyclerViewAdapter extends RecyclerView.Adapter { plugin.excludeInlineProcessor(HtmlInlineProcessor.class); + plugin.addInlineProcessor(new SuperscriptInlineProcessor()); })) + .usePlugin(HtmlPlugin.create(plugin -> { + plugin.excludeDefaults(true).addHandler(new SuperScriptHandler()); + })) + .usePlugin(new ProcessRedditSuperscript()) .usePlugin(new AbstractMarkwonPlugin() { @Override public void configureConfiguration(@NonNull MarkwonConfiguration.Builder builder) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/CopyTextBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/CopyTextBottomSheetFragment.java index d8cf1fe9..4264f36a 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/CopyTextBottomSheetFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/CopyTextBottomSheetFragment.java @@ -6,6 +6,7 @@ import android.content.ClipData; import android.content.ClipboardManager; import android.content.Context; import android.os.Bundle; +import android.text.Html; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -72,7 +73,8 @@ public class CopyTextBottomSheetFragment extends LandscapeExpandedRoundedBottomS } if (markdownText != null) { - markdownText = markdownText.replaceAll("", "^").replaceAll("", ""); + //markdownText = markdownText.replaceAll("", "^").replaceAll("", ""); + markdownText = markdownText.replaceAll(">", ">"); copyMarkdownTextView.setOnClickListener(view -> { showCopyDialog(markdownText); dismiss(); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SidebarFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SidebarFragment.java index f02db229..416b3046 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SidebarFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SidebarFragment.java @@ -34,6 +34,8 @@ import io.noties.markwon.Markwon; import io.noties.markwon.MarkwonConfiguration; import io.noties.markwon.core.MarkwonTheme; import io.noties.markwon.ext.strikethrough.StrikethroughPlugin; +import io.noties.markwon.html.HtmlPlugin; +import io.noties.markwon.html.tag.SuperScriptHandler; import io.noties.markwon.inlineparser.HtmlInlineProcessor; import io.noties.markwon.inlineparser.MarkwonInlineParserPlugin; import io.noties.markwon.linkify.LinkifyPlugin; @@ -55,6 +57,8 @@ import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFi import ml.docilealligator.infinityforreddit.subreddit.FetchSubredditData; import ml.docilealligator.infinityforreddit.subreddit.SubredditData; import ml.docilealligator.infinityforreddit.subreddit.SubredditViewModel; +import ml.docilealligator.infinityforreddit.utils.ProcessRedditSuperscript; +import ml.docilealligator.infinityforreddit.utils.SuperscriptInlineProcessor; import retrofit2.Retrofit; public class SidebarFragment extends Fragment { @@ -107,7 +111,12 @@ public class SidebarFragment extends Fragment { Markwon markwon = Markwon.builder(activity) .usePlugin(MarkwonInlineParserPlugin.create(plugin -> { plugin.excludeInlineProcessor(HtmlInlineProcessor.class); + plugin.addInlineProcessor(new SuperscriptInlineProcessor()); })) + .usePlugin(HtmlPlugin.create(plugin -> { + plugin.excludeDefaults(true).addHandler(new SuperScriptHandler()); + })) + .usePlugin(new ProcessRedditSuperscript()) .usePlugin(new AbstractMarkwonPlugin() { @Override public void beforeSetText(@NonNull TextView textView, @NonNull Spanned markdown) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/ProcessRedditSuperscript.java b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/ProcessRedditSuperscript.java new file mode 100644 index 00000000..0dc539d7 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/ProcessRedditSuperscript.java @@ -0,0 +1,46 @@ +package ml.docilealligator.infinityforreddit.utils; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import io.noties.markwon.AbstractMarkwonPlugin; + +public class ProcessRedditSuperscript extends AbstractMarkwonPlugin { + private static final Pattern re = Pattern.compile("(?:\\^\\((.+?)\\))|(?:\\^(\\S+))"); + + @Override + public String processMarkdown(String markdown) { + StringBuilder builder = new StringBuilder(); + Matcher matcher = re.matcher(markdown); + int start = 0; + + while (matcher.find()) { + try { + String match; + if ((match = matcher.group(1)) != null || (match = matcher.group(2)) != null) { + builder.append(markdown.substring(start, matcher.start())) + .append("") + .append(match) + .append(""); + start = matcher.end(); + } else { + throw new NullPointerException(); + } + } catch(NullPointerException e) { + e.printStackTrace(); + } finally { + continue; + } + } + + if (start < markdown.length()) { + builder.append(markdown.substring(start)); + } + + if(builder.length() > 0) { + return builder.toString(); } + else { + return markdown; + } + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SuperscriptInlineProcessor.java b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SuperscriptInlineProcessor.java new file mode 100644 index 00000000..136a69d4 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SuperscriptInlineProcessor.java @@ -0,0 +1,32 @@ +package ml.docilealligator.infinityforreddit.utils; + +import androidx.annotation.Nullable; + +import org.commonmark.node.HtmlInline; +import org.commonmark.node.Node; + +import java.util.regex.Pattern; + +import io.noties.markwon.inlineparser.InlineProcessor; + +public class SuperscriptInlineProcessor extends InlineProcessor { + private static final Pattern HTML_TAG = Pattern.compile("", Pattern.CASE_INSENSITIVE); + + @Override + public char specialCharacter() { + return '<'; + } + + @Nullable + @Override + protected Node parse() { + String m = match(HTML_TAG); + if (m != null) { + HtmlInline node = new HtmlInline(); + node.setLiteral(m); + return node; + } else { + return null; + } + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java index ad2b7405..16aeb642 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java @@ -65,6 +65,8 @@ public class Utils { .replaceAll("((?<=[\\s])|^)/[rRuU]/[\\w-]+/{0,1}", "[$0](https://www.reddit.com$0)") .replaceAll("((?<=[\\s])|^)[rRuU]/[\\w-]+/{0,1}", "[$0](https://www.reddit.com/$0)") .replaceAll("\\^{2,}", "^") + .replaceAll("(", "$1>") + .replaceAll(">!", ">!") .replaceAll("(^|^ *|\\n *)#(?!($|\\s|#))", "$0 ") .replaceAll("(^|^ *|\\n *)##(?!($|\\s|#))", "$0 ") .replaceAll("(^|^ *|\\n *)###(?!($|\\s|#))", "$0 ") @@ -72,7 +74,8 @@ public class Utils { .replaceAll("(^|^ *|\\n *)#####(?!($|\\s|#))", "$0 ") .replaceAll("(^|^ *|\\n *)######(?!($|\\s|#))", "$0 ")); - return fixSuperScript(regexed); + //return fixSuperScript(regexed); + return regexed.toString(); } private static String fixSuperScript(StringBuilder regexed) {