mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-11-10 20:57:25 +01:00
Support inline gif in comments.
This commit is contained in:
parent
98a66a8bb7
commit
bedcf6d0b6
@ -140,7 +140,7 @@ public class ParseComment {
|
|||||||
String distinguished = singleCommentData.getString(JSONUtils.DISTINGUISHED_KEY);
|
String distinguished = singleCommentData.getString(JSONUtils.DISTINGUISHED_KEY);
|
||||||
String commentMarkdown = "";
|
String commentMarkdown = "";
|
||||||
if (!singleCommentData.isNull(JSONUtils.BODY_KEY)) {
|
if (!singleCommentData.isNull(JSONUtils.BODY_KEY)) {
|
||||||
commentMarkdown = Utils.modifyMarkdown(singleCommentData.getString(JSONUtils.BODY_KEY).trim());
|
commentMarkdown = Utils.parseInlineGifInComments(Utils.modifyMarkdown(singleCommentData.getString(JSONUtils.BODY_KEY).trim()));
|
||||||
}
|
}
|
||||||
String commentRawText = Utils.trimTrailingWhitespace(
|
String commentRawText = Utils.trimTrailingWhitespace(
|
||||||
Html.fromHtml(singleCommentData.getString(JSONUtils.BODY_HTML_KEY))).toString();
|
Html.fromHtml(singleCommentData.getString(JSONUtils.BODY_HTML_KEY))).toString();
|
||||||
|
@ -22,6 +22,8 @@ import androidx.core.text.HtmlCompat;
|
|||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import ml.docilealligator.infinityforreddit.R;
|
import ml.docilealligator.infinityforreddit.R;
|
||||||
import ml.docilealligator.infinityforreddit.SortType;
|
import ml.docilealligator.infinityforreddit.SortType;
|
||||||
@ -93,6 +95,23 @@ public class Utils {
|
|||||||
return regexed.toString();
|
return regexed.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String parseInlineGifInComments(String markdown) {
|
||||||
|
StringBuilder markdownStringBuilder = new StringBuilder(markdown);
|
||||||
|
Pattern inlineGifPattern = Pattern.compile("!\\[gif]\\(giphy\\|\\w+\\)");
|
||||||
|
Matcher matcher = inlineGifPattern.matcher(markdownStringBuilder);
|
||||||
|
while (matcher.find()) {
|
||||||
|
markdownStringBuilder.replace(matcher.start(), matcher.end(), "[gif](https://media3.giphy.com/media/" + markdownStringBuilder.substring(matcher.start() + "![gif](giphy|".length(), matcher.end() - 1) + "/giphy.mp4)");
|
||||||
|
}
|
||||||
|
|
||||||
|
Pattern inlineGifPattern2 = Pattern.compile("!\\[gif]\\(giphy\\|\\w+\\|downsized\\)");
|
||||||
|
Matcher matcher2 = inlineGifPattern2.matcher(markdownStringBuilder);
|
||||||
|
while (matcher2.find()) {
|
||||||
|
markdownStringBuilder.replace(matcher2.start(), matcher2.end(), "[gif](https://media3.giphy.com/media/" + markdownStringBuilder.substring(matcher2.start() + "![gif](giphy|".length(), matcher2.end() - "|downsized\\)".length()) + "/giphy.mp4)");
|
||||||
|
}
|
||||||
|
|
||||||
|
return markdownStringBuilder.toString();
|
||||||
|
}
|
||||||
|
|
||||||
public static CharSequence trimTrailingWhitespace(CharSequence source) {
|
public static CharSequence trimTrailingWhitespace(CharSequence source) {
|
||||||
|
|
||||||
if(source == null)
|
if(source == null)
|
||||||
|
Loading…
Reference in New Issue
Block a user