Latte filter – noescape in href

pn-pm
Member | 20
+
0
-

Im trying to make a filter email_link to create mailto link, obfuscated against spammers, by using html entities and prepending also the ‘mailto:’ protocol prefix (will use for own validated addresses)

It is not working in the href attribute, only if i add modifiers **|nocheck|noescape **
Is there a way to modify the filter, so i dont have to use the modifiers inline
Maybe some special contentType, or way to apply modifiers to FilterInfo object ?

// WORKS
<a href="{$email|email_link|nocheck|noescape}">{$email|email_text}</a> ...
// DOESNT WORK (href attribute is empty)
<a href="{$email|email_link}">{$email|email_text}</a> ...
// Example of antispambot resulting address: &#101;mai&#108;&#64;&#97;&#100;r&#101;s&#97;&#46;&#120;&#121;
function filter_email_link(FilterInfo $info, $str){
	// $info->contentType = \Latte\ContentType::Text;   ???
	return 'm&#097;ilt&#111;' . ':' . antispambot($str); // 'm&#097;ilt&#111;' => encoded mailto:
}
function filter_email_text(FilterInfo $info, $str){
	// html contentType allow encoded entities, but not in attribute
	$info->contentType = \Latte\ContentType::Html;
	return 'm&#097;ilt&#111;' . ':' . antispambot($str);
}

Problem is, the content-aware filter rejects the encoded mailto link, if used in href

Last edited by pn-pm (2023-09-06 12:52)