Skip to content

Commit

Permalink
Improved description extras
Browse files Browse the repository at this point in the history
  • Loading branch information
pablouser1 committed Sep 29, 2023
1 parent 200a6fc commit 80f3ca4
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions app/Helpers/Wrappers.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,13 @@ public static function latte(string $template, BaseTemplate $base) {
});

// Add URLs to video descriptions
// TODO: Make it work with unicode characters such as emojis
$latte->addFunction('render_desc', function (string $desc, array $textExtras = []): string {
$sanitizedDesc = htmlspecialchars($desc);
$out = $sanitizedDesc;
foreach ($textExtras as $extra) {
$url = '';
$text = mb_substr($desc, $extra->start, $extra->end - $extra->start, 'UTF-8');
// We do -1 to also take the # or @
$text = mb_substr($desc, $extra->start - 1, $extra->end - $extra->start, 'UTF-8');
switch ($extra->type) {
// User URL
case TextExtras::USER:
Expand All @@ -114,7 +114,8 @@ public static function latte(string $template, BaseTemplate $base) {
break;
}

$out = str_replace($text, "<a href=\"$url\">$text</a>", $out);
// We do \b to avoid non-strict matches ('#hi' would match with '#hii' and we don't want that)
$out = preg_replace("/$text\b/", "<a href=\"$url\">$text</a>", $out);
}
return $out;
});
Expand Down

0 comments on commit 80f3ca4

Please sign in to comment.