Welcome to mirror list, hosted at ThFree Co, Russian Federation.

WwwLinksProcessor.java « text « util « shared « notes « owncloud « niedermann « it « java « main « src « app - github.com/stefan-niedermann/nextcloud-notes.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 689d7fd8594985fe399d53bcd37ea6d84b85c90f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package it.niedermann.owncloud.notes.shared.util.text;

import androidx.annotation.NonNull;

import java.util.regex.Pattern;

public class WwwLinksProcessor extends TextProcessor {

    private static final String WWW_URLS_PROTOCOL_PREFIX = "https://";
    private static final String REGEX_REPLACE_WWW_URLS = "\\[([^]]*)]\\((www\\..+)\\)";

    /**
     * Prefixes all links, that not not start with a protocol identifier, but with "www." with http://
     * <p>
     * See https://github.com/stefan-niedermann/nextcloud-notes/issues/949
     *
     * @return Markdown with all pseudo-links replaced through actual HTTP-links
     */
    @Override
    public String process(String s) {
        return Pattern
                .compile(REGEX_REPLACE_WWW_URLS)
                .matcher(s)
                .replaceAll(String.format("[$1](%s$2)", WWW_URLS_PROTOCOL_PREFIX));
    }
}