Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CamelCase in tags should work with hyphens #71

Open
jikamens opened this issue Jun 13, 2023 · 1 comment
Open

CamelCase in tags should work with hyphens #71

jikamens opened this issue Jun 13, 2023 · 1 comment

Comments

@jikamens
Copy link

When a tag has hyphens in it the words separated by hyphens should be capitalized. Patch:

From 6186667dd20aa4f01e608d809894d4d4d42429dd Mon Sep 17 00:00:00 2001
From: Jonathan Kamens <[email protected]>
Date: Tue, 13 Jun 2023 11:13:20 -0400
Subject: [PATCH] Treat do CamelCase properly for words tags with hyphens in
 them

When we encounter a tag with hyphens in it, convert the hyphens to
spaces before doing the CamelCase conversion on the tag, so that words
separated by hyphens are properly capitalized.
---
 trunk/mastodon_autopost.php | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/trunk/mastodon_autopost.php b/trunk/mastodon_autopost.php
index be85606..02f93a5 100644
--- a/trunk/mastodon_autopost.php
+++ b/trunk/mastodon_autopost.php
@@ -552,6 +552,12 @@ class autopostToMastodon
     private function fixHashTag($tag)
     {
         $tag = html_entity_decode($tag, ENT_COMPAT, 'UTF-8');
+        // Treat hyphens as spaces for purposes of CamelCase capitalization.
+        // \u{2013} is en dash. \u{2014} is em dash.
+        // I tried putting the three characters inside [] instead of using |
+        // and it gave weird results, presumably because Unicode characters
+        // inside [] behaves weirdly, so that's why I'm using | here.
+        $tag = preg_replace("/-|\u{2013}|\u{2014}/", ' ', $tag);
         if (preg_match('/\s/', $tag)) {
            $tag = ucwords($tag);
         }
-- 
2.40.1

@Rpnpif
Copy link

Rpnpif commented Aug 28, 2023

Camel Case could not be convenient for other language as French where all words must not be capitalized in a title for example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants