getArgumentNames(){
- return List.of("forceTargetBlank");
+ return List.of("forceTargetBlank", "keepLinksRel");
}
}
diff --git a/src/main/java/smithereen/text/TextProcessor.java b/src/main/java/smithereen/text/TextProcessor.java
index 3c8dfad5..b3536190 100644
--- a/src/main/java/smithereen/text/TextProcessor.java
+++ b/src/main/java/smithereen/text/TextProcessor.java
@@ -433,7 +433,7 @@ public void tail(@NotNull Node node, int depth){
return newBody.html();
}
- public static String postprocessPostHTMLForDisplay(String text, boolean forceTargetBlank){
+ public static String postprocessPostHTMLForDisplay(String text, boolean forceTargetBlank, boolean keepLinksRel){
if(text==null)
return "";
Document doc=Jsoup.parseBodyFragment(text);
@@ -469,7 +469,7 @@ public static String postprocessPostHTMLForDisplay(String text, boolean forceTar
URI uri=new URI(href);
if(forceTargetBlank || (uri.isAbsolute() && (uri.getHost()==null || !Config.isLocal(uri)))){
el.attr("target", "_blank");
- if(!el.hasAttr("rel"))
+ if(!keepLinksRel || !el.hasAttr("rel"))
el.attr("rel", "noopener ugc");
}
}catch(URISyntaxException x){}
diff --git a/src/main/resources/templates/desktop/profile.twig b/src/main/resources/templates/desktop/profile.twig
index 22e932e9..b084ccca 100644
--- a/src/main/resources/templates/desktop/profile.twig
+++ b/src/main/resources/templates/desktop/profile.twig
@@ -12,7 +12,7 @@
{% endif %}
{% for fld in fields %}
{{ fld.name }}:
- {% if fld.html %}{{ fld.value | postprocessHTML }}{% else %}{{ fld.value | nl2br }}{% endif %}
+ {% if fld.html %}{{ fld.value | postprocessHTML(keepLinksRel=true) }}{% else %}{{ fld.value | nl2br }}{% endif %}
{% else %}
{{ L('profile_no_info') }}
{% endfor %}
diff --git a/src/main/resources/templates/mobile/profile.twig b/src/main/resources/templates/mobile/profile.twig
index ece5acc2..ff5926c1 100644
--- a/src/main/resources/templates/mobile/profile.twig
+++ b/src/main/resources/templates/mobile/profile.twig
@@ -11,7 +11,7 @@
{% endif %}
{% for fld in fields %}
{{ fld.name }}:
- {% if fld.html %}{{ fld.value | postprocessHTML }}{% else %}{{ fld.value | nl2br }}{% endif %}
+ {% if fld.html %}{{ fld.value | postprocessHTML(keepLinksRel=true) }}{% else %}{{ fld.value | nl2br }}{% endif %}
{% else %}
{{ L('profile_no_info') }}
{% endfor %}
diff --git a/src/test/java/smithereen/HTMLProcessingTest.java b/src/test/java/smithereen/HTMLProcessingTest.java
index adb65974..a18067a2 100644
--- a/src/test/java/smithereen/HTMLProcessingTest.java
+++ b/src/test/java/smithereen/HTMLProcessingTest.java
@@ -29,7 +29,7 @@ public void testMastodonTootMicroformatIsKept(){
"#photo #birds #sparrow #фото #птицы #воробей
\n"+
"@rf @russian_mastodon
";
- String out=TextProcessor.postprocessPostHTMLForDisplay(TextProcessor.sanitizeHTML(in), false);
+ String out=TextProcessor.postprocessPostHTMLForDisplay(TextProcessor.sanitizeHTML(in), false, false);
assertEquals(expected.replaceAll("\\s*\n", ""), out.replaceAll("\\s*\n", ""));
}
@@ -37,7 +37,7 @@ public void testMastodonTootMicroformatIsKept(){
public void testTargetBlankIsAddedToExternalLinks(){
String in="External link";
String expected="External link";
- String out=TextProcessor.postprocessPostHTMLForDisplay(TextProcessor.sanitizeHTML(in), false);
+ String out=TextProcessor.postprocessPostHTMLForDisplay(TextProcessor.sanitizeHTML(in), false, false);
assertEquals(expected, out);
}
@@ -79,7 +79,7 @@ public void testUnsupportedUrlSchemesAreRemoved(){
public void testRelativeUrlsAreExpended(){
String in="Relative link";
String expected="Relative link";
- assertEquals(expected, TextProcessor.postprocessPostHTMLForDisplay(TextProcessor.sanitizeHTML(in, URI.create("https://example.com/")), false));
+ assertEquals(expected, TextProcessor.postprocessPostHTMLForDisplay(TextProcessor.sanitizeHTML(in, URI.create("https://example.com/")), false, false));
}
@Test