diff options
author | Alex Ning <chineseperson5@gmail.com> | 2021-02-24 14:46:44 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2021-02-24 14:46:44 +0000 |
commit | abb37707fbc34c5c1a77b3990642a44b560dcd71 (patch) | |
tree | 3fa8669d6e6400d6738ab7f8c9ca2d54475e88aa /app | |
parent | f4bfa4fc401d484379c529c4266e3b78d88306be (diff) | |
download | infinity-for-reddit-abb37707fbc34c5c1a77b3990642a44b560dcd71.tar infinity-for-reddit-abb37707fbc34c5c1a77b3990642a44b560dcd71.tar.gz infinity-for-reddit-abb37707fbc34c5c1a77b3990642a44b560dcd71.tar.bz2 infinity-for-reddit-abb37707fbc34c5c1a77b3990642a44b560dcd71.tar.lz infinity-for-reddit-abb37707fbc34c5c1a77b3990642a44b560dcd71.tar.xz infinity-for-reddit-abb37707fbc34c5c1a77b3990642a44b560dcd71.tar.zst infinity-for-reddit-abb37707fbc34c5c1a77b3990642a44b560dcd71.zip |
Try to fix superscript.
Diffstat (limited to 'app')
10 files changed, 56 insertions, 126 deletions
diff --git a/app/build.gradle b/app/build.gradle index 0ef1b854..b2820092 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -138,6 +138,7 @@ dependencies { implementation "io.noties.markwon:linkify:$markwonVersion" implementation "io.noties.markwon:recycler-table:$markwonVersion" implementation "io.noties.markwon:simple-ext:$markwonVersion" + implementation "io.noties.markwon:html:$markwonVersion" implementation 'com.atlassian.commonmark:commonmark-ext-gfm-tables:0.14.0' implementation 'me.saket:better-link-movement-method:2.2.0' diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java index 44c393ff..74dbe822 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java @@ -7,7 +7,6 @@ import android.net.Uri; import android.os.Build; import android.os.Bundle; import android.text.Spanned; -import android.text.style.SuperscriptSpan; import android.text.util.Linkify; import android.view.Menu; import android.view.MenuItem; @@ -42,11 +41,11 @@ 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.linkify.LinkifyPlugin; import io.noties.markwon.recycler.MarkwonAdapter; import io.noties.markwon.recycler.table.TableEntry; import io.noties.markwon.recycler.table.TableEntryPlugin; -import io.noties.markwon.simple.ext.SimpleExtPlugin; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.adapters.MarkdownBottomBarRecyclerViewAdapter; @@ -136,6 +135,7 @@ public class CommentActivity extends BaseActivity { int linkColor = mCustomThemeWrapper.getLinkColor(); Markwon markwon = Markwon.builder(this) + .usePlugin(HtmlPlugin.create()) .usePlugin(new AbstractMarkwonPlugin() { @Override public void configureConfiguration(@NonNull MarkwonConfiguration.Builder builder) { @@ -153,12 +153,6 @@ public class CommentActivity extends BaseActivity { } }) .usePlugin(LinkifyPlugin.create(Linkify.WEB_URLS)) - .usePlugin(SimpleExtPlugin.create(plugin -> - plugin.addExtension(1, '^', (configuration, props) -> { - return new SuperscriptSpan(); - }) - ) - ) .build(); if (parentTextMarkdown != null) { commentParentMarkwonView.setOnLongClickListener(view -> { @@ -182,6 +176,7 @@ public class CommentActivity extends BaseActivity { contentMarkdownRecyclerView.setVisibility(View.VISIBLE); contentMarkdownRecyclerView.setNestedScrollingEnabled(false); Markwon postBodyMarkwon = Markwon.builder(this) + .usePlugin(HtmlPlugin.create()) .usePlugin(new AbstractMarkwonPlugin() { @Override public void beforeSetText(@NonNull TextView textView, @NonNull Spanned markdown) { @@ -214,12 +209,6 @@ public class CommentActivity extends BaseActivity { }) .usePlugin(StrikethroughPlugin.create()) .usePlugin(LinkifyPlugin.create(Linkify.WEB_URLS)) - .usePlugin(SimpleExtPlugin.create(plugin -> - plugin.addExtension(1, '^', (configuration, props) -> { - return new SuperscriptSpan(); - }) - ) - ) .usePlugin(TableEntryPlugin.create(this)) .build(); MarkwonAdapter markwonAdapter = MarkwonAdapter.builder(R.layout.adapter_default_entry, R.id.text) 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 79e3d8a5..312fe6cd 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FullMarkdownActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FullMarkdownActivity.java @@ -10,7 +10,6 @@ import android.text.SpannableStringBuilder; import android.text.Spanned; import android.text.TextPaint; import android.text.style.ClickableSpan; -import android.text.style.SuperscriptSpan; import android.text.util.Linkify; import android.view.MenuItem; import android.view.View; @@ -44,15 +43,15 @@ 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.linkify.LinkifyPlugin; import io.noties.markwon.recycler.MarkwonAdapter; import io.noties.markwon.recycler.table.TableEntry; import io.noties.markwon.recycler.table.TableEntryPlugin; -import io.noties.markwon.simple.ext.SimpleExtPlugin; -import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; -import ml.docilealligator.infinityforreddit.customviews.MarkwonLinearLayoutManager; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; +import ml.docilealligator.infinityforreddit.customviews.MarkwonLinearLayoutManager; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; public class FullMarkdownActivity extends BaseActivity { @@ -123,6 +122,7 @@ public class FullMarkdownActivity extends BaseActivity { int spoilerBackgroundColor = markdownColor | 0xFF000000; int linkColor = mCustomThemeWrapper.getLinkColor(); Markwon markwon = Markwon.builder(this) + .usePlugin(HtmlPlugin.create()) .usePlugin(new AbstractMarkwonPlugin() { @NonNull @Override @@ -204,12 +204,6 @@ public class FullMarkdownActivity extends BaseActivity { }) .usePlugin(StrikethroughPlugin.create()) .usePlugin(LinkifyPlugin.create(Linkify.WEB_URLS)) - .usePlugin(SimpleExtPlugin.create(plugin -> - plugin.addExtension(1, '^', (configuration, props) -> { - return new SuperscriptSpan(); - }) - ) - ) .usePlugin(TableEntryPlugin.create(this)) .build(); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentAndPostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentAndPostRecyclerViewAdapter.java index d7116056..ad040c64 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentAndPostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentAndPostRecyclerViewAdapter.java @@ -16,7 +16,6 @@ import android.text.SpannableStringBuilder; import android.text.Spanned; import android.text.TextPaint; import android.text.style.ClickableSpan; -import android.text.style.SuperscriptSpan; import android.text.util.Linkify; import android.view.LayoutInflater; import android.view.View; @@ -79,12 +78,12 @@ 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.linkify.LinkifyPlugin; import io.noties.markwon.movement.MovementMethodPlugin; import io.noties.markwon.recycler.MarkwonAdapter; import io.noties.markwon.recycler.table.TableEntry; import io.noties.markwon.recycler.table.TableEntryPlugin; -import io.noties.markwon.simple.ext.SimpleExtPlugin; import jp.wasabeef.glide.transformations.BlurTransformation; import jp.wasabeef.glide.transformations.RoundedCornersTransformation; import me.saket.bettermovementmethod.BetterLinkMovementMethod; @@ -266,6 +265,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy int postSpoilerBackgroundColor = markdownColor | 0xFF000000; int linkColor = customThemeWrapper.getLinkColor(); mPostDetailMarkwon = Markwon.builder(mActivity) + .usePlugin(HtmlPlugin.create()) .usePlugin(new AbstractMarkwonPlugin() { @NonNull @Override @@ -368,15 +368,10 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy return true; }))) .usePlugin(LinkifyPlugin.create(Linkify.WEB_URLS)) - .usePlugin(SimpleExtPlugin.create(plugin -> - plugin.addExtension(1, '^', (configuration, props) -> { - return new SuperscriptSpan(); - }) - ) - ) .usePlugin(TableEntryPlugin.create(mActivity)) .build(); mCommentMarkwon = Markwon.builder(mActivity) + .usePlugin(HtmlPlugin.create()) .usePlugin(new AbstractMarkwonPlugin() { @NonNull @Override @@ -462,12 +457,6 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy return true; }))) .usePlugin(LinkifyPlugin.create(Linkify.WEB_URLS)) - .usePlugin(SimpleExtPlugin.create(plugin -> - plugin.addExtension(1, '^', (configuration, props) -> { - return new SuperscriptSpan(); - }) - ) - ) .build(); mMarkwonAdapter = MarkwonAdapter.builder(R.layout.adapter_default_entry, R.id.text) .include(TableBlock.class, TableEntry.create(builder -> builder 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 c6ce9687..202166da 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,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.HtmlPlugin; import io.noties.markwon.linkify.LinkifyPlugin; import io.noties.markwon.movement.MovementMethodPlugin; import io.noties.markwon.simple.ext.SimpleExtPlugin; @@ -115,6 +116,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment mCommentColor = customThemeWrapper.getCommentColor(); int commentSpoilerBackgroundColor = mCommentColor | 0xFF000000; mMarkwon = Markwon.builder(mActivity) + .usePlugin(HtmlPlugin.create()) .usePlugin(new AbstractMarkwonPlugin() { @NonNull @Override @@ -203,12 +205,6 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment }))) .usePlugin(LinkifyPlugin.create(Linkify.WEB_URLS)) .usePlugin(StrikethroughPlugin.create()) - .usePlugin(SimpleExtPlugin.create(plugin -> - plugin.addExtension(1, '^', (configuration, props) -> { - return new SuperscriptSpan(); - }) - ) - ) .build(); mLocale = locale; mAccessToken = accessToken; 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 e6da1344..2c283669 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/MessageRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/MessageRecyclerViewAdapter.java @@ -10,7 +10,6 @@ import android.text.Spanned; import android.text.TextPaint; import android.text.method.LinkMovementMethod; import android.text.style.ClickableSpan; -import android.text.style.SuperscriptSpan; import android.text.util.Linkify; import android.view.LayoutInflater; import android.view.View; @@ -35,8 +34,10 @@ 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.linkify.LinkifyPlugin; -import io.noties.markwon.simple.ext.SimpleExtPlugin; +import ml.docilealligator.infinityforreddit.NetworkState; +import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.activities.LinkResolverActivity; import ml.docilealligator.infinityforreddit.activities.ViewPrivateMessagesActivity; import ml.docilealligator.infinityforreddit.activities.ViewUserDetailActivity; @@ -44,8 +45,6 @@ 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.NetworkState; -import ml.docilealligator.infinityforreddit.R; import retrofit2.Retrofit; public class MessageRecyclerViewAdapter extends PagedListAdapter<Message, RecyclerView.ViewHolder> { @@ -100,6 +99,7 @@ public class MessageRecyclerViewAdapter extends PagedListAdapter<Message, Recycl mButtonTextColor = customThemeWrapper.getButtonTextColor(); mMarkwon = Markwon.builder(mContext) + .usePlugin(HtmlPlugin.create()) .usePlugin(new AbstractMarkwonPlugin() { @NonNull @Override @@ -177,12 +177,6 @@ public class MessageRecyclerViewAdapter extends PagedListAdapter<Message, Recycl }) .usePlugin(StrikethroughPlugin.create()) .usePlugin(LinkifyPlugin.create(Linkify.WEB_URLS)) - .usePlugin(SimpleExtPlugin.create(plugin -> - plugin.addExtension(1, '^', (configuration, props) -> { - return new SuperscriptSpan(); - }) - ) - ) .build(); mAccessToken = accessToken; if (where.equals(FetchMessage.WHERE_MESSAGES)) { 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 9d2de4ec..190b8ad5 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PrivateMessagesDetailRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PrivateMessagesDetailRecyclerViewAdapter.java @@ -4,7 +4,6 @@ import android.content.Intent; import android.content.SharedPreferences; import android.graphics.Color; import android.net.Uri; -import android.text.style.SuperscriptSpan; import android.text.util.Linkify; import android.view.LayoutInflater; import android.view.View; @@ -28,15 +27,15 @@ 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.linkify.LinkifyPlugin; -import io.noties.markwon.simple.ext.SimpleExtPlugin; import jp.wasabeef.glide.transformations.RoundedCornersTransformation; +import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.activities.LinkResolverActivity; import ml.docilealligator.infinityforreddit.activities.ViewPrivateMessagesActivity; import ml.docilealligator.infinityforreddit.activities.ViewUserDetailActivity; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.message.Message; -import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; import ml.docilealligator.infinityforreddit.utils.Utils; @@ -67,6 +66,7 @@ public class PrivateMessagesDetailRecyclerViewAdapter extends RecyclerView.Adapt mLocale = locale; mAccountName = accountName; mMarkwon = Markwon.builder(viewPrivateMessagesActivity) + .usePlugin(HtmlPlugin.create()) .usePlugin(new AbstractMarkwonPlugin() { @Override public void configureConfiguration(@NonNull MarkwonConfiguration.Builder builder) { @@ -85,12 +85,6 @@ public class PrivateMessagesDetailRecyclerViewAdapter extends RecyclerView.Adapt }) .usePlugin(StrikethroughPlugin.create()) .usePlugin(LinkifyPlugin.create(Linkify.WEB_URLS)) - .usePlugin(SimpleExtPlugin.create(plugin -> - plugin.addExtension(1, '^', (configuration, props) -> { - return new SuperscriptSpan(); - }) - ) - ) .build(); mShowElapsedTime = sharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_ELAPSED_TIME_KEY, false); mTimeFormatPattern = sharedPreferences.getString(SharedPreferencesUtils.TIME_FORMAT_KEY, SharedPreferencesUtils.TIME_FORMAT_DEFAULT_VALUE); 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 5f7fd8e0..51d55400 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RulesRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RulesRecyclerViewAdapter.java @@ -3,7 +3,6 @@ package ml.docilealligator.infinityforreddit.adapters; import android.content.Intent; import android.net.Uri; import android.os.Bundle; -import android.text.style.SuperscriptSpan; import android.text.util.Linkify; import android.view.LayoutInflater; import android.view.View; @@ -23,9 +22,9 @@ 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.linkify.LinkifyPlugin; import io.noties.markwon.movement.MovementMethodPlugin; -import io.noties.markwon.simple.ext.SimpleExtPlugin; import me.saket.bettermovementmethod.BetterLinkMovementMethod; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.Rule; @@ -41,6 +40,7 @@ public class RulesRecyclerViewAdapter extends RecyclerView.Adapter<RulesRecycler public RulesRecyclerViewAdapter(AppCompatActivity activity, CustomThemeWrapper customThemeWrapper) { markwon = Markwon.builder(activity) + .usePlugin(HtmlPlugin.create()) .usePlugin(new AbstractMarkwonPlugin() { @Override public void configureConfiguration(@NonNull MarkwonConfiguration.Builder builder) { @@ -69,12 +69,6 @@ public class RulesRecyclerViewAdapter extends RecyclerView.Adapter<RulesRecycler }))) .usePlugin(LinkifyPlugin.create(Linkify.WEB_URLS)) .usePlugin(StrikethroughPlugin.create()) - .usePlugin(SimpleExtPlugin.create(plugin -> - plugin.addExtension(1, '^', (configuration, props) -> { - return new SuperscriptSpan(); - }) - ) - ) .build(); mPrimaryTextColor = customThemeWrapper.getPrimaryTextColor(); mSecondaryTextColor = customThemeWrapper.getSecondaryTextColor(); 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 0e76c543..7297cb54 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SidebarFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SidebarFragment.java @@ -7,7 +7,6 @@ import android.net.Uri; import android.os.Bundle; import android.os.Handler; import android.text.Spanned; -import android.text.style.SuperscriptSpan; import android.text.util.Linkify; import android.view.LayoutInflater; import android.view.View; @@ -36,12 +35,12 @@ 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.linkify.LinkifyPlugin; import io.noties.markwon.movement.MovementMethodPlugin; import io.noties.markwon.recycler.MarkwonAdapter; import io.noties.markwon.recycler.table.TableEntry; import io.noties.markwon.recycler.table.TableEntryPlugin; -import io.noties.markwon.simple.ext.SimpleExtPlugin; import me.saket.bettermovementmethod.BetterLinkMovementMethod; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; @@ -103,6 +102,7 @@ public class SidebarFragment extends Fragment { markdownColor = mCustomThemeWrapper.getSecondaryTextColor(); Markwon markwon = Markwon.builder(activity) + .usePlugin(HtmlPlugin.create()) .usePlugin(new AbstractMarkwonPlugin() { @Override public void beforeSetText(@NonNull TextView textView, @NonNull Spanned markdown) { @@ -134,12 +134,6 @@ public class SidebarFragment extends Fragment { return true; }))) .usePlugin(LinkifyPlugin.create(Linkify.WEB_URLS)) - .usePlugin(SimpleExtPlugin.create(plugin -> - plugin.addExtension(1, '^', (configuration, props) -> { - return new SuperscriptSpan(); - }) - ) - ) .usePlugin(TableEntryPlugin.create(activity)) .build(); MarkwonAdapter markwonAdapter = MarkwonAdapter.builder(R.layout.adapter_default_entry, R.id.text) 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 de048168..f7a7d247 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java @@ -52,57 +52,42 @@ public class Utils { return fixSuperScript(regexed); } - public static String fixSuperScript(StringBuilder regexed) { - int newestCaretIndex = regexed.indexOf("^"); - if (newestCaretIndex >= 0) { - boolean hasBracket = false; - int caretWithLeftBracketIndex = -1; - for (int i = newestCaretIndex + 1; i < regexed.length(); i++) { - char currentChar = regexed.charAt(i); - if (currentChar == '^') { - if (!(i > 0 && regexed.charAt(i - 1) == '\\')) { - if (newestCaretIndex < 0) { - newestCaretIndex = i; - } else { - regexed.insert(i, '^'); - newestCaretIndex = i + 1; - i++; - if (newestCaretIndex == regexed.length() - 1) { - regexed.deleteCharAt(regexed.length() - 1); - newestCaretIndex = -1; - break; - } - } - } - } else if (currentChar == ' ' || currentChar == '\n') { - if (newestCaretIndex >= 0) { - if (i != newestCaretIndex + 1) { - regexed.insert(i, '^'); - newestCaretIndex = -1; - i++; - } else { - newestCaretIndex = -1; - } - } - } else if (currentChar == '(') { - if (newestCaretIndex >= 0 && i == newestCaretIndex + 1) { + private static String fixSuperScript(StringBuilder regexed) { + boolean hasBracket = false; + int nCarets = 0; + for (int i = 0; i < regexed.length(); i++) { + char currentChar = regexed.charAt(i); + if (currentChar == '^') { + if (!(i > 0 && regexed.charAt(i - 1) == '\\')) { + if (i < regexed.length() - 1 && regexed.charAt(i + 1) == '(') { + regexed.replace(i, i + 2, "<sup>"); hasBracket = true; - newestCaretIndex = -1; - caretWithLeftBracketIndex = i - 1; - } - } else if (currentChar == ')') { - if (hasBracket) { - hasBracket = false; - regexed.setCharAt(i, '^'); - regexed.replace(caretWithLeftBracketIndex, caretWithLeftBracketIndex + 2, "^"); - caretWithLeftBracketIndex = -1; - i--; + } else { + regexed.replace(i, i + 1, "<sup>"); } + nCarets++; } + } else if (currentChar == ')' && hasBracket) { + hasBracket = false; + regexed.replace(i, i + 1, "</sup>"); + nCarets--; + } else if (currentChar == '\n') { + hasBracket = false; + for (int j = 0; j < nCarets; j++) { + regexed.insert(i, "</sup>"); + i += 6; + } + nCarets = 0; + } else if (currentChar == ' ' && !hasBracket) { + for (int j = 0; j < nCarets; j++) { + regexed.insert(i, "</sup>"); + i += 6; + } + nCarets = 0; } - if (newestCaretIndex >=0 || caretWithLeftBracketIndex >= 0) { - regexed.insert(regexed.length(), '^'); - } + } + for (int j = 0; j < nCarets; j++) { + regexed.append("</sup>"); } return regexed.toString(); |