From 2cdf523eff80d4cee7bab64fbdd6c1e34908207d Mon Sep 17 00:00:00 2001 From: scria1000 <91804886+scria1000@users.noreply.github.com> Date: Thu, 11 Nov 2021 18:41:24 +0300 Subject: More fixes related to markdown rendering --- .../infinityforreddit/activities/CommentActivity.java | 11 ++++++++--- .../infinityforreddit/activities/FullMarkdownActivity.java | 9 ++++++--- .../activities/ViewSubredditDetailActivity.java | 5 +++++ .../infinityforreddit/activities/ViewUserDetailActivity.java | 5 +++++ .../infinityforreddit/activities/WikiActivity.java | 9 ++++++--- .../adapters/CommentsListingRecyclerViewAdapter.java | 7 +++++-- .../adapters/CommentsRecyclerViewAdapter.java | 7 +++++-- .../adapters/MessageRecyclerViewAdapter.java | 9 ++++++--- .../adapters/PostDetailRecyclerViewAdapter.java | 9 ++++++--- .../adapters/PrivateMessagesDetailRecyclerViewAdapter.java | 7 +++++-- .../infinityforreddit/adapters/RulesRecyclerViewAdapter.java | 7 +++++-- .../infinityforreddit/fragments/SidebarFragment.java | 7 +++++-- 12 files changed, 67 insertions(+), 25 deletions(-) (limited to 'app/src/main/java/ml') 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 1f85f362..db2353dc 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java @@ -50,7 +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.inlineparser.HtmlInlineProcessor; +import io.noties.markwon.inlineparser.MarkwonInlineParserPlugin; import io.noties.markwon.linkify.LinkifyPlugin; import io.noties.markwon.recycler.MarkwonAdapter; import io.noties.markwon.recycler.table.TableEntry; @@ -160,7 +161,9 @@ public class CommentActivity extends BaseActivity implements UploadImageEnabledA int linkColor = mCustomThemeWrapper.getLinkColor(); Markwon markwon = Markwon.builder(this) - .usePlugin(HtmlPlugin.create()) + .usePlugin(MarkwonInlineParserPlugin.create(plugin -> { + plugin.excludeInlineProcessor(HtmlInlineProcessor.class); + })) .usePlugin(new AbstractMarkwonPlugin() { @Override public void configureConfiguration(@NonNull MarkwonConfiguration.Builder builder) { @@ -201,7 +204,9 @@ public class CommentActivity extends BaseActivity implements UploadImageEnabledA contentMarkdownRecyclerView.setVisibility(View.VISIBLE); contentMarkdownRecyclerView.setNestedScrollingEnabled(false); Markwon postBodyMarkwon = Markwon.builder(this) - .usePlugin(HtmlPlugin.create()) + .usePlugin(MarkwonInlineParserPlugin.create(plugin -> { + plugin.excludeInlineProcessor(HtmlInlineProcessor.class); + })) .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 60406d70..7a54b5d1 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FullMarkdownActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FullMarkdownActivity.java @@ -47,7 +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.inlineparser.HtmlInlineProcessor; +import io.noties.markwon.inlineparser.MarkwonInlineParserPlugin; import io.noties.markwon.linkify.LinkifyPlugin; import io.noties.markwon.recycler.MarkwonAdapter; import io.noties.markwon.recycler.table.TableEntry; @@ -131,7 +132,9 @@ public class FullMarkdownActivity extends BaseActivity { int spoilerBackgroundColor = markdownColor | 0xFF000000; int linkColor = mCustomThemeWrapper.getLinkColor(); Markwon markwon = Markwon.builder(this) - .usePlugin(HtmlPlugin.create()) + .usePlugin(MarkwonInlineParserPlugin.create(plugin -> { + plugin.excludeInlineProcessor(HtmlInlineProcessor.class); + })) .usePlugin(new AbstractMarkwonPlugin() { @NonNull @Override @@ -152,7 +155,7 @@ public class FullMarkdownActivity extends BaseActivity { @Override public void afterSetText(@NonNull TextView textView) { textView.setHighlightColor(Color.TRANSPARENT); - SpannableStringBuilder markdownStringBuilder = new SpannableStringBuilder(textView.getText().toString()); + SpannableStringBuilder markdownStringBuilder = new SpannableStringBuilder(textView.getText()); Pattern spoilerPattern = Pattern.compile(">![\\S\\s]+?!<"); Matcher matcher = spoilerPattern.matcher(markdownStringBuilder); int start = 0; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java index 2f534fb0..368e2b46 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java @@ -71,6 +71,8 @@ import io.noties.markwon.AbstractMarkwonPlugin; import io.noties.markwon.Markwon; import io.noties.markwon.MarkwonConfiguration; import io.noties.markwon.core.MarkwonTheme; +import io.noties.markwon.inlineparser.HtmlInlineProcessor; +import io.noties.markwon.inlineparser.MarkwonInlineParserPlugin; import io.noties.markwon.linkify.LinkifyPlugin; import io.noties.markwon.movement.MovementMethodPlugin; import jp.wasabeef.glide.transformations.RoundedCornersTransformation; @@ -380,6 +382,9 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp Locale locale = getResources().getConfiguration().locale; Markwon markwon = Markwon.builder(this) + .usePlugin(MarkwonInlineParserPlugin.create(plugin -> { + plugin.excludeInlineProcessor(HtmlInlineProcessor.class); + })) .usePlugin(new AbstractMarkwonPlugin() { @Override public void configureConfiguration(@NonNull MarkwonConfiguration.Builder builder) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java index d12290ee..7ef81969 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java @@ -73,6 +73,8 @@ import io.noties.markwon.AbstractMarkwonPlugin; import io.noties.markwon.Markwon; import io.noties.markwon.MarkwonConfiguration; import io.noties.markwon.core.MarkwonTheme; +import io.noties.markwon.inlineparser.HtmlInlineProcessor; +import io.noties.markwon.inlineparser.MarkwonInlineParserPlugin; import io.noties.markwon.linkify.LinkifyPlugin; import io.noties.markwon.movement.MovementMethodPlugin; import jp.wasabeef.glide.transformations.RoundedCornersTransformation; @@ -376,6 +378,9 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele Locale locale = getResources().getConfiguration().locale; Markwon markwon = Markwon.builder(this) + .usePlugin(MarkwonInlineParserPlugin.create(plugin -> { + plugin.excludeInlineProcessor(HtmlInlineProcessor.class); + })) .usePlugin(new AbstractMarkwonPlugin() { @Override public void configureConfiguration(@NonNull MarkwonConfiguration.Builder builder) { 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 63b147fb..d5c8cb61 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WikiActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WikiActivity.java @@ -51,7 +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.inlineparser.HtmlInlineProcessor; +import io.noties.markwon.inlineparser.MarkwonInlineParserPlugin; import io.noties.markwon.linkify.LinkifyPlugin; import io.noties.markwon.recycler.MarkwonAdapter; import io.noties.markwon.recycler.table.TableEntry; @@ -156,7 +157,9 @@ public class WikiActivity extends BaseActivity { int spoilerBackgroundColor = markdownColor | 0xFF000000; int linkColor = mCustomThemeWrapper.getLinkColor(); markwon = Markwon.builder(this) - .usePlugin(HtmlPlugin.create()) + .usePlugin(MarkwonInlineParserPlugin.create(plugin -> { + plugin.excludeInlineProcessor(HtmlInlineProcessor.class); + })) .usePlugin(new AbstractMarkwonPlugin() { @NonNull @Override @@ -177,7 +180,7 @@ public class WikiActivity extends BaseActivity { @Override public void afterSetText(@NonNull TextView textView) { textView.setHighlightColor(Color.TRANSPARENT); - SpannableStringBuilder markdownStringBuilder = new SpannableStringBuilder(textView.getText().toString()); + SpannableStringBuilder markdownStringBuilder = new SpannableStringBuilder(textView.getText()); Pattern spoilerPattern = Pattern.compile(">![\\S\\s]+?!<"); Matcher matcher = spoilerPattern.matcher(markdownStringBuilder); int start = 0; 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 e298734c..cc0e640d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java @@ -42,7 +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.inlineparser.HtmlInlineProcessor; +import io.noties.markwon.inlineparser.MarkwonInlineParserPlugin; import io.noties.markwon.linkify.LinkifyPlugin; import me.saket.bettermovementmethod.BetterLinkMovementMethod; import ml.docilealligator.infinityforreddit.NetworkState; @@ -116,7 +117,9 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter { + plugin.excludeInlineProcessor(HtmlInlineProcessor.class); + })) .usePlugin(new AbstractMarkwonPlugin() { @NonNull @Override diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java index b9d6bfd0..a06b476d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java @@ -47,7 +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.inlineparser.HtmlInlineProcessor; +import io.noties.markwon.inlineparser.MarkwonInlineParserPlugin; import io.noties.markwon.linkify.LinkifyPlugin; import io.noties.markwon.movement.MovementMethodPlugin; import me.saket.bettermovementmethod.BetterLinkMovementMethod; @@ -160,7 +161,9 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter { + plugin.excludeInlineProcessor(HtmlInlineProcessor.class); + })) .usePlugin(new AbstractMarkwonPlugin() { @NonNull @Override diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/MessageRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/MessageRecyclerViewAdapter.java index 440544dc..4c0ae441 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/MessageRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/MessageRecyclerViewAdapter.java @@ -34,7 +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.inlineparser.HtmlInlineProcessor; +import io.noties.markwon.inlineparser.MarkwonInlineParserPlugin; import io.noties.markwon.linkify.LinkifyPlugin; import ml.docilealligator.infinityforreddit.NetworkState; import ml.docilealligator.infinityforreddit.R; @@ -99,7 +100,9 @@ public class MessageRecyclerViewAdapter extends PagedListAdapter { + plugin.excludeInlineProcessor(HtmlInlineProcessor.class); + })) .usePlugin(new AbstractMarkwonPlugin() { @NonNull @Override @@ -120,7 +123,7 @@ public class MessageRecyclerViewAdapter extends PagedListAdapter![\\S\\s]+?!<"); Matcher matcher = spoilerPattern.matcher(markdownStringBuilder); int start = 0; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java index e5075417..ccb19b26 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java @@ -73,7 +73,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.inlineparser.HtmlInlineProcessor; +import io.noties.markwon.inlineparser.MarkwonInlineParserPlugin; import io.noties.markwon.linkify.LinkifyPlugin; import io.noties.markwon.movement.MovementMethodPlugin; import io.noties.markwon.recycler.MarkwonAdapter; @@ -226,7 +227,9 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter { + plugin.excludeInlineProcessor(HtmlInlineProcessor.class); + })) .usePlugin(new AbstractMarkwonPlugin() { @NonNull @Override @@ -247,7 +250,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter![\\S\\s]+?!<"); Matcher matcher = spoilerPattern.matcher(markdownStringBuilder); int start = 0; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PrivateMessagesDetailRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PrivateMessagesDetailRecyclerViewAdapter.java index 8fe78d79..e4ca0dd0 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PrivateMessagesDetailRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PrivateMessagesDetailRecyclerViewAdapter.java @@ -27,7 +27,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.inlineparser.HtmlInlineProcessor; +import io.noties.markwon.inlineparser.MarkwonInlineParserPlugin; import io.noties.markwon.linkify.LinkifyPlugin; import jp.wasabeef.glide.transformations.RoundedCornersTransformation; import ml.docilealligator.infinityforreddit.R; @@ -66,7 +67,9 @@ public class PrivateMessagesDetailRecyclerViewAdapter extends RecyclerView.Adapt mLocale = locale; mAccountName = accountName; mMarkwon = Markwon.builder(viewPrivateMessagesActivity) - .usePlugin(HtmlPlugin.create()) + .usePlugin(MarkwonInlineParserPlugin.create(plugin -> { + plugin.excludeInlineProcessor(HtmlInlineProcessor.class); + })) .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 454ecdd4..6cf4ee07 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RulesRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RulesRecyclerViewAdapter.java @@ -22,7 +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.inlineparser.HtmlInlineProcessor; +import io.noties.markwon.inlineparser.MarkwonInlineParserPlugin; import io.noties.markwon.linkify.LinkifyPlugin; import io.noties.markwon.movement.MovementMethodPlugin; import me.saket.bettermovementmethod.BetterLinkMovementMethod; @@ -40,7 +41,9 @@ public class RulesRecyclerViewAdapter extends RecyclerView.Adapter { + plugin.excludeInlineProcessor(HtmlInlineProcessor.class); + })) .usePlugin(new AbstractMarkwonPlugin() { @Override public void configureConfiguration(@NonNull MarkwonConfiguration.Builder builder) { 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 ef3d6925..f02db229 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SidebarFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SidebarFragment.java @@ -34,7 +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.inlineparser.HtmlInlineProcessor; +import io.noties.markwon.inlineparser.MarkwonInlineParserPlugin; import io.noties.markwon.linkify.LinkifyPlugin; import io.noties.markwon.movement.MovementMethodPlugin; import io.noties.markwon.recycler.MarkwonAdapter; @@ -104,7 +105,9 @@ public class SidebarFragment extends Fragment { markdownColor = mCustomThemeWrapper.getPrimaryTextColor(); Markwon markwon = Markwon.builder(activity) - .usePlugin(HtmlPlugin.create()) + .usePlugin(MarkwonInlineParserPlugin.create(plugin -> { + plugin.excludeInlineProcessor(HtmlInlineProcessor.class); + })) .usePlugin(new AbstractMarkwonPlugin() { @Override public void beforeSetText(@NonNull TextView textView, @NonNull Spanned markdown) { -- cgit v1.2.3 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: Add custom superscript processor --- .../activities/CommentActivity.java | 14 +++++++ .../activities/FullMarkdownActivity.java | 12 +++++- .../infinityforreddit/activities/WikiActivity.java | 12 +++++- .../CommentsListingRecyclerViewAdapter.java | 12 +++++- .../adapters/CommentsRecyclerViewAdapter.java | 15 ++++++- .../adapters/MessageRecyclerViewAdapter.java | 11 ++++++ .../adapters/PostDetailRecyclerViewAdapter.java | 12 +++++- .../PrivateMessagesDetailRecyclerViewAdapter.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 ++- 14 files changed, 195 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 (limited to 'app/src/main/java/ml') 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) { -- cgit v1.2.3 From 5fae42c210df8def1e32e4e306fd09729fc1f4ec Mon Sep 17 00:00:00 2001 From: scria1000 <91804886+scria1000@users.noreply.github.com> Date: Sat, 13 Nov 2021 01:34:28 +0300 Subject: Try to handle unescaped space inside link blocks * Commonmark spec does not parse links with unescaped spaces in the link query * Maybe we can do the parsing ourselves by extending 'InlineProcessor', instead of using slow regex * Reuse `fixSuperScript` --- .../activities/CommentActivity.java | 15 ++++-- .../activities/EditCommentActivity.java | 2 +- .../activities/EditPostActivity.java | 2 +- .../activities/FullMarkdownActivity.java | 19 ++------ .../infinityforreddit/activities/WikiActivity.java | 19 ++------ .../CommentsListingRecyclerViewAdapter.java | 18 +------- .../adapters/CommentsRecyclerViewAdapter.java | 20 +------- .../adapters/MessageRecyclerViewAdapter.java | 17 +------ .../adapters/PostDetailRecyclerViewAdapter.java | 17 +------ .../PrivateMessagesDetailRecyclerViewAdapter.java | 8 +++- .../adapters/RulesRecyclerViewAdapter.java | 9 +++- .../fragments/SidebarFragment.java | 9 +++- .../utils/ProcessRedditSuperscript.java | 46 ------------------- .../infinityforreddit/utils/Utils.java | 53 ++++++++++++++++++++-- 14 files changed, 97 insertions(+), 157 deletions(-) delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/utils/ProcessRedditSuperscript.java (limited to 'app/src/main/java/ml') 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 2ffa10e7..b6e5717a 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java @@ -70,7 +70,6 @@ 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; @@ -172,8 +171,13 @@ public class CommentActivity extends BaseActivity implements UploadImageEnabledA .usePlugin(HtmlPlugin.create(plugin -> { plugin.excludeDefaults(true).addHandler(new SuperScriptHandler()); })) - .usePlugin(new ProcessRedditSuperscript()) .usePlugin(new AbstractMarkwonPlugin() { + @NonNull + @Override + public String processMarkdown(@NonNull String markdown) { + return super.processMarkdown(Utils.fixSuperScript(new StringBuilder(markdown))); + } + @Override public void configureConfiguration(@NonNull MarkwonConfiguration.Builder builder) { builder.linkResolver((view, link) -> { @@ -220,8 +224,13 @@ public class CommentActivity extends BaseActivity implements UploadImageEnabledA .usePlugin(HtmlPlugin.create(plugin -> { plugin.excludeDefaults(true).addHandler(new SuperScriptHandler()); })) - .usePlugin(new ProcessRedditSuperscript()) .usePlugin(new AbstractMarkwonPlugin() { + @NonNull + @Override + public String processMarkdown(@NonNull String markdown) { + return super.processMarkdown(Utils.fixSuperScript(new StringBuilder(markdown))); + } + @Override public void beforeSetText(@NonNull TextView textView, @NonNull Spanned markdown) { textView.setTextColor(markdownColor); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditCommentActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditCommentActivity.java index 4f4b81ec..cb03370b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditCommentActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditCommentActivity.java @@ -132,7 +132,7 @@ public class EditCommentActivity extends BaseActivity implements UploadImageEnab mFullName = getIntent().getStringExtra(EXTRA_FULLNAME); mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null); - mCommentContent = getIntent().getStringExtra(EXTRA_CONTENT); + mCommentContent = getIntent().getStringExtra(EXTRA_CONTENT).replaceAll(">",">"); contentEditText.setText(mCommentContent); if (savedInstanceState != null) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditPostActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditPostActivity.java index 0d22d9b3..16e91ebc 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditPostActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditPostActivity.java @@ -141,7 +141,7 @@ public class EditPostActivity extends BaseActivity implements UploadImageEnabled mFullName = getIntent().getStringExtra(EXTRA_FULLNAME); mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null); titleTextView.setText(getIntent().getStringExtra(EXTRA_TITLE)); - mPostContent = getIntent().getStringExtra(EXTRA_CONTENT); + mPostContent = getIntent().getStringExtra(EXTRA_CONTENT).replaceAll(">",">");; contentEditText.setText(mPostContent); if (savedInstanceState != null) { 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 92bd1ec8..5ef80ffc 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FullMarkdownActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FullMarkdownActivity.java @@ -33,7 +33,6 @@ import org.commonmark.ext.gfm.tables.TableBlock; import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; -import java.util.ArrayList; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -61,9 +60,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; +import ml.docilealligator.infinityforreddit.utils.Utils; public class FullMarkdownActivity extends BaseActivity { @@ -143,25 +142,13 @@ public class FullMarkdownActivity extends BaseActivity { .usePlugin(HtmlPlugin.create(plugin -> { plugin.excludeDefaults(true).addHandler(new SuperScriptHandler()); })) - .usePlugin(new ProcessRedditSuperscript()) .usePlugin(new AbstractMarkwonPlugin() { - /* @NonNull @Override public String processMarkdown(@NonNull String markdown) { - StringBuilder markdownStringBuilder = new StringBuilder(markdown); - Pattern spoilerPattern = Pattern.compile(">![\\S\\s]+?!<"); - Matcher matcher = spoilerPattern.matcher(markdownStringBuilder); - ArrayList matched = new ArrayList<>(); - while (matcher.find()) { - matched.add(matcher.start()); - } - for (int i = matched.size() - 1; i >= 0; i--) { - markdownStringBuilder.replace(matched.get(i), matched.get(i) + 1, ">"); - } - return super.processMarkdown(markdownStringBuilder.toString()); + return super.processMarkdown(Utils.fixSuperScript(new StringBuilder(markdown))); } - */ + @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 644ac4b5..657eafe7 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WikiActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WikiActivity.java @@ -37,7 +37,6 @@ import org.greenrobot.eventbus.Subscribe; import org.json.JSONException; import org.json.JSONObject; -import java.util.ArrayList; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -67,9 +66,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 ml.docilealligator.infinityforreddit.utils.Utils; import retrofit2.Call; import retrofit2.Callback; import retrofit2.Response; @@ -168,25 +167,13 @@ public class WikiActivity extends BaseActivity { .usePlugin(HtmlPlugin.create(plugin -> { plugin.excludeDefaults(true).addHandler(new SuperScriptHandler()); })) - .usePlugin(new ProcessRedditSuperscript()) .usePlugin(new AbstractMarkwonPlugin() { - /* @NonNull @Override public String processMarkdown(@NonNull String markdown) { - StringBuilder markdownStringBuilder = new StringBuilder(markdown); - Pattern spoilerPattern = Pattern.compile(">![\\S\\s]+?!<"); - Matcher matcher = spoilerPattern.matcher(markdownStringBuilder); - ArrayList matched = new ArrayList<>(); - while (matcher.find()) { - matched.add(matcher.start()); - } - for (int i = matched.size() - 1; i >= 0; i--) { - markdownStringBuilder.replace(matched.get(i), matched.get(i) + 1, ">"); - } - return super.processMarkdown(markdownStringBuilder.toString()); + return super.processMarkdown(Utils.fixSuperScript(new StringBuilder(markdown))); } - */ + @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 1a3fb7ac..176953ea 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java @@ -30,7 +30,6 @@ import androidx.recyclerview.widget.DiffUtil; import androidx.recyclerview.widget.ItemTouchHelper; import androidx.recyclerview.widget.RecyclerView; -import java.util.ArrayList; import java.util.Locale; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -63,7 +62,6 @@ 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; @@ -128,25 +126,13 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter { plugin.excludeDefaults(true).addHandler(new SuperScriptHandler()); })) - .usePlugin(new ProcessRedditSuperscript()) .usePlugin(new AbstractMarkwonPlugin() { - /* @NonNull @Override public String processMarkdown(@NonNull String markdown) { - StringBuilder markdownStringBuilder = new StringBuilder(markdown); - Pattern spoilerPattern = Pattern.compile(">![\\S\\s]+?!<"); - Matcher matcher = spoilerPattern.matcher(markdownStringBuilder); - ArrayList matched = new ArrayList<>(); - while (matcher.find()) { - matched.add(matcher.start()); - } - for (int i = matched.size() - 1; i >= 0; i--) { - markdownStringBuilder.replace(matched.get(i), matched.get(i) + 1, ">"); - } - return super.processMarkdown(markdownStringBuilder.toString()); + return super.processMarkdown(Utils.fixSuperScript(new StringBuilder(markdown))); } - */ + @Override public void afterSetText(@NonNull TextView textView) { textView.setHighlightColor(Color.TRANSPARENT); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java index 8a6cb8b9..d59514cf 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java @@ -47,10 +47,7 @@ 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.HtmlEmptyTagReplacement; import io.noties.markwon.html.HtmlPlugin; -import io.noties.markwon.html.tag.ImageHandler; -import io.noties.markwon.html.tag.LinkHandler; import io.noties.markwon.html.tag.SuperScriptHandler; import io.noties.markwon.inlineparser.HtmlInlineProcessor; import io.noties.markwon.inlineparser.MarkwonInlineParserPlugin; @@ -74,7 +71,6 @@ import ml.docilealligator.infinityforreddit.customviews.SpoilerOnClickTextView; import ml.docilealligator.infinityforreddit.fragments.ViewPostDetailFragment; import ml.docilealligator.infinityforreddit.post.Post; 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; @@ -175,25 +171,13 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter { plugin.excludeDefaults(true).addHandler(new SuperScriptHandler()); })) - .usePlugin(new ProcessRedditSuperscript()) .usePlugin(new AbstractMarkwonPlugin() { - /* @NonNull @Override public String processMarkdown(@NonNull String markdown) { - StringBuilder markdownStringBuilder = new StringBuilder(markdown); - Pattern spoilerPattern = Pattern.compile(">![\\S\\s]+?!<"); - Matcher matcher = spoilerPattern.matcher(markdownStringBuilder); - ArrayList matched = new ArrayList<>(); - while (matcher.find()) { - matched.add(matcher.start()); - } - for (int i = matched.size() - 1; i >= 0; i--) { - markdownStringBuilder.replace(matched.get(i), matched.get(i) + 1, ">"); - } - return super.processMarkdown(markdownStringBuilder.toString()); + return super.processMarkdown(Utils.fixSuperScript(new StringBuilder(markdown))); } - */ + @Override public void afterSetText(@NonNull TextView textView) { SpannableStringBuilder markdownStringBuilder = new SpannableStringBuilder(textView.getText()); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/MessageRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/MessageRecyclerViewAdapter.java index 5b6aae99..3f63ec80 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/MessageRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/MessageRecyclerViewAdapter.java @@ -48,8 +48,8 @@ import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.message.FetchMessage; import ml.docilealligator.infinityforreddit.message.Message; import ml.docilealligator.infinityforreddit.message.ReadMessage; -import ml.docilealligator.infinityforreddit.utils.ProcessRedditSuperscript; import ml.docilealligator.infinityforreddit.utils.SuperscriptInlineProcessor; +import ml.docilealligator.infinityforreddit.utils.Utils; import retrofit2.Retrofit; public class MessageRecyclerViewAdapter extends PagedListAdapter { @@ -111,25 +111,12 @@ public class MessageRecyclerViewAdapter extends PagedListAdapter { plugin.excludeDefaults(true).addHandler(new SuperScriptHandler()); })) - .usePlugin(new ProcessRedditSuperscript()) .usePlugin(new AbstractMarkwonPlugin() { - /* @NonNull @Override public String processMarkdown(@NonNull String markdown) { - StringBuilder markdownStringBuilder = new StringBuilder(markdown); - Pattern spoilerPattern = Pattern.compile(">![\\S\\s]+?!<"); - Matcher matcher = spoilerPattern.matcher(markdownStringBuilder); - ArrayList matched = new ArrayList<>(); - while (matcher.find()) { - matched.add(matcher.start()); - } - for (int i = matched.size() - 1; i >= 0; i--) { - markdownStringBuilder.replace(matched.get(i), matched.get(i) + 1, ">"); - } - return super.processMarkdown(markdownStringBuilder.toString()); + return super.processMarkdown(Utils.fixSuperScript(new StringBuilder(markdown))); } - */ @Override public void afterSetText(@NonNull TextView textView) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java index 8663da52..85411123 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java @@ -112,7 +112,6 @@ import ml.docilealligator.infinityforreddit.fragments.ViewPostDetailFragment; import ml.docilealligator.infinityforreddit.post.Post; import ml.docilealligator.infinityforreddit.post.PostPagingSource; 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; @@ -238,25 +237,13 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter { plugin.excludeDefaults(true).addHandler(new SuperScriptHandler()); })) - .usePlugin(new ProcessRedditSuperscript()) .usePlugin(new AbstractMarkwonPlugin() { - /* @NonNull @Override public String processMarkdown(@NonNull String markdown) { - StringBuilder markdownStringBuilder = new StringBuilder(markdown); - Pattern spoilerPattern = Pattern.compile(">![\\S\\s]+?!<"); - Matcher matcher = spoilerPattern.matcher(markdownStringBuilder); - ArrayList matched = new ArrayList<>(); - while (matcher.find()) { - matched.add(matcher.start()); - } - for (int i = matched.size() - 1; i >= 0; i--) { - markdownStringBuilder.replace(matched.get(i), matched.get(i) + 1, ">"); - } - return super.processMarkdown(markdownStringBuilder.toString()); + return super.processMarkdown(Utils.fixSuperScript(new StringBuilder(markdown))); } - */ + @Override public void afterSetText(@NonNull TextView textView) { textView.setHighlightColor(Color.TRANSPARENT); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PrivateMessagesDetailRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PrivateMessagesDetailRecyclerViewAdapter.java index 99adc221..93f487bf 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PrivateMessagesDetailRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PrivateMessagesDetailRecyclerViewAdapter.java @@ -39,7 +39,6 @@ import ml.docilealligator.infinityforreddit.activities.ViewPrivateMessagesActivi import ml.docilealligator.infinityforreddit.activities.ViewUserDetailActivity; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.message.Message; -import ml.docilealligator.infinityforreddit.utils.ProcessRedditSuperscript; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; import ml.docilealligator.infinityforreddit.utils.SuperscriptInlineProcessor; import ml.docilealligator.infinityforreddit.utils.Utils; @@ -78,8 +77,13 @@ public class PrivateMessagesDetailRecyclerViewAdapter extends RecyclerView.Adapt .usePlugin(HtmlPlugin.create(plugin -> { plugin.excludeDefaults(true).addHandler(new SuperScriptHandler()); })) - .usePlugin(new ProcessRedditSuperscript()) .usePlugin(new AbstractMarkwonPlugin() { + @NonNull + @Override + public String processMarkdown(@NonNull String markdown) { + return super.processMarkdown(Utils.fixSuperScript(new StringBuilder(markdown))); + } + @Override public void configureConfiguration(@NonNull MarkwonConfiguration.Builder builder) { builder.linkResolver((view, link) -> { 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 4eb9d5d8..789c0865 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RulesRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RulesRecyclerViewAdapter.java @@ -34,8 +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; +import ml.docilealligator.infinityforreddit.utils.Utils; public class RulesRecyclerViewAdapter extends RecyclerView.Adapter { private Markwon markwon; @@ -52,8 +52,13 @@ public class RulesRecyclerViewAdapter extends RecyclerView.Adapter { plugin.excludeDefaults(true).addHandler(new SuperScriptHandler()); })) - .usePlugin(new ProcessRedditSuperscript()) .usePlugin(new AbstractMarkwonPlugin() { + @NonNull + @Override + public String processMarkdown(@NonNull String markdown) { + return super.processMarkdown(Utils.fixSuperScript(new StringBuilder(markdown))); + } + @Override public void configureConfiguration(@NonNull MarkwonConfiguration.Builder builder) { builder.linkResolver((view, link) -> { 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 416b3046..6fb68f53 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SidebarFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SidebarFragment.java @@ -57,8 +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 ml.docilealligator.infinityforreddit.utils.Utils; import retrofit2.Retrofit; public class SidebarFragment extends Fragment { @@ -116,8 +116,13 @@ public class SidebarFragment extends Fragment { .usePlugin(HtmlPlugin.create(plugin -> { plugin.excludeDefaults(true).addHandler(new SuperScriptHandler()); })) - .usePlugin(new ProcessRedditSuperscript()) .usePlugin(new AbstractMarkwonPlugin() { + @NonNull + @Override + public String processMarkdown(@NonNull String markdown) { + return super.processMarkdown(Utils.fixSuperScript(new StringBuilder(markdown))); + } + @Override public void beforeSetText(@NonNull TextView textView, @NonNull Spanned markdown) { textView.setTextColor(markdownColor); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/ProcessRedditSuperscript.java b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/ProcessRedditSuperscript.java deleted file mode 100644 index 0dc539d7..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/ProcessRedditSuperscript.java +++ /dev/null @@ -1,46 +0,0 @@ -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/Utils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java index 16aeb642..b76b63be 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java @@ -61,12 +61,11 @@ public class Utils { private static final long YEAR_MILLIS = 12 * MONTH_MILLIS; public static String modifyMarkdown(String markdown) { - StringBuilder regexed = new StringBuilder(markdown + StringBuilder regexed = new StringBuilder(trimAndEscapeSpaceInLinks(markdown) .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(">!", ">!") // If it's in a code black, html entity remains escaped .replaceAll("(^|^ *|\\n *)#(?!($|\\s|#))", "$0 ") .replaceAll("(^|^ *|\\n *)##(?!($|\\s|#))", "$0 ") .replaceAll("(^|^ *|\\n *)###(?!($|\\s|#))", "$0 ") @@ -78,7 +77,53 @@ public class Utils { return regexed.toString(); } - private static String fixSuperScript(StringBuilder regexed) { + // Also matches links inside code blocks as a side effect + private static String trimAndEscapeSpaceInLinks(String markdown){ + String TEXT = "\\[([^\\[]\\n?[\\S\\h]+?\\n?[\\S\\h]*?)]"; + String LINK = "(\\n?[\\h]*?\\n?https?:\\/\\/[\\S\\h]+?\n?)"; + String TITLE = "(?:\\s\"(\\n?[\\S\\h]+?\\n?[\\S\\h]*?)?\")?"; + Pattern pattern = Pattern.compile(TEXT + "\\(" + LINK + TITLE + "\\n?\\h*?\\)"); + Matcher matcher = pattern.matcher(markdown); + StringBuilder builder = new StringBuilder(); + int start = 0; + while (matcher.find()) try { + String match1; + String match2; + String match3; + if ((match1 = matcher.group(1)) != null && (match2 = matcher.group(2)) != null) { + match1 = match1.trim().replaceAll("\\s+", " "); + match2 = match2.trim().replaceAll(" ", "%20"); + match3 = matcher.group(3); + builder.append(markdown.substring(start, matcher.start())) + .append("[") + .append(match1) + .append("]") + .append("(") + .append(match2); + if (match3 != null) { + builder.append(" \"") + .append(match3) + .append("\""); + } + builder.append(")"); + start = matcher.end(); + } + } catch (NullPointerException e) { + e.printStackTrace(); + } + + if (start < markdown.length()) { + builder.append(markdown.substring(start)); + } + + if(builder.length() > 0) { + return builder.toString(); } + else { + return markdown; + } + } + + public static String fixSuperScript(StringBuilder regexed) { boolean hasBracket = false; int nCarets = 0; for (int i = 0; i < regexed.length(); i++) { -- cgit v1.2.3 From e3976248cc948df3633f4254d29645389ae9221d Mon Sep 17 00:00:00 2001 From: scria1000 <91804886+scria1000@users.noreply.github.com> Date: Sat, 13 Nov 2021 15:58:55 +0300 Subject: Disable BangInlineProcessor Don't process ! bangs before links since reddit markdown does not support it. Now links inside spoilers can be rendered correctly. --- .../activities/CommentActivity.java | 3 ++ .../activities/FullMarkdownActivity.java | 2 + .../activities/ViewSubredditDetailActivity.java | 11 +++-- .../activities/ViewUserDetailActivity.java | 11 +++-- .../infinityforreddit/activities/WikiActivity.java | 2 + .../CommentsListingRecyclerViewAdapter.java | 47 +++++++++--------- .../adapters/CommentsRecyclerViewAdapter.java | 57 ++++++++++++---------- .../adapters/MessageRecyclerViewAdapter.java | 2 + .../adapters/PostDetailRecyclerViewAdapter.java | 50 ++++++++++--------- .../PrivateMessagesDetailRecyclerViewAdapter.java | 2 + .../adapters/RulesRecyclerViewAdapter.java | 2 + .../fragments/SidebarFragment.java | 2 + .../infinityforreddit/utils/Utils.java | 2 +- 13 files changed, 111 insertions(+), 82 deletions(-) (limited to 'app/src/main/java/ml') 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 b6e5717a..d095428f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java @@ -52,6 +52,7 @@ 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.BangInlineProcessor; import io.noties.markwon.inlineparser.HtmlInlineProcessor; import io.noties.markwon.inlineparser.MarkwonInlineParserPlugin; import io.noties.markwon.linkify.LinkifyPlugin; @@ -166,6 +167,7 @@ public class CommentActivity extends BaseActivity implements UploadImageEnabledA Markwon markwon = Markwon.builder(this) .usePlugin(MarkwonInlineParserPlugin.create(plugin -> { plugin.excludeInlineProcessor(HtmlInlineProcessor.class); + plugin.excludeInlineProcessor(BangInlineProcessor.class); plugin.addInlineProcessor(new SuperscriptInlineProcessor()); })) .usePlugin(HtmlPlugin.create(plugin -> { @@ -219,6 +221,7 @@ public class CommentActivity extends BaseActivity implements UploadImageEnabledA Markwon postBodyMarkwon = Markwon.builder(this) .usePlugin(MarkwonInlineParserPlugin.create(plugin -> { plugin.excludeInlineProcessor(HtmlInlineProcessor.class); + plugin.excludeInlineProcessor(BangInlineProcessor.class); plugin.addInlineProcessor(new SuperscriptInlineProcessor()); })) .usePlugin(HtmlPlugin.create(plugin -> { 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 5ef80ffc..12545d44 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FullMarkdownActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FullMarkdownActivity.java @@ -48,6 +48,7 @@ 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.BangInlineProcessor; import io.noties.markwon.inlineparser.HtmlInlineProcessor; import io.noties.markwon.inlineparser.MarkwonInlineParserPlugin; import io.noties.markwon.linkify.LinkifyPlugin; @@ -137,6 +138,7 @@ public class FullMarkdownActivity extends BaseActivity { Markwon markwon = Markwon.builder(this) .usePlugin(MarkwonInlineParserPlugin.create(plugin -> { plugin.excludeInlineProcessor(HtmlInlineProcessor.class); + plugin.excludeInlineProcessor(BangInlineProcessor.class); plugin.addInlineProcessor(new SuperscriptInlineProcessor()); })) .usePlugin(HtmlPlugin.create(plugin -> { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java index 368e2b46..dcca88b5 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java @@ -4,6 +4,7 @@ import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.content.res.ColorStateList; +import android.graphics.PorterDuff; import android.net.Uri; import android.os.Build; import android.os.Bundle; @@ -71,6 +72,7 @@ import io.noties.markwon.AbstractMarkwonPlugin; import io.noties.markwon.Markwon; import io.noties.markwon.MarkwonConfiguration; import io.noties.markwon.core.MarkwonTheme; +import io.noties.markwon.inlineparser.BangInlineProcessor; import io.noties.markwon.inlineparser.HtmlInlineProcessor; import io.noties.markwon.inlineparser.MarkwonInlineParserPlugin; import io.noties.markwon.linkify.LinkifyPlugin; @@ -384,6 +386,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp Markwon markwon = Markwon.builder(this) .usePlugin(MarkwonInlineParserPlugin.create(plugin -> { plugin.excludeInlineProcessor(HtmlInlineProcessor.class); + plugin.excludeInlineProcessor(BangInlineProcessor.class); })) .usePlugin(new AbstractMarkwonPlugin() { @Override @@ -546,10 +549,10 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp descriptionTextView.setTextColor(primaryTextColor); bottomNavigationView.setBackgroundTint(ColorStateList.valueOf(mCustomThemeWrapper.getBottomAppBarBackgroundColor())); int bottomAppBarIconColor = mCustomThemeWrapper.getBottomAppBarIconColor(); - option2BottomAppBar.setColorFilter(bottomAppBarIconColor, android.graphics.PorterDuff.Mode.SRC_IN); - option1BottomAppBar.setColorFilter(bottomAppBarIconColor, android.graphics.PorterDuff.Mode.SRC_IN); - option3BottomAppBar.setColorFilter(bottomAppBarIconColor, android.graphics.PorterDuff.Mode.SRC_IN); - option4BottomAppBar.setColorFilter(bottomAppBarIconColor, android.graphics.PorterDuff.Mode.SRC_IN); + option2BottomAppBar.setColorFilter(bottomAppBarIconColor, PorterDuff.Mode.SRC_IN); + option1BottomAppBar.setColorFilter(bottomAppBarIconColor, PorterDuff.Mode.SRC_IN); + option3BottomAppBar.setColorFilter(bottomAppBarIconColor, PorterDuff.Mode.SRC_IN); + option4BottomAppBar.setColorFilter(bottomAppBarIconColor, PorterDuff.Mode.SRC_IN); applyTabLayoutTheme(tabLayout); applyFABTheme(fab); unsubscribedColor = mCustomThemeWrapper.getUnsubscribed(); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java index 7ef81969..16ec23b9 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java @@ -5,6 +5,7 @@ import android.content.Intent; import android.content.SharedPreferences; import android.content.res.ColorStateList; import android.content.res.Resources; +import android.graphics.PorterDuff; import android.net.Uri; import android.os.AsyncTask; import android.os.Build; @@ -73,6 +74,7 @@ import io.noties.markwon.AbstractMarkwonPlugin; import io.noties.markwon.Markwon; import io.noties.markwon.MarkwonConfiguration; import io.noties.markwon.core.MarkwonTheme; +import io.noties.markwon.inlineparser.BangInlineProcessor; import io.noties.markwon.inlineparser.HtmlInlineProcessor; import io.noties.markwon.inlineparser.MarkwonInlineParserPlugin; import io.noties.markwon.linkify.LinkifyPlugin; @@ -380,6 +382,7 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele Markwon markwon = Markwon.builder(this) .usePlugin(MarkwonInlineParserPlugin.create(plugin -> { plugin.excludeInlineProcessor(HtmlInlineProcessor.class); + plugin.excludeInlineProcessor(BangInlineProcessor.class); })) .usePlugin(new AbstractMarkwonPlugin() { @Override @@ -640,10 +643,10 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele cakedayTextView.setTextColor(mCustomThemeWrapper.getPrimaryTextColor()); bottomNavigationView.setBackgroundTint(ColorStateList.valueOf(mCustomThemeWrapper.getBottomAppBarBackgroundColor())); int bottomAppBarIconColor = mCustomThemeWrapper.getBottomAppBarIconColor(); - option2BottomAppBar.setColorFilter(bottomAppBarIconColor, android.graphics.PorterDuff.Mode.SRC_IN); - option1BottomAppBar.setColorFilter(bottomAppBarIconColor, android.graphics.PorterDuff.Mode.SRC_IN); - option3BottomAppBar.setColorFilter(bottomAppBarIconColor, android.graphics.PorterDuff.Mode.SRC_IN); - option4BottomAppBar.setColorFilter(bottomAppBarIconColor, android.graphics.PorterDuff.Mode.SRC_IN); + option2BottomAppBar.setColorFilter(bottomAppBarIconColor, PorterDuff.Mode.SRC_IN); + option1BottomAppBar.setColorFilter(bottomAppBarIconColor, PorterDuff.Mode.SRC_IN); + option3BottomAppBar.setColorFilter(bottomAppBarIconColor, PorterDuff.Mode.SRC_IN); + option4BottomAppBar.setColorFilter(bottomAppBarIconColor, PorterDuff.Mode.SRC_IN); applyFABTheme(fab); descriptionTextView.setTextColor(mCustomThemeWrapper.getPrimaryTextColor()); subscribeUserChip.setTextColor(mCustomThemeWrapper.getChipTextColor()); 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 657eafe7..ca206b8b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WikiActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WikiActivity.java @@ -52,6 +52,7 @@ 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.BangInlineProcessor; import io.noties.markwon.inlineparser.HtmlInlineProcessor; import io.noties.markwon.inlineparser.MarkwonInlineParserPlugin; import io.noties.markwon.linkify.LinkifyPlugin; @@ -162,6 +163,7 @@ public class WikiActivity extends BaseActivity { markwon = Markwon.builder(this) .usePlugin(MarkwonInlineParserPlugin.create(plugin -> { plugin.excludeInlineProcessor(HtmlInlineProcessor.class); + plugin.excludeInlineProcessor(BangInlineProcessor.class); plugin.addInlineProcessor(new SuperscriptInlineProcessor()); })) .usePlugin(HtmlPlugin.create(plugin -> { 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 176953ea..91827d06 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java @@ -4,6 +4,7 @@ import android.content.Intent; import android.content.SharedPreferences; import android.content.res.ColorStateList; import android.graphics.Color; +import android.graphics.PorterDuff; import android.net.Uri; import android.os.Bundle; import android.text.SpannableStringBuilder; @@ -43,6 +44,7 @@ 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.BangInlineProcessor; import io.noties.markwon.inlineparser.HtmlInlineProcessor; import io.noties.markwon.inlineparser.MarkwonInlineParserPlugin; import io.noties.markwon.linkify.LinkifyPlugin; @@ -121,6 +123,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter { plugin.excludeInlineProcessor(HtmlInlineProcessor.class); + plugin.excludeInlineProcessor(BangInlineProcessor.class); plugin.addInlineProcessor(new SuperscriptInlineProcessor()); })) .usePlugin(HtmlPlugin.create(plugin -> { @@ -281,12 +284,12 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter { @@ -565,20 +568,20 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter { plugin.excludeInlineProcessor(HtmlInlineProcessor.class); + plugin.excludeInlineProcessor(BangInlineProcessor.class); plugin.addInlineProcessor(new SuperscriptInlineProcessor()); })) .usePlugin(HtmlPlugin.create(plugin -> { @@ -486,13 +489,13 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter authorTextView.performClick()); @@ -1254,20 +1257,20 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter { plugin.excludeInlineProcessor(HtmlInlineProcessor.class); + plugin.excludeInlineProcessor(BangInlineProcessor.class); plugin.addInlineProcessor(new SuperscriptInlineProcessor()); })) .usePlugin(HtmlPlugin.create(plugin -> { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java index 85411123..dec86c7b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java @@ -75,6 +75,7 @@ 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.BangInlineProcessor; import io.noties.markwon.inlineparser.HtmlInlineProcessor; import io.noties.markwon.inlineparser.MarkwonInlineParserPlugin; import io.noties.markwon.linkify.LinkifyPlugin; @@ -232,6 +233,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter { plugin.excludeInlineProcessor(HtmlInlineProcessor.class); + plugin.excludeInlineProcessor(BangInlineProcessor.class); plugin.addInlineProcessor(new SuperscriptInlineProcessor()); })) .usePlugin(HtmlPlugin.create(plugin -> { @@ -594,16 +596,16 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter { if (mPost != null) { @@ -2348,7 +2350,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter { Intent intent = new Intent(mActivity, ViewRedditGalleryActivity.class); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PrivateMessagesDetailRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PrivateMessagesDetailRecyclerViewAdapter.java index 93f487bf..6480e886 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PrivateMessagesDetailRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PrivateMessagesDetailRecyclerViewAdapter.java @@ -29,6 +29,7 @@ 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.BangInlineProcessor; import io.noties.markwon.inlineparser.HtmlInlineProcessor; import io.noties.markwon.inlineparser.MarkwonInlineParserPlugin; import io.noties.markwon.linkify.LinkifyPlugin; @@ -72,6 +73,7 @@ public class PrivateMessagesDetailRecyclerViewAdapter extends RecyclerView.Adapt mMarkwon = Markwon.builder(viewPrivateMessagesActivity) .usePlugin(MarkwonInlineParserPlugin.create(plugin -> { plugin.excludeInlineProcessor(HtmlInlineProcessor.class); + plugin.excludeInlineProcessor(BangInlineProcessor.class); plugin.addInlineProcessor(new SuperscriptInlineProcessor()); })) .usePlugin(HtmlPlugin.create(plugin -> { 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 789c0865..4a603c94 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RulesRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RulesRecyclerViewAdapter.java @@ -24,6 +24,7 @@ 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.BangInlineProcessor; import io.noties.markwon.inlineparser.HtmlInlineProcessor; import io.noties.markwon.inlineparser.MarkwonInlineParserPlugin; import io.noties.markwon.linkify.LinkifyPlugin; @@ -47,6 +48,7 @@ public class RulesRecyclerViewAdapter extends RecyclerView.Adapter { plugin.excludeInlineProcessor(HtmlInlineProcessor.class); + plugin.excludeInlineProcessor(BangInlineProcessor.class); plugin.addInlineProcessor(new SuperscriptInlineProcessor()); })) .usePlugin(HtmlPlugin.create(plugin -> { 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 6fb68f53..ff31ccae 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SidebarFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SidebarFragment.java @@ -36,6 +36,7 @@ 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.BangInlineProcessor; import io.noties.markwon.inlineparser.HtmlInlineProcessor; import io.noties.markwon.inlineparser.MarkwonInlineParserPlugin; import io.noties.markwon.linkify.LinkifyPlugin; @@ -111,6 +112,7 @@ public class SidebarFragment extends Fragment { Markwon markwon = Markwon.builder(activity) .usePlugin(MarkwonInlineParserPlugin.create(plugin -> { plugin.excludeInlineProcessor(HtmlInlineProcessor.class); + plugin.excludeInlineProcessor(BangInlineProcessor.class); plugin.addInlineProcessor(new SuperscriptInlineProcessor()); })) .usePlugin(HtmlPlugin.create(plugin -> { 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 b76b63be..edc49f95 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java @@ -65,7 +65,7 @@ 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(">!", ">!") // If it's in a code black, html entity remains escaped + .replaceAll(">!", ">!") // If it's in a code block, html entity remains escaped .replaceAll("(^|^ *|\\n *)#(?!($|\\s|#))", "$0 ") .replaceAll("(^|^ *|\\n *)##(?!($|\\s|#))", "$0 ") .replaceAll("(^|^ *|\\n *)###(?!($|\\s|#))", "$0 ") -- cgit v1.2.3 From 839325efbedb108917b37353c9493fea305d71e2 Mon Sep 17 00:00:00 2001 From: scria1000 <91804886+scria1000@users.noreply.github.com> Date: Sun, 14 Nov 2021 14:52:07 +0300 Subject: Don't handle unescaped bracket links for now Until there is a better solution that can also handle `[Title]: https://link.com` type links and others. --- .../infinityforreddit/utils/Utils.java | 48 +--------------------- 1 file changed, 1 insertion(+), 47 deletions(-) (limited to 'app/src/main/java/ml') 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 edc49f95..0b49ba31 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java @@ -61,7 +61,7 @@ public class Utils { private static final long YEAR_MILLIS = 12 * MONTH_MILLIS; public static String modifyMarkdown(String markdown) { - StringBuilder regexed = new StringBuilder(trimAndEscapeSpaceInLinks(markdown) + StringBuilder regexed = new StringBuilder(markdown .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,}", "^") @@ -77,52 +77,6 @@ public class Utils { return regexed.toString(); } - // Also matches links inside code blocks as a side effect - private static String trimAndEscapeSpaceInLinks(String markdown){ - String TEXT = "\\[([^\\[]\\n?[\\S\\h]+?\\n?[\\S\\h]*?)]"; - String LINK = "(\\n?[\\h]*?\\n?https?:\\/\\/[\\S\\h]+?\n?)"; - String TITLE = "(?:\\s\"(\\n?[\\S\\h]+?\\n?[\\S\\h]*?)?\")?"; - Pattern pattern = Pattern.compile(TEXT + "\\(" + LINK + TITLE + "\\n?\\h*?\\)"); - Matcher matcher = pattern.matcher(markdown); - StringBuilder builder = new StringBuilder(); - int start = 0; - while (matcher.find()) try { - String match1; - String match2; - String match3; - if ((match1 = matcher.group(1)) != null && (match2 = matcher.group(2)) != null) { - match1 = match1.trim().replaceAll("\\s+", " "); - match2 = match2.trim().replaceAll(" ", "%20"); - match3 = matcher.group(3); - builder.append(markdown.substring(start, matcher.start())) - .append("[") - .append(match1) - .append("]") - .append("(") - .append(match2); - if (match3 != null) { - builder.append(" \"") - .append(match3) - .append("\""); - } - builder.append(")"); - start = matcher.end(); - } - } catch (NullPointerException e) { - e.printStackTrace(); - } - - if (start < markdown.length()) { - builder.append(markdown.substring(start)); - } - - if(builder.length() > 0) { - return builder.toString(); } - else { - return markdown; - } - } - public static String fixSuperScript(StringBuilder regexed) { boolean hasBracket = false; int nCarets = 0; -- cgit v1.2.3 From ef1bdf2fa5fa4505e609b0862d9c7ed01659da38 Mon Sep 17 00:00:00 2001 From: scria1000 <91804886+scria1000@users.noreply.github.com> Date: Sun, 14 Nov 2021 16:34:50 +0300 Subject: Optimize spoiler regex Optimize spoiler regex to allow at least one new line. >! match this!< >!match this!< >! match this!< >!don't match this! match this !< >!match this !< --- app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/src/main/java/ml') 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 0b49ba31..525dfa2a 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java @@ -65,7 +65,7 @@ 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(">!", ">!") // If it's in a code block, html entity remains escaped + .replaceAll("(?:>!)(\\n?[\\S\\h]+?\\n?[\\S\\h]+\\n?!<)", ">!$1") // html entity remains escaped inside an inline block .replaceAll("(^|^ *|\\n *)#(?!($|\\s|#))", "$0 ") .replaceAll("(^|^ *|\\n *)##(?!($|\\s|#))", "$0 ") .replaceAll("(^|^ *|\\n *)###(?!($|\\s|#))", "$0 ") -- cgit v1.2.3 From a52342b336ab71dece4d923e1be17d95fc6b0e30 Mon Sep 17 00:00:00 2001 From: scria1000 <91804886+scria1000@users.noreply.github.com> Date: Sun, 14 Nov 2021 17:21:59 +0300 Subject: Refactor --- .../infinityforreddit/activities/CommentActivity.java | 4 ++-- .../infinityforreddit/activities/FullMarkdownActivity.java | 2 +- .../docilealligator/infinityforreddit/activities/WikiActivity.java | 2 +- .../adapters/CommentsListingRecyclerViewAdapter.java | 2 +- .../infinityforreddit/adapters/CommentsRecyclerViewAdapter.java | 2 +- .../infinityforreddit/adapters/MessageRecyclerViewAdapter.java | 2 +- .../infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java | 2 +- .../adapters/PrivateMessagesDetailRecyclerViewAdapter.java | 2 +- .../infinityforreddit/adapters/RulesRecyclerViewAdapter.java | 2 +- .../docilealligator/infinityforreddit/fragments/SidebarFragment.java | 2 +- .../main/java/ml/docilealligator/infinityforreddit/utils/Utils.java | 5 ++--- 11 files changed, 13 insertions(+), 14 deletions(-) (limited to 'app/src/main/java/ml') 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 d095428f..0d84fd8b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java @@ -177,7 +177,7 @@ public class CommentActivity extends BaseActivity implements UploadImageEnabledA @NonNull @Override public String processMarkdown(@NonNull String markdown) { - return super.processMarkdown(Utils.fixSuperScript(new StringBuilder(markdown))); + return super.processMarkdown(markdown); } @Override @@ -231,7 +231,7 @@ public class CommentActivity extends BaseActivity implements UploadImageEnabledA @NonNull @Override public String processMarkdown(@NonNull String markdown) { - return super.processMarkdown(Utils.fixSuperScript(new StringBuilder(markdown))); + return super.processMarkdown(markdown); } @Override 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 12545d44..5de7106f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FullMarkdownActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FullMarkdownActivity.java @@ -148,7 +148,7 @@ public class FullMarkdownActivity extends BaseActivity { @NonNull @Override public String processMarkdown(@NonNull String markdown) { - return super.processMarkdown(Utils.fixSuperScript(new StringBuilder(markdown))); + return super.processMarkdown(markdown); } @Override 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 ca206b8b..9cd26d46 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WikiActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WikiActivity.java @@ -173,7 +173,7 @@ public class WikiActivity extends BaseActivity { @NonNull @Override public String processMarkdown(@NonNull String markdown) { - return super.processMarkdown(Utils.fixSuperScript(new StringBuilder(markdown))); + return super.processMarkdown(markdown); } @Override 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 91827d06..5c85c4b2 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java @@ -133,7 +133,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter Date: Sun, 14 Nov 2021 21:48:11 +0300 Subject: Revert changes made in refactor We need the original superscript markdown for when we edit posts! --- .../infinityforreddit/activities/CommentActivity.java | 4 ++-- .../infinityforreddit/activities/FullMarkdownActivity.java | 2 +- .../docilealligator/infinityforreddit/activities/WikiActivity.java | 2 +- .../adapters/CommentsListingRecyclerViewAdapter.java | 2 +- .../infinityforreddit/adapters/CommentsRecyclerViewAdapter.java | 2 +- .../infinityforreddit/adapters/MessageRecyclerViewAdapter.java | 2 +- .../infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java | 2 +- .../adapters/PrivateMessagesDetailRecyclerViewAdapter.java | 2 +- .../infinityforreddit/adapters/RulesRecyclerViewAdapter.java | 2 +- .../infinityforreddit/fragments/SidebarFragment.java | 2 +- .../java/ml/docilealligator/infinityforreddit/utils/Utils.java | 7 +++++-- 11 files changed, 16 insertions(+), 13 deletions(-) (limited to 'app/src/main/java/ml') 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 0d84fd8b..ffb9173b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java @@ -177,7 +177,7 @@ public class CommentActivity extends BaseActivity implements UploadImageEnabledA @NonNull @Override public String processMarkdown(@NonNull String markdown) { - return super.processMarkdown(markdown); + return super.processMarkdown(Utils.fixSuperScript(markdown)); } @Override @@ -231,7 +231,7 @@ public class CommentActivity extends BaseActivity implements UploadImageEnabledA @NonNull @Override public String processMarkdown(@NonNull String markdown) { - return super.processMarkdown(markdown); + return super.processMarkdown(Utils.fixSuperScript(markdown)); } @Override 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 5de7106f..32a5f452 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FullMarkdownActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FullMarkdownActivity.java @@ -148,7 +148,7 @@ public class FullMarkdownActivity extends BaseActivity { @NonNull @Override public String processMarkdown(@NonNull String markdown) { - return super.processMarkdown(markdown); + return super.processMarkdown(Utils.fixSuperScript(markdown)); } @Override 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 9cd26d46..1a353a7f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WikiActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WikiActivity.java @@ -173,7 +173,7 @@ public class WikiActivity extends BaseActivity { @NonNull @Override public String processMarkdown(@NonNull String markdown) { - return super.processMarkdown(markdown); + return super.processMarkdown(Utils.fixSuperScript(markdown)); } @Override 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 5c85c4b2..616b9c1b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java @@ -133,7 +133,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter