From cdba58fb2126780a511a9f7b8e4c6f91a6dfcbf2 Mon Sep 17 00:00:00 2001 From: n Date: Sun, 25 Feb 2024 18:36:26 +0100 Subject: [PATCH] regex fixes --- README.md | 4 ---- clickat.php | 8 ++++---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index e1b41fb..ab84d10 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,3 @@ $ git clone https://forge.tourmentine.com/n/shaarli-plugin-clickat.git path/to/s - Threads with `@nic@threads.net`, - Bluesky with `@nic.bsky.social`, - Fediverse with `@nic@instance`. - -## Caveats - -For now addresses need to be proceded by an empty space. diff --git a/clickat.php b/clickat.php index cd973e6..63aca5f 100644 --- a/clickat.php +++ b/clickat.php @@ -12,12 +12,12 @@ use Shaarli\Render\TemplatePage; function hook_clickat_render_linklist($data) { $patterns = array( - '/\ @([\w\d]+).bsky.social/' => ' @\1.bsky.social', - '/\ @([\w\d]+)@([\w\d_\-\.]+)/' => ' @\1', - '/\ @([\w\d]+)/' => ' @\1' + '/([^\S]+)@([\w]+).bsky.social/' => '\1@\2.bsky.social', + '/([^\S]+)@([\w]+)@([\w_\-\.]+)/' => '\1@\2', + '/([^\S]+)@([\w]+)/' => '\1@\2' ); foreach ($data['links'] as &$value) { - if (strpos($value['description'], ' @') !== false) { + if (strpos($value['description'], '@') !== false) { foreach($patterns as $nic => $link) { $value['description'] = preg_replace($nic, $link, $value['description']); }