Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9f09ceff authored by Stefan Niedermann's avatar Stefan Niedermann
Browse files

Use checkbox-emoji-replacement also in title and excerpt

parent 279a977e
Loading
Loading
Loading
Loading
+0 −40
Original line number Diff line number Diff line
package android.text;

import androidx.annotation.Nullable;

import java.util.Iterator;

public class TextUtils {

    /**
     * Returns a string containing the tokens joined by delimiters.
     *
     * @param delimiter a CharSequence that will be inserted between the tokens. If null, the string
     *     "null" will be used as the delimiter.
     * @param tokens an array objects to be joined. Strings will be formed from the objects by
     *     calling object.toString(). If tokens is null, a NullPointerException will be thrown. If
     *     tokens is empty, an empty string will be returned.
     */
    public static String join(CharSequence delimiter, Iterable<?> tokens) {
        final Iterator<?> it = tokens.iterator();
        if (!it.hasNext()) {
            return "";
        }
        final StringBuilder sb = new StringBuilder();
        sb.append(it.next());
        while (it.hasNext()) {
            sb.append(delimiter);
            sb.append(it.next());
        }
        return sb.toString();
    }

    /**
     * Returns true if the string is null or 0-length.
     * @param str the string to be examined
     * @return true if str is null or zero length
     */
    public static boolean isEmpty(@Nullable CharSequence str) {
        return str == null || str.length() == 0;
    }
}
+3 −0
Original line number Diff line number Diff line
@@ -660,5 +660,8 @@ public class MarkdownUtilTest extends TestCase {
        assertEquals("Title", MarkdownUtil.removeMarkdown("# Title"));
        assertEquals("Aufzählung", MarkdownUtil.removeMarkdown("* Aufzählung"));
//        assertEquals("Foo Link Bar", MarkdownUtil.removeMarkdown("Foo [Link](https://example.com) Bar"));

        assertFalse(MarkdownUtil.removeMarkdown("- [ ] Test").contains("- [ ]"));
        assertTrue(MarkdownUtil.removeMarkdown("- [ ] Test").endsWith("Test"));
    }
}
 No newline at end of file
+13 −11
Original line number Diff line number Diff line
@@ -75,7 +75,8 @@ public class MarkdownUtil {
        return parseCompat(markdownProcessor, replaceCheckboxesWithEmojis(content));
    }

    private static CharSequence replaceCheckboxesWithEmojis(String content) {
    @NonNull
    private static CharSequence replaceCheckboxesWithEmojis(@NonNull String content) {
        return runForEachCheckbox(content, (line) -> {
            for (EListType listType : EListType.values()) {
                if (checkboxCheckedEmoji != null) {
@@ -116,6 +117,7 @@ public class MarkdownUtil {
    /**
     * Performs the given {@param map} function for each line which contains a checkbox
     */
    @NonNull
    private static CharSequence runForEachCheckbox(@NonNull String markdownString, @NonNull Function<String, String> map) {
        final String[] lines = markdownString.split("\n");
        boolean isInFencedCodeBlock = false;
@@ -432,7 +434,7 @@ public class MarkdownUtil {
    }

    /**
     * Strips all Markdown from the given String
     * Strips all Markdown from {@param s} and replaces checkboxes with emojis.
     *
     * @param s Markdown string
     * @return Plain text string
@@ -441,13 +443,13 @@ public class MarkdownUtil {
    public static String removeMarkdown(@Nullable String s) {
        if (s == null)
            return "";
        String result = s;
        result = PATTERN_LISTS.matcher(result).replaceAll("");
        result = PATTERN_HEADINGS.matcher(result).replaceAll("$1");
        result = PATTERN_HEADING_LINE.matcher(result).replaceAll("");
        result = PATTERN_EMPHASIS.matcher(result).replaceAll("$2");
        result = PATTERN_SPACE_1.matcher(result).replaceAll("");
        result = PATTERN_SPACE_2.matcher(result).replaceAll("");
        return result;
        s = replaceCheckboxesWithEmojis(s).toString();
        s = PATTERN_LISTS.matcher(s).replaceAll("");
        s = PATTERN_HEADINGS.matcher(s).replaceAll("$1");
        s = PATTERN_HEADING_LINE.matcher(s).replaceAll("");
        s = PATTERN_EMPHASIS.matcher(s).replaceAll("$2");
        s = PATTERN_SPACE_1.matcher(s).replaceAll("");
        s = PATTERN_SPACE_2.matcher(s).replaceAll("");
        return s;
    }
}