blob: 73cc5832e97b3421908bc8bc4bcf430558347878 (
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
|
package it.niedermann.owncloud.notes.shared.util.text;
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));
}
}
|