Last active
February 2, 2025 02:35
-
-
Save patfinder/7fe39ea2fe9ec2545d8c4783af6dce24 to your computer and use it in GitHub Desktop.
Simple script to convert markdown bold text to Unicode 'bold' characters. You can exend the script with other ranges (like bold AND itatic) (explore chars after and properly before 119808(A) .. 119859(z)). This can be used for formatting Facebook text.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import re | |
| text = "Todayโs world is driven by **technology** and **connectivity**, reshaping interactions and work. **Environmental issues** and social change call for urgent, **collective action** toward sustainability." | |
| ## Output: Todayโs world is driven by ๐ญ๐๐๐ก๐ง๐จ๐ฅ๐จ๐ ๐ฒ and ๐๐จ๐ง๐ง๐๐๐ญ๐ข๐ฏ๐ข๐ญ๐ฒ, reshaping interactions and work. ๐๐ง๐ฏ๐ข๐ซ๐จ๐ง๐ฆ๐๐ง๐ญ๐๐ฅ ๐ข๐ฌ๐ฌ๐ฎ๐๐ฌ and social change call for urgent, ๐๐จ๐ฅ๐ฅ๐๐๐ญ๐ข๐ฏ๐ ๐๐๐ญ๐ข๐จ๐ง toward sustainability. | |
| # text = "_000 **A** 111 **b** 222" | |
| def convert(text): | |
| # Split input to couple of 'normal' and 'bold' | |
| # Process each couple, then continue with remaining text | |
| rex = r'(.*?)\*\*(.*?)\*\*' | |
| result = '' | |
| while True: | |
| # Find couple | |
| match = re.match(rex, text) | |
| # No more match, combine remaining with previous result. | |
| if not match: | |
| result += text | |
| break | |
| # 2. For each bold range, convert them to 'bold' format | |
| groups = match.groups() | |
| normal = groups[0] | |
| bold = groups[1] | |
| # Transformed of `bold` | |
| t_bold = '' | |
| for ch in bold: | |
| # Bold A..Z <--> 119808..119833 | |
| if ch >= 'A' and ch <= 'Z': | |
| ch = chr(ord(ch) - ord('A') + 119808) | |
| # Bold a..z <--> 119834..119859 | |
| elif ch >= 'a' and ch <= 'z': | |
| ch = chr(ord(ch) - ord('a') + 119834) | |
| t_bold += ch | |
| # 3. Combine ranges back as original string. | |
| text = text[match.span()[1]:] | |
| result += (normal + t_bold) | |
| return result | |
| converted= convert(text) | |
| print(converted) | |
| ## Todayโs world is driven by ๐ญ๐๐๐ก๐ง๐จ๐ฅ๐จ๐ ๐ฒ and ๐๐จ๐ง๐ง๐๐๐ญ๐ข๐ฏ๐ข๐ญ๐ฒ, reshaping interactions and work. ๐๐ง๐ฏ๐ข๐ซ๐จ๐ง๐ฆ๐๐ง๐ญ๐๐ฅ ๐ข๐ฌ๐ฌ๐ฎ๐๐ฌ and social change call for urgent, ๐๐จ๐ฅ๐ฅ๐๐๐ญ๐ข๐ฏ๐ ๐๐๐ญ๐ข๐จ๐ง toward sustainability. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment