Undo superscript parser changes for now (#577)

Undo superscript parser changes
This commit is contained in:
scria1000 2021-12-12 12:51:43 +00:00 committed by GitHub
parent a2c6685dd8
commit c934bc7740
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 233 additions and 264 deletions

View File

@ -153,6 +153,7 @@ dependencies {
implementation "io.noties.markwon:linkify:$markwonVersion" implementation "io.noties.markwon:linkify:$markwonVersion"
implementation "io.noties.markwon:recycler-table:$markwonVersion" implementation "io.noties.markwon:recycler-table:$markwonVersion"
implementation "io.noties.markwon:simple-ext:$markwonVersion" implementation "io.noties.markwon:simple-ext:$markwonVersion"
implementation "io.noties.markwon:html:$markwonVersion"
implementation "io.noties.markwon:inline-parser:$markwonVersion" implementation "io.noties.markwon:inline-parser:$markwonVersion"
implementation 'com.atlassian.commonmark:commonmark-ext-gfm-tables:0.14.0' implementation 'com.atlassian.commonmark:commonmark-ext-gfm-tables:0.14.0'
implementation 'me.saket:better-link-movement-method:2.2.0' implementation 'me.saket:better-link-movement-method:2.2.0'

View File

@ -50,6 +50,8 @@ import io.noties.markwon.Markwon;
import io.noties.markwon.MarkwonConfiguration; import io.noties.markwon.MarkwonConfiguration;
import io.noties.markwon.core.MarkwonTheme; import io.noties.markwon.core.MarkwonTheme;
import io.noties.markwon.ext.strikethrough.StrikethroughPlugin; 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.AutolinkInlineProcessor; import io.noties.markwon.inlineparser.AutolinkInlineProcessor;
import io.noties.markwon.inlineparser.BangInlineProcessor; import io.noties.markwon.inlineparser.BangInlineProcessor;
import io.noties.markwon.inlineparser.HtmlInlineProcessor; import io.noties.markwon.inlineparser.HtmlInlineProcessor;
@ -71,7 +73,7 @@ import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed; import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed;
import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent; import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent;
import ml.docilealligator.infinityforreddit.markdown.SpoilerParserPlugin; import ml.docilealligator.infinityforreddit.markdown.SpoilerParserPlugin;
import ml.docilealligator.infinityforreddit.markdown.SuperscriptPlugin; import ml.docilealligator.infinityforreddit.markdown.SuperscriptInlineProcessor;
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
import ml.docilealligator.infinityforreddit.utils.Utils; import ml.docilealligator.infinityforreddit.utils.Utils;
import retrofit2.Retrofit; import retrofit2.Retrofit;
@ -171,13 +173,16 @@ public class CommentActivity extends BaseActivity implements UploadImageEnabledA
plugin.excludeInlineProcessor(AutolinkInlineProcessor.class); plugin.excludeInlineProcessor(AutolinkInlineProcessor.class);
plugin.excludeInlineProcessor(HtmlInlineProcessor.class); plugin.excludeInlineProcessor(HtmlInlineProcessor.class);
plugin.excludeInlineProcessor(BangInlineProcessor.class); plugin.excludeInlineProcessor(BangInlineProcessor.class);
plugin.addInlineProcessor(new SuperscriptInlineProcessor());
}))
.usePlugin(HtmlPlugin.create(plugin -> {
plugin.excludeDefaults(true).addHandler(new SuperScriptHandler());
})) }))
.usePlugin(SuperscriptPlugin.create())
.usePlugin(new AbstractMarkwonPlugin() { .usePlugin(new AbstractMarkwonPlugin() {
@NonNull @NonNull
@Override @Override
public String processMarkdown(@NonNull String markdown) { public String processMarkdown(@NonNull String markdown) {
return super.processMarkdown(markdown); return Utils.fixSuperScript(markdown);
} }
@Override @Override
@ -224,13 +229,16 @@ public class CommentActivity extends BaseActivity implements UploadImageEnabledA
plugin.excludeInlineProcessor(AutolinkInlineProcessor.class); plugin.excludeInlineProcessor(AutolinkInlineProcessor.class);
plugin.excludeInlineProcessor(HtmlInlineProcessor.class); plugin.excludeInlineProcessor(HtmlInlineProcessor.class);
plugin.excludeInlineProcessor(BangInlineProcessor.class); plugin.excludeInlineProcessor(BangInlineProcessor.class);
plugin.addInlineProcessor(new SuperscriptInlineProcessor());
}))
.usePlugin(HtmlPlugin.create(plugin -> {
plugin.excludeDefaults(true).addHandler(new SuperScriptHandler());
})) }))
.usePlugin(SuperscriptPlugin.create())
.usePlugin(new AbstractMarkwonPlugin() { .usePlugin(new AbstractMarkwonPlugin() {
@NonNull @NonNull
@Override @Override
public String processMarkdown(@NonNull String markdown) { public String processMarkdown(@NonNull String markdown) {
return super.processMarkdown(markdown); return Utils.fixSuperScript(markdown);
} }
@Override @Override

View File

@ -3,10 +3,14 @@ package ml.docilealligator.infinityforreddit.activities;
import android.app.Activity; import android.app.Activity;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.graphics.Color;
import android.net.Uri; import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.text.SpannableStringBuilder;
import android.text.Spanned; import android.text.Spanned;
import android.text.TextPaint;
import android.text.style.ClickableSpan;
import android.text.util.Linkify; import android.text.util.Linkify;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
@ -29,6 +33,9 @@ import org.commonmark.ext.gfm.tables.TableBlock;
import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.Subscribe;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
@ -39,6 +46,8 @@ import io.noties.markwon.Markwon;
import io.noties.markwon.MarkwonConfiguration; import io.noties.markwon.MarkwonConfiguration;
import io.noties.markwon.core.MarkwonTheme; import io.noties.markwon.core.MarkwonTheme;
import io.noties.markwon.ext.strikethrough.StrikethroughPlugin; 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.AutolinkInlineProcessor; import io.noties.markwon.inlineparser.AutolinkInlineProcessor;
import io.noties.markwon.inlineparser.BangInlineProcessor; import io.noties.markwon.inlineparser.BangInlineProcessor;
import io.noties.markwon.inlineparser.HtmlInlineProcessor; import io.noties.markwon.inlineparser.HtmlInlineProcessor;
@ -54,8 +63,10 @@ import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFi
import ml.docilealligator.infinityforreddit.customviews.MarkwonLinearLayoutManager; import ml.docilealligator.infinityforreddit.customviews.MarkwonLinearLayoutManager;
import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent; import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent;
import ml.docilealligator.infinityforreddit.markdown.SpoilerParserPlugin; import ml.docilealligator.infinityforreddit.markdown.SpoilerParserPlugin;
import ml.docilealligator.infinityforreddit.markdown.SuperscriptPlugin; import ml.docilealligator.infinityforreddit.markdown.SpoilerSpan;
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
import ml.docilealligator.infinityforreddit.markdown.SuperscriptInlineProcessor;
import ml.docilealligator.infinityforreddit.utils.Utils;
public class FullMarkdownActivity extends BaseActivity { public class FullMarkdownActivity extends BaseActivity {
@ -132,13 +143,16 @@ public class FullMarkdownActivity extends BaseActivity {
plugin.excludeInlineProcessor(AutolinkInlineProcessor.class); plugin.excludeInlineProcessor(AutolinkInlineProcessor.class);
plugin.excludeInlineProcessor(HtmlInlineProcessor.class); plugin.excludeInlineProcessor(HtmlInlineProcessor.class);
plugin.excludeInlineProcessor(BangInlineProcessor.class); plugin.excludeInlineProcessor(BangInlineProcessor.class);
plugin.addInlineProcessor(new SuperscriptInlineProcessor());
}))
.usePlugin(HtmlPlugin.create(plugin -> {
plugin.excludeDefaults(true).addHandler(new SuperScriptHandler());
})) }))
.usePlugin(SuperscriptPlugin.create())
.usePlugin(new AbstractMarkwonPlugin() { .usePlugin(new AbstractMarkwonPlugin() {
@NonNull @NonNull
@Override @Override
public String processMarkdown(@NonNull String markdown) { public String processMarkdown(@NonNull String markdown) {
return super.processMarkdown(markdown); return Utils.fixSuperScript(markdown);
} }
@Override @Override

View File

@ -44,6 +44,8 @@ import io.noties.markwon.Markwon;
import io.noties.markwon.MarkwonConfiguration; import io.noties.markwon.MarkwonConfiguration;
import io.noties.markwon.core.MarkwonTheme; import io.noties.markwon.core.MarkwonTheme;
import io.noties.markwon.ext.strikethrough.StrikethroughPlugin; 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.AutolinkInlineProcessor; import io.noties.markwon.inlineparser.AutolinkInlineProcessor;
import io.noties.markwon.inlineparser.BangInlineProcessor; import io.noties.markwon.inlineparser.BangInlineProcessor;
import io.noties.markwon.inlineparser.HtmlInlineProcessor; import io.noties.markwon.inlineparser.HtmlInlineProcessor;
@ -63,7 +65,7 @@ import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFi
import ml.docilealligator.infinityforreddit.customviews.MarkwonLinearLayoutManager; import ml.docilealligator.infinityforreddit.customviews.MarkwonLinearLayoutManager;
import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent; import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent;
import ml.docilealligator.infinityforreddit.markdown.SpoilerParserPlugin; import ml.docilealligator.infinityforreddit.markdown.SpoilerParserPlugin;
import ml.docilealligator.infinityforreddit.markdown.SuperscriptPlugin; import ml.docilealligator.infinityforreddit.markdown.SuperscriptInlineProcessor;
import ml.docilealligator.infinityforreddit.utils.JSONUtils; import ml.docilealligator.infinityforreddit.utils.JSONUtils;
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
import ml.docilealligator.infinityforreddit.utils.Utils; import ml.docilealligator.infinityforreddit.utils.Utils;
@ -165,13 +167,16 @@ public class WikiActivity extends BaseActivity {
plugin.excludeInlineProcessor(AutolinkInlineProcessor.class); plugin.excludeInlineProcessor(AutolinkInlineProcessor.class);
plugin.excludeInlineProcessor(HtmlInlineProcessor.class); plugin.excludeInlineProcessor(HtmlInlineProcessor.class);
plugin.excludeInlineProcessor(BangInlineProcessor.class); plugin.excludeInlineProcessor(BangInlineProcessor.class);
plugin.addInlineProcessor(new SuperscriptInlineProcessor());
}))
.usePlugin(HtmlPlugin.create(plugin -> {
plugin.excludeDefaults(true).addHandler(new SuperScriptHandler());
})) }))
.usePlugin(SuperscriptPlugin.create())
.usePlugin(new AbstractMarkwonPlugin() { .usePlugin(new AbstractMarkwonPlugin() {
@NonNull @NonNull
@Override @Override
public String processMarkdown(@NonNull String markdown) { public String processMarkdown(@NonNull String markdown) {
return super.processMarkdown(markdown); return Utils.fixSuperScript(markdown);
} }
@Override @Override

View File

@ -3,9 +3,14 @@ package ml.docilealligator.infinityforreddit.adapters;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.res.ColorStateList; import android.content.res.ColorStateList;
import android.graphics.Color;
import android.graphics.PorterDuff; import android.graphics.PorterDuff;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.TextPaint;
import android.text.style.ClickableSpan;
import android.text.util.Linkify; import android.text.util.Linkify;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@ -27,6 +32,8 @@ import androidx.recyclerview.widget.ItemTouchHelper;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import java.util.Locale; import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import butterknife.BindView; import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
@ -35,6 +42,8 @@ import io.noties.markwon.Markwon;
import io.noties.markwon.MarkwonConfiguration; import io.noties.markwon.MarkwonConfiguration;
import io.noties.markwon.core.MarkwonTheme; import io.noties.markwon.core.MarkwonTheme;
import io.noties.markwon.ext.strikethrough.StrikethroughPlugin; 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.AutolinkInlineProcessor; import io.noties.markwon.inlineparser.AutolinkInlineProcessor;
import io.noties.markwon.inlineparser.BangInlineProcessor; import io.noties.markwon.inlineparser.BangInlineProcessor;
import io.noties.markwon.inlineparser.HtmlInlineProcessor; import io.noties.markwon.inlineparser.HtmlInlineProcessor;
@ -56,9 +65,10 @@ import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.customviews.CommentIndentationView; import ml.docilealligator.infinityforreddit.customviews.CommentIndentationView;
import ml.docilealligator.infinityforreddit.customviews.SpoilerOnClickTextView; import ml.docilealligator.infinityforreddit.customviews.SpoilerOnClickTextView;
import ml.docilealligator.infinityforreddit.markdown.SpoilerParserPlugin; import ml.docilealligator.infinityforreddit.markdown.SpoilerParserPlugin;
import ml.docilealligator.infinityforreddit.markdown.SuperscriptPlugin; import ml.docilealligator.infinityforreddit.markdown.SpoilerSpan;
import ml.docilealligator.infinityforreddit.utils.APIUtils; import ml.docilealligator.infinityforreddit.utils.APIUtils;
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
import ml.docilealligator.infinityforreddit.markdown.SuperscriptInlineProcessor;
import ml.docilealligator.infinityforreddit.utils.Utils; import ml.docilealligator.infinityforreddit.utils.Utils;
import retrofit2.Retrofit; import retrofit2.Retrofit;
@ -118,13 +128,16 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
plugin.excludeInlineProcessor(AutolinkInlineProcessor.class); plugin.excludeInlineProcessor(AutolinkInlineProcessor.class);
plugin.excludeInlineProcessor(HtmlInlineProcessor.class); plugin.excludeInlineProcessor(HtmlInlineProcessor.class);
plugin.excludeInlineProcessor(BangInlineProcessor.class); plugin.excludeInlineProcessor(BangInlineProcessor.class);
plugin.addInlineProcessor(new SuperscriptInlineProcessor());
}))
.usePlugin(HtmlPlugin.create(plugin -> {
plugin.excludeDefaults(true).addHandler(new SuperScriptHandler());
})) }))
.usePlugin(SuperscriptPlugin.create())
.usePlugin(new AbstractMarkwonPlugin() { .usePlugin(new AbstractMarkwonPlugin() {
@NonNull @NonNull
@Override @Override
public String processMarkdown(@NonNull String markdown) { public String processMarkdown(@NonNull String markdown) {
return super.processMarkdown(markdown); return Utils.fixSuperScript(markdown);
} }
@Override @Override

View File

@ -42,7 +42,10 @@ import io.noties.markwon.Markwon;
import io.noties.markwon.MarkwonConfiguration; import io.noties.markwon.MarkwonConfiguration;
import io.noties.markwon.core.MarkwonTheme; import io.noties.markwon.core.MarkwonTheme;
import io.noties.markwon.ext.strikethrough.StrikethroughPlugin; 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.AutolinkInlineProcessor; import io.noties.markwon.inlineparser.AutolinkInlineProcessor;
import io.noties.markwon.inlineparser.BackslashInlineProcessor;
import io.noties.markwon.inlineparser.BangInlineProcessor; import io.noties.markwon.inlineparser.BangInlineProcessor;
import io.noties.markwon.inlineparser.HtmlInlineProcessor; import io.noties.markwon.inlineparser.HtmlInlineProcessor;
import io.noties.markwon.inlineparser.MarkwonInlineParserPlugin; import io.noties.markwon.inlineparser.MarkwonInlineParserPlugin;
@ -65,7 +68,7 @@ import ml.docilealligator.infinityforreddit.customviews.CommentIndentationView;
import ml.docilealligator.infinityforreddit.customviews.SpoilerOnClickTextView; import ml.docilealligator.infinityforreddit.customviews.SpoilerOnClickTextView;
import ml.docilealligator.infinityforreddit.fragments.ViewPostDetailFragment; import ml.docilealligator.infinityforreddit.fragments.ViewPostDetailFragment;
import ml.docilealligator.infinityforreddit.markdown.SpoilerParserPlugin; import ml.docilealligator.infinityforreddit.markdown.SpoilerParserPlugin;
import ml.docilealligator.infinityforreddit.markdown.SuperscriptPlugin; import ml.docilealligator.infinityforreddit.markdown.SuperscriptInlineProcessor;
import ml.docilealligator.infinityforreddit.post.Post; import ml.docilealligator.infinityforreddit.post.Post;
import ml.docilealligator.infinityforreddit.utils.APIUtils; import ml.docilealligator.infinityforreddit.utils.APIUtils;
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
@ -164,13 +167,16 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
plugin.excludeInlineProcessor(AutolinkInlineProcessor.class); plugin.excludeInlineProcessor(AutolinkInlineProcessor.class);
plugin.excludeInlineProcessor(HtmlInlineProcessor.class); plugin.excludeInlineProcessor(HtmlInlineProcessor.class);
plugin.excludeInlineProcessor(BangInlineProcessor.class); plugin.excludeInlineProcessor(BangInlineProcessor.class);
plugin.addInlineProcessor(new SuperscriptInlineProcessor());
}))
.usePlugin(HtmlPlugin.create(plugin -> {
plugin.excludeDefaults(true).addHandler(new SuperScriptHandler());
})) }))
.usePlugin(SuperscriptPlugin.create())
.usePlugin(new AbstractMarkwonPlugin() { .usePlugin(new AbstractMarkwonPlugin() {
@NonNull @NonNull
@Override @Override
public String processMarkdown(@NonNull String markdown) { public String processMarkdown(@NonNull String markdown) {
return super.processMarkdown(markdown); return Utils.fixSuperScript(markdown);
} }
@Override @Override

View File

@ -3,8 +3,13 @@ package ml.docilealligator.infinityforreddit.adapters;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.res.ColorStateList; import android.content.res.ColorStateList;
import android.graphics.Color;
import android.net.Uri; import android.net.Uri;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.TextPaint;
import android.text.method.LinkMovementMethod; import android.text.method.LinkMovementMethod;
import android.text.style.ClickableSpan;
import android.text.util.Linkify; import android.text.util.Linkify;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@ -19,6 +24,8 @@ import androidx.recyclerview.widget.DiffUtil;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import butterknife.BindView; import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
@ -27,6 +34,8 @@ import io.noties.markwon.Markwon;
import io.noties.markwon.MarkwonConfiguration; import io.noties.markwon.MarkwonConfiguration;
import io.noties.markwon.core.MarkwonTheme; import io.noties.markwon.core.MarkwonTheme;
import io.noties.markwon.ext.strikethrough.StrikethroughPlugin; 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.AutolinkInlineProcessor; import io.noties.markwon.inlineparser.AutolinkInlineProcessor;
import io.noties.markwon.inlineparser.BangInlineProcessor; import io.noties.markwon.inlineparser.BangInlineProcessor;
import io.noties.markwon.inlineparser.HtmlInlineProcessor; import io.noties.markwon.inlineparser.HtmlInlineProcessor;
@ -39,10 +48,12 @@ import ml.docilealligator.infinityforreddit.activities.ViewPrivateMessagesActivi
import ml.docilealligator.infinityforreddit.activities.ViewUserDetailActivity; import ml.docilealligator.infinityforreddit.activities.ViewUserDetailActivity;
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.markdown.SpoilerParserPlugin; import ml.docilealligator.infinityforreddit.markdown.SpoilerParserPlugin;
import ml.docilealligator.infinityforreddit.markdown.SuperscriptPlugin; import ml.docilealligator.infinityforreddit.markdown.SpoilerSpan;
import ml.docilealligator.infinityforreddit.message.FetchMessage; import ml.docilealligator.infinityforreddit.message.FetchMessage;
import ml.docilealligator.infinityforreddit.message.Message; import ml.docilealligator.infinityforreddit.message.Message;
import ml.docilealligator.infinityforreddit.message.ReadMessage; import ml.docilealligator.infinityforreddit.message.ReadMessage;
import ml.docilealligator.infinityforreddit.markdown.SuperscriptInlineProcessor;
import ml.docilealligator.infinityforreddit.utils.Utils;
import retrofit2.Retrofit; import retrofit2.Retrofit;
public class MessageRecyclerViewAdapter extends PagedListAdapter<Message, RecyclerView.ViewHolder> { public class MessageRecyclerViewAdapter extends PagedListAdapter<Message, RecyclerView.ViewHolder> {
@ -101,13 +112,16 @@ public class MessageRecyclerViewAdapter extends PagedListAdapter<Message, Recycl
plugin.excludeInlineProcessor(AutolinkInlineProcessor.class); plugin.excludeInlineProcessor(AutolinkInlineProcessor.class);
plugin.excludeInlineProcessor(HtmlInlineProcessor.class); plugin.excludeInlineProcessor(HtmlInlineProcessor.class);
plugin.excludeInlineProcessor(BangInlineProcessor.class); plugin.excludeInlineProcessor(BangInlineProcessor.class);
plugin.addInlineProcessor(new SuperscriptInlineProcessor());
}))
.usePlugin(HtmlPlugin.create(plugin -> {
plugin.excludeDefaults(true).addHandler(new SuperScriptHandler());
})) }))
.usePlugin(SuperscriptPlugin.create())
.usePlugin(new AbstractMarkwonPlugin() { .usePlugin(new AbstractMarkwonPlugin() {
@NonNull @NonNull
@Override @Override
public String processMarkdown(@NonNull String markdown) { public String processMarkdown(@NonNull String markdown) {
return super.processMarkdown(markdown); return Utils.fixSuperScript(markdown);
} }
@Override @Override

View File

@ -67,6 +67,8 @@ import io.noties.markwon.Markwon;
import io.noties.markwon.MarkwonConfiguration; import io.noties.markwon.MarkwonConfiguration;
import io.noties.markwon.core.MarkwonTheme; import io.noties.markwon.core.MarkwonTheme;
import io.noties.markwon.ext.strikethrough.StrikethroughPlugin; 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.AutolinkInlineProcessor; import io.noties.markwon.inlineparser.AutolinkInlineProcessor;
import io.noties.markwon.inlineparser.BangInlineProcessor; import io.noties.markwon.inlineparser.BangInlineProcessor;
import io.noties.markwon.inlineparser.HtmlInlineProcessor; import io.noties.markwon.inlineparser.HtmlInlineProcessor;
@ -105,7 +107,7 @@ import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFi
import ml.docilealligator.infinityforreddit.customviews.MarkwonLinearLayoutManager; import ml.docilealligator.infinityforreddit.customviews.MarkwonLinearLayoutManager;
import ml.docilealligator.infinityforreddit.fragments.ViewPostDetailFragment; import ml.docilealligator.infinityforreddit.fragments.ViewPostDetailFragment;
import ml.docilealligator.infinityforreddit.markdown.SpoilerParserPlugin; import ml.docilealligator.infinityforreddit.markdown.SpoilerParserPlugin;
import ml.docilealligator.infinityforreddit.markdown.SuperscriptPlugin; import ml.docilealligator.infinityforreddit.markdown.SuperscriptInlineProcessor;
import ml.docilealligator.infinityforreddit.post.Post; import ml.docilealligator.infinityforreddit.post.Post;
import ml.docilealligator.infinityforreddit.post.PostPagingSource; import ml.docilealligator.infinityforreddit.post.PostPagingSource;
import ml.docilealligator.infinityforreddit.utils.APIUtils; import ml.docilealligator.infinityforreddit.utils.APIUtils;
@ -229,13 +231,16 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
plugin.excludeInlineProcessor(AutolinkInlineProcessor.class); plugin.excludeInlineProcessor(AutolinkInlineProcessor.class);
plugin.excludeInlineProcessor(HtmlInlineProcessor.class); plugin.excludeInlineProcessor(HtmlInlineProcessor.class);
plugin.excludeInlineProcessor(BangInlineProcessor.class); plugin.excludeInlineProcessor(BangInlineProcessor.class);
plugin.addInlineProcessor(new SuperscriptInlineProcessor());
}))
.usePlugin(HtmlPlugin.create(plugin -> {
plugin.excludeDefaults(true).addHandler(new SuperScriptHandler());
})) }))
.usePlugin(SuperscriptPlugin.create())
.usePlugin(new AbstractMarkwonPlugin() { .usePlugin(new AbstractMarkwonPlugin() {
@NonNull @NonNull
@Override @Override
public String processMarkdown(@NonNull String markdown) { public String processMarkdown(@NonNull String markdown) {
return super.processMarkdown(markdown); return Utils.fixSuperScript(markdown);
} }
@Override @Override

View File

@ -27,6 +27,8 @@ import io.noties.markwon.Markwon;
import io.noties.markwon.MarkwonConfiguration; import io.noties.markwon.MarkwonConfiguration;
import io.noties.markwon.core.MarkwonTheme; import io.noties.markwon.core.MarkwonTheme;
import io.noties.markwon.ext.strikethrough.StrikethroughPlugin; 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.AutolinkInlineProcessor; import io.noties.markwon.inlineparser.AutolinkInlineProcessor;
import io.noties.markwon.inlineparser.BangInlineProcessor; import io.noties.markwon.inlineparser.BangInlineProcessor;
import io.noties.markwon.inlineparser.HtmlInlineProcessor; import io.noties.markwon.inlineparser.HtmlInlineProcessor;
@ -38,9 +40,9 @@ import ml.docilealligator.infinityforreddit.activities.LinkResolverActivity;
import ml.docilealligator.infinityforreddit.activities.ViewPrivateMessagesActivity; import ml.docilealligator.infinityforreddit.activities.ViewPrivateMessagesActivity;
import ml.docilealligator.infinityforreddit.activities.ViewUserDetailActivity; import ml.docilealligator.infinityforreddit.activities.ViewUserDetailActivity;
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.markdown.SuperscriptPlugin;
import ml.docilealligator.infinityforreddit.message.Message; import ml.docilealligator.infinityforreddit.message.Message;
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
import ml.docilealligator.infinityforreddit.markdown.SuperscriptInlineProcessor;
import ml.docilealligator.infinityforreddit.utils.Utils; import ml.docilealligator.infinityforreddit.utils.Utils;
public class PrivateMessagesDetailRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { public class PrivateMessagesDetailRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
@ -74,13 +76,16 @@ public class PrivateMessagesDetailRecyclerViewAdapter extends RecyclerView.Adapt
plugin.excludeInlineProcessor(AutolinkInlineProcessor.class); plugin.excludeInlineProcessor(AutolinkInlineProcessor.class);
plugin.excludeInlineProcessor(HtmlInlineProcessor.class); plugin.excludeInlineProcessor(HtmlInlineProcessor.class);
plugin.excludeInlineProcessor(BangInlineProcessor.class); plugin.excludeInlineProcessor(BangInlineProcessor.class);
plugin.addInlineProcessor(new SuperscriptInlineProcessor());
}))
.usePlugin(HtmlPlugin.create(plugin -> {
plugin.excludeDefaults(true).addHandler(new SuperScriptHandler());
})) }))
.usePlugin(SuperscriptPlugin.create())
.usePlugin(new AbstractMarkwonPlugin() { .usePlugin(new AbstractMarkwonPlugin() {
@NonNull @NonNull
@Override @Override
public String processMarkdown(@NonNull String markdown) { public String processMarkdown(@NonNull String markdown) {
return super.processMarkdown(markdown); return Utils.fixSuperScript(markdown);
} }
@Override @Override

View File

@ -22,6 +22,8 @@ import io.noties.markwon.Markwon;
import io.noties.markwon.MarkwonConfiguration; import io.noties.markwon.MarkwonConfiguration;
import io.noties.markwon.core.MarkwonTheme; import io.noties.markwon.core.MarkwonTheme;
import io.noties.markwon.ext.strikethrough.StrikethroughPlugin; 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.AutolinkInlineProcessor; import io.noties.markwon.inlineparser.AutolinkInlineProcessor;
import io.noties.markwon.inlineparser.BangInlineProcessor; import io.noties.markwon.inlineparser.BangInlineProcessor;
import io.noties.markwon.inlineparser.HtmlInlineProcessor; import io.noties.markwon.inlineparser.HtmlInlineProcessor;
@ -34,7 +36,8 @@ import ml.docilealligator.infinityforreddit.Rule;
import ml.docilealligator.infinityforreddit.activities.LinkResolverActivity; import ml.docilealligator.infinityforreddit.activities.LinkResolverActivity;
import ml.docilealligator.infinityforreddit.bottomsheetfragments.UrlMenuBottomSheetFragment; import ml.docilealligator.infinityforreddit.bottomsheetfragments.UrlMenuBottomSheetFragment;
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.markdown.SuperscriptPlugin; import ml.docilealligator.infinityforreddit.markdown.SuperscriptInlineProcessor;
import ml.docilealligator.infinityforreddit.utils.Utils;
public class RulesRecyclerViewAdapter extends RecyclerView.Adapter<RulesRecyclerViewAdapter.RuleViewHolder> { public class RulesRecyclerViewAdapter extends RecyclerView.Adapter<RulesRecyclerViewAdapter.RuleViewHolder> {
private Markwon markwon; private Markwon markwon;
@ -48,13 +51,16 @@ public class RulesRecyclerViewAdapter extends RecyclerView.Adapter<RulesRecycler
plugin.excludeInlineProcessor(AutolinkInlineProcessor.class); plugin.excludeInlineProcessor(AutolinkInlineProcessor.class);
plugin.excludeInlineProcessor(HtmlInlineProcessor.class); plugin.excludeInlineProcessor(HtmlInlineProcessor.class);
plugin.excludeInlineProcessor(BangInlineProcessor.class); plugin.excludeInlineProcessor(BangInlineProcessor.class);
plugin.addInlineProcessor(new SuperscriptInlineProcessor());
}))
.usePlugin(HtmlPlugin.create(plugin -> {
plugin.excludeDefaults(true).addHandler(new SuperScriptHandler());
})) }))
.usePlugin(SuperscriptPlugin.create())
.usePlugin(new AbstractMarkwonPlugin() { .usePlugin(new AbstractMarkwonPlugin() {
@NonNull @NonNull
@Override @Override
public String processMarkdown(@NonNull String markdown) { public String processMarkdown(@NonNull String markdown) {
return super.processMarkdown(markdown); return Utils.fixSuperScript(markdown);
} }
@Override @Override

View File

@ -34,6 +34,8 @@ import io.noties.markwon.Markwon;
import io.noties.markwon.MarkwonConfiguration; import io.noties.markwon.MarkwonConfiguration;
import io.noties.markwon.core.MarkwonTheme; import io.noties.markwon.core.MarkwonTheme;
import io.noties.markwon.ext.strikethrough.StrikethroughPlugin; 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.AutolinkInlineProcessor; import io.noties.markwon.inlineparser.AutolinkInlineProcessor;
import io.noties.markwon.inlineparser.BangInlineProcessor; import io.noties.markwon.inlineparser.BangInlineProcessor;
import io.noties.markwon.inlineparser.HtmlInlineProcessor; import io.noties.markwon.inlineparser.HtmlInlineProcessor;
@ -54,10 +56,11 @@ import ml.docilealligator.infinityforreddit.bottomsheetfragments.CopyTextBottomS
import ml.docilealligator.infinityforreddit.bottomsheetfragments.UrlMenuBottomSheetFragment; import ml.docilealligator.infinityforreddit.bottomsheetfragments.UrlMenuBottomSheetFragment;
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed; import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed;
import ml.docilealligator.infinityforreddit.markdown.SuperscriptPlugin;
import ml.docilealligator.infinityforreddit.subreddit.FetchSubredditData; import ml.docilealligator.infinityforreddit.subreddit.FetchSubredditData;
import ml.docilealligator.infinityforreddit.subreddit.SubredditData; import ml.docilealligator.infinityforreddit.subreddit.SubredditData;
import ml.docilealligator.infinityforreddit.subreddit.SubredditViewModel; import ml.docilealligator.infinityforreddit.subreddit.SubredditViewModel;
import ml.docilealligator.infinityforreddit.markdown.SuperscriptInlineProcessor;
import ml.docilealligator.infinityforreddit.utils.Utils;
import retrofit2.Retrofit; import retrofit2.Retrofit;
public class SidebarFragment extends Fragment { public class SidebarFragment extends Fragment {
@ -112,13 +115,16 @@ public class SidebarFragment extends Fragment {
plugin.excludeInlineProcessor(AutolinkInlineProcessor.class); plugin.excludeInlineProcessor(AutolinkInlineProcessor.class);
plugin.excludeInlineProcessor(HtmlInlineProcessor.class); plugin.excludeInlineProcessor(HtmlInlineProcessor.class);
plugin.excludeInlineProcessor(BangInlineProcessor.class); plugin.excludeInlineProcessor(BangInlineProcessor.class);
plugin.addInlineProcessor(new SuperscriptInlineProcessor());
}))
.usePlugin(HtmlPlugin.create(plugin -> {
plugin.excludeDefaults(true).addHandler(new SuperScriptHandler());
})) }))
.usePlugin(SuperscriptPlugin.create())
.usePlugin(new AbstractMarkwonPlugin() { .usePlugin(new AbstractMarkwonPlugin() {
@NonNull @NonNull
@Override @Override
public String processMarkdown(@NonNull String markdown) { public String processMarkdown(@NonNull String markdown) {
return super.processMarkdown(markdown); return Utils.fixSuperScript(markdown);
} }
@Override @Override

View File

@ -5,6 +5,7 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.net.Uri; import android.net.Uri;
import android.os.Build; import android.os.Build;
@ -309,6 +310,7 @@ public class ViewRedditGalleryImageOrGifFragment extends Fragment {
return true; return true;
}); });
captionUrlTextView.setVisibility(View.VISIBLE); captionUrlTextView.setVisibility(View.VISIBLE);
captionUrlTextView.setHighlightColor(Color.TRANSPARENT);
} }
} }

View File

@ -70,19 +70,19 @@ public class SpoilerParserPlugin extends AbstractMarkwonPlugin {
@Override @Override
public void afterSetText(@NonNull TextView textView) { public void afterSetText(@NonNull TextView textView) {
textView.setHighlightColor(Color.TRANSPARENT);
if (!textHasSpoiler || textView.getText().length() < 5) { if (!textHasSpoiler || textView.getText().length() < 5) {
firstSpoilerStart = 0; firstSpoilerStart = 0;
return; return;
} }
textView.setHighlightColor(Color.TRANSPARENT);
SpannableStringBuilder markdownStringBuilder = new SpannableStringBuilder(textView.getText()); SpannableStringBuilder markdownStringBuilder = new SpannableStringBuilder(textView.getText());
ArrayList<Pair<Integer, Integer>> spoilers = parse(markdownStringBuilder, firstSpoilerStart); ArrayList<Pair<Integer, Integer>> spoilers = parse(markdownStringBuilder, firstSpoilerStart);
firstSpoilerStart = 0; firstSpoilerStart = 0;
textHasSpoiler = false; // Since PostDetail can contain multiple TextViews, we do this here
if (spoilers.size() == 0) { if (spoilers.size() == 0) {
textHasSpoiler = false;
return; return;
} }

View File

@ -1,25 +0,0 @@
package ml.docilealligator.infinityforreddit.markdown;
import android.text.TextPaint;
import android.text.style.MetricAffectingSpan;
import androidx.annotation.NonNull;
public class SuperScriptSpan extends MetricAffectingSpan {
private static final float SCRIPT_DEF_TEXT_SIZE_RATIO = .75F;
@Override
public void updateDrawState(TextPaint tp) {
apply(tp);
}
@Override
public void updateMeasureState(@NonNull TextPaint tp) {
apply(tp);
}
private void apply(TextPaint paint) {
paint.setTextSize(paint.getTextSize() * SCRIPT_DEF_TEXT_SIZE_RATIO);
paint.baselineShift += (int) (paint.ascent() / 2);
}
}

View File

@ -1,31 +0,0 @@
package ml.docilealligator.infinityforreddit.markdown;
import org.commonmark.node.CustomNode;
import org.commonmark.node.Visitor;
public class Superscript extends CustomNode {
private String literal;
private int level;
@Override
public void accept(Visitor visitor) {
visitor.visit(this);
}
public String getLiteral() {
return literal;
}
public void setLiteral(String literal) {
this.literal = literal;
}
public int getLevel() {
return level;
}
public void setLevel(int level) {
this.level = level;
}
}

View File

@ -0,0 +1,32 @@
package ml.docilealligator.infinityforreddit.markdown;
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("^</?sup>", 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;
}
}
}

View File

@ -1,116 +0,0 @@
package ml.docilealligator.infinityforreddit.markdown;
import androidx.annotation.Nullable;
import org.commonmark.node.Node;
import io.noties.markwon.inlineparser.InlineProcessor;
public class SuperscriptParser extends InlineProcessor {
private int level = 0;
@Override
public char specialCharacter() {
return '^';
}
@Nullable
@Override
protected Node parse() {
Node node = parseSuperscript(level);
if (node != null) {
return nestSuperscriptNodes(node);
}
level = 0;
return null;
}
private Node nestSuperscriptNodes(Node node) {
if (block.getLastChild() instanceof Superscript
&& peek() != '^') {
var current = block.getLastChild();
current.appendChild(node);
Node tmp = null;
while (true) {
tmp = current;
current = current.getPrevious();
if (current instanceof Superscript) {
current.appendChild(tmp);
} else {
break;
}
}
level = 0;
return tmp;
} else {
level++;
return node;
}
}
// Hopefully we've handled edge cases
private Superscript parseSuperscript(int level) {
int start = index;
int length = input.length();
int caret_pos = -1;
int nCarets = 0;
int new_lines = 0;
boolean hasBracket = false;
for (int i = start; i < length; i++) {
char currentChar = input.charAt(i);
if (currentChar == '\n') {
new_lines++;
if (new_lines > 0 && nCarets > 0 || hasBracket) {
break;
}
} else if ((i + 1) < length
&& nCarets == 0
&& !hasBracket
&& !(i > 0 && input.charAt(i - 1) == '\\')
&& currentChar == '^'
&& !Character.isWhitespace(input.charAt(i + 1))) {
if (input.charAt(i + 1) == '(') {
hasBracket = true;
}
caret_pos = i;
nCarets++;
} else if (nCarets > 0) {
if (hasBracket
&& (i > 0)
&& currentChar == ')'
&& input.charAt(i - 1) != '\\') {
index = i + 1;
Superscript node = new Superscript();
node.setLiteral(input.substring(caret_pos + 2, i));
node.setLevel(level);
return node;
} else if (!hasBracket && Character.isWhitespace(currentChar)) {
index = i;
Superscript node = new Superscript();
node.setLiteral(input.substring(caret_pos + 1, i));
node.setLevel(level);
return node;
} else if (!hasBracket && (i == length - 1)) {
index = i + 1;
Superscript node = new Superscript();
node.setLiteral(input.substring(caret_pos + 1, i + 1));
node.setLevel(level);
return node;
} else if ((i + 1) < length
&& (i > 0)
&& currentChar == '^'
&& input.charAt(i - 1) != '\\'
&& !Character.isWhitespace(input.charAt(i + 1))) {
index = i;
Superscript node = new Superscript();
node.setLiteral(input.substring(caret_pos + 1, i));
node.setLevel(level);
return node;
}
}
}
return null;
}
}

View File

@ -1,38 +0,0 @@
package ml.docilealligator.infinityforreddit.markdown;
import androidx.annotation.NonNull;
import io.noties.markwon.AbstractMarkwonPlugin;
import io.noties.markwon.MarkwonVisitor;
import io.noties.markwon.inlineparser.MarkwonInlineParserPlugin;
public class SuperscriptPlugin extends AbstractMarkwonPlugin {
SuperscriptPlugin() {
}
public static SuperscriptPlugin create() {
return new SuperscriptPlugin();
}
@Override
public void configure(@NonNull Registry registry) {
registry.require(MarkwonInlineParserPlugin.class, plugin ->
plugin.factoryBuilder().addInlineProcessor(new SuperscriptParser()));
}
@Override
public void configureVisitor(@NonNull MarkwonVisitor.Builder builder) {
builder.on(Superscript.class, (visitor, superscript) -> {
if (superscript.getLevel() < 29) { // Arbitrary nesting limit
final int start = visitor.length();
visitor.builder().append(superscript.getLiteral());
visitor.visitChildren(superscript);
visitor.setSpans(start, new SuperScriptSpan());
} else {
visitor.clear();
}
});
}
}

View File

@ -59,8 +59,7 @@ public final class Utils {
private static final long DAY_MILLIS = 24 * HOUR_MILLIS; private static final long DAY_MILLIS = 24 * HOUR_MILLIS;
private static final long MONTH_MILLIS = 30 * DAY_MILLIS; private static final long MONTH_MILLIS = 30 * DAY_MILLIS;
private static final long YEAR_MILLIS = 12 * MONTH_MILLIS; private static final long YEAR_MILLIS = 12 * MONTH_MILLIS;
private static final Pattern[] REGEX_PATTERNS = {
public static final Pattern[] REGEX_PATTERN = {
Pattern.compile("((?<=[\\s])|^)/[rRuU]/[\\w-]+/{0,1}"), Pattern.compile("((?<=[\\s])|^)/[rRuU]/[\\w-]+/{0,1}"),
Pattern.compile("((?<=[\\s])|^)[rRuU]/[\\w-]+/{0,1}"), Pattern.compile("((?<=[\\s])|^)[rRuU]/[\\w-]+/{0,1}"),
Pattern.compile("\\^{2,}"), Pattern.compile("\\^{2,}"),
@ -77,42 +76,102 @@ public final class Utils {
}; };
public static String modifyMarkdown(String markdown) { public static String modifyMarkdown(String markdown) {
String regexed = REGEX_PATTERN[0].matcher(markdown).replaceAll("[$0](https://www.reddit.com$0)"); String regexed = REGEX_PATTERNS[0].matcher(markdown).replaceAll("[$0](https://www.reddit.com$0)");
regexed = REGEX_PATTERN[1].matcher(regexed).replaceAll("[$0](https://www.reddit.com/$0)"); regexed = REGEX_PATTERNS[1].matcher(regexed).replaceAll("[$0](https://www.reddit.com/$0)");
regexed = REGEX_PATTERN[2].matcher(regexed).replaceAll("^"); regexed = REGEX_PATTERNS[2].matcher(regexed).replaceAll("^");
regexed = REGEX_PATTERN[3].matcher(regexed).replaceAll("$0 "); regexed = REGEX_PATTERNS[3].matcher(regexed).replaceAll("$0 ");
regexed = REGEX_PATTERN[4].matcher(regexed).replaceAll("$0 "); regexed = REGEX_PATTERNS[4].matcher(regexed).replaceAll("$0 ");
regexed = REGEX_PATTERN[5].matcher(regexed).replaceAll("$0 "); regexed = REGEX_PATTERNS[5].matcher(regexed).replaceAll("$0 ");
regexed = REGEX_PATTERN[6].matcher(regexed).replaceAll("$0 "); regexed = REGEX_PATTERNS[6].matcher(regexed).replaceAll("$0 ");
regexed = REGEX_PATTERN[7].matcher(regexed).replaceAll("$0 "); regexed = REGEX_PATTERNS[7].matcher(regexed).replaceAll("$0 ");
regexed = REGEX_PATTERN[8].matcher(regexed).replaceAll("$0 "); regexed = REGEX_PATTERNS[8].matcher(regexed).replaceAll("$0 ");
//return fixSuperScript(regexed);
// We don't want to fix super scripts here because we need the original markdown later for editing posts
return regexed; return regexed;
} }
public static String fixSuperScript(String regexedMarkdown) {
StringBuilder regexed = new StringBuilder(regexedMarkdown);
boolean hasBracket = false;
int nCarets = 0;
int new_lines = 0;
for (int i = 0; i < regexed.length(); i++) {
char currentChar = regexed.charAt(i);
if (hasBracket && currentChar == '\n') {
new_lines++;
if (new_lines > 1) {
hasBracket = false;
nCarets = 0;
new_lines = 0;
}
} else if (currentChar == '^') {
if (!(i > 0 && regexed.charAt(i - 1) == '\\')) {
if (nCarets == 0 && i < regexed.length() - 1 && regexed.charAt(i + 1) == '(') {
regexed.replace(i, i + 2, "<sup>");
hasBracket = true;
} else {
regexed.replace(i, i + 1, "<sup>");
}
nCarets++;
}
} else if (hasBracket && currentChar == ')') {
if (i > 0 && regexed.charAt(i - 1) == '\\') {
hasBracket = false;
nCarets--;
continue;
}
hasBracket = false;
regexed.replace(i, i + 1, "</sup>");
nCarets--;
} else if (!hasBracket && currentChar == '\n') {
for (int j = 0; j < nCarets; j++) {
regexed.insert(i, "</sup>");
i += 6;
}
nCarets = 0;
} else if (!hasBracket && Character.isWhitespace(currentChar)) {
for (int j = 0; j < nCarets; j++) {
regexed.insert(i, "</sup>");
i += 6;
}
nCarets = 0;
} else {
new_lines = 0;
}
}
if (!hasBracket) {
for (int j = 0; j < nCarets; j++) {
regexed.append("</sup>");
}
}
return regexed.toString();
}
public static String parseInlineGifInComments(String markdown) { public static String parseInlineGifInComments(String markdown) {
StringBuilder markdownStringBuilder = new StringBuilder(markdown); StringBuilder markdownStringBuilder = new StringBuilder(markdown);
Pattern inlineGifPattern = REGEX_PATTERN[9]; Pattern inlineGifPattern = REGEX_PATTERNS[9];
Matcher matcher = inlineGifPattern.matcher(markdownStringBuilder); Matcher matcher = inlineGifPattern.matcher(markdownStringBuilder);
while (matcher.find()) { while (matcher.find()) {
markdownStringBuilder.replace(matcher.start(), matcher.end(), "[gif](https://i.giphy.com/media/" + markdownStringBuilder.substring(matcher.start() + "![gif](giphy|".length(), matcher.end() - 1) + "/giphy.mp4)"); markdownStringBuilder.replace(matcher.start(), matcher.end(), "[gif](https://i.giphy.com/media/" + markdownStringBuilder.substring(matcher.start() + "![gif](giphy|".length(), matcher.end() - 1) + "/giphy.mp4)");
matcher = inlineGifPattern.matcher(markdownStringBuilder); matcher = inlineGifPattern.matcher(markdownStringBuilder);
} }
Pattern inlineGifPattern2 = REGEX_PATTERN[10]; Pattern inlineGifPattern2 = REGEX_PATTERNS[10];
Matcher matcher2 = inlineGifPattern2.matcher(markdownStringBuilder); Matcher matcher2 = inlineGifPattern2.matcher(markdownStringBuilder);
while (matcher2.find()) { while (matcher2.find()) {
markdownStringBuilder.replace(matcher2.start(), matcher2.end(), "[gif](https://i.giphy.com/media/" + markdownStringBuilder.substring(matcher2.start() + "![gif](giphy|".length(), matcher2.end() - "|downsized\\)".length() + 1) + "/giphy.mp4)"); markdownStringBuilder.replace(matcher2.start(), matcher2.end(), "[gif](https://i.giphy.com/media/" + markdownStringBuilder.substring(matcher2.start() + "![gif](giphy|".length(), matcher2.end() - "|downsized\\)".length() + 1) + "/giphy.mp4)");
matcher2 = inlineGifPattern2.matcher(markdownStringBuilder); matcher2 = inlineGifPattern2.matcher(markdownStringBuilder);
} }
Pattern inlineGifPattern3 = REGEX_PATTERN[11]; Pattern inlineGifPattern3 = REGEX_PATTERNS[11];
Matcher matcher3 = inlineGifPattern3.matcher(markdownStringBuilder); Matcher matcher3 = inlineGifPattern3.matcher(markdownStringBuilder);
while (matcher3.find()) { while (matcher3.find()) {
markdownStringBuilder.replace(matcher3.start(), matcher3.end(), markdownStringBuilder.replace(matcher3.start(), matcher3.end(),
"[gif](https://reddit-meta-production.s3.amazonaws.com/public/fortnitebr/emotes/snoomoji_emotes/" "[gif](https://reddit-meta-production.s3.amazonaws.com/public/fortnitebr/emotes/snoomoji_emotes/"
+ markdownStringBuilder.substring( + markdownStringBuilder.substring(
matcher3.start() + "![gif](emote|".length(), matcher3.end() - 1).replace('|', '/') + ".gif)"); matcher3.start() + "![gif](emote|".length(), matcher3.end() - 1).replace('|', '/') + ".gif)");
matcher3 = inlineGifPattern3.matcher(markdownStringBuilder); matcher3 = inlineGifPattern3.matcher(markdownStringBuilder);
} }
@ -132,7 +191,7 @@ public final class Utils {
i--; i--;
} while (i >= 0 && Character.isWhitespace(source.charAt(i))); } while (i >= 0 && Character.isWhitespace(source.charAt(i)));
return source.subSequence(0, i+1); return source.subSequence(0, i + 1);
} }
public static String getFormattedTime(Locale locale, long time, String pattern) { public static String getFormattedTime(Locale locale, long time, String pattern) {
@ -141,7 +200,7 @@ public final class Utils {
return new SimpleDateFormat(pattern, locale).format(postTimeCalendar.getTime()); return new SimpleDateFormat(pattern, locale).format(postTimeCalendar.getTime());
} }
public static String getElapsedTime(Context context, long time) { public static String getElapsedTime(Context context, long time) {
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
long diff = now - time; long diff = now - time;
@ -205,7 +264,8 @@ public final class Utils {
return NETWORK_TYPE_CELLULAR; return NETWORK_TYPE_CELLULAR;
} }
} }
} catch (SecurityException ignore) {} } catch (SecurityException ignore) {
}
return NETWORK_TYPE_OTHER; return NETWORK_TYPE_OTHER;
} else { } else {
boolean isWifi = false; boolean isWifi = false;
@ -320,7 +380,7 @@ public final class Utils {
public static void uploadImageToReddit(Context context, Executor executor, Retrofit oauthRetrofit, public static void uploadImageToReddit(Context context, Executor executor, Retrofit oauthRetrofit,
Retrofit uploadMediaRetrofit, String accessToken, EditText editText, Retrofit uploadMediaRetrofit, String accessToken, EditText editText,
CoordinatorLayout coordinatorLayout, Uri imageUri, CoordinatorLayout coordinatorLayout, Uri imageUri,
ArrayList<UploadedImage>uploadedImages) { ArrayList<UploadedImage> uploadedImages) {
Toast.makeText(context, R.string.uploading_image, Toast.LENGTH_SHORT).show(); Toast.makeText(context, R.string.uploading_image, Toast.LENGTH_SHORT).show();
Handler handler = new Handler(); Handler handler = new Handler();
executor.execute(() -> { executor.execute(() -> {

View File

@ -74,6 +74,8 @@
<item name="android:textSize">?attr/font_default</item> <item name="android:textSize">?attr/font_default</item>
<item name="materialAlertDialogTitleTextStyle">@style/MaterialAlertDialogTitleTextStyle <item name="materialAlertDialogTitleTextStyle">@style/MaterialAlertDialogTitleTextStyle
</item> </item>
<item name="buttonBarPositiveButtonStyle">@style/MaterialAlertDialogPositiveButtonStyle
</item>
<item name="buttonBarNegativeButtonStyle">@style/MaterialAlertDialogNegativeButtonStyle <item name="buttonBarNegativeButtonStyle">@style/MaterialAlertDialogNegativeButtonStyle
</item> </item>
</style> </style>