DEV Community

Cover image for Script for converting Markdown with bold text to Unicode, retaining the bold text.
Le Vuong
Le Vuong

Posted on • Edited on

1

Script for converting Markdown with bold text to Unicode, retaining the bold text.

Hello developers,

Have you ever needed to convert Markdown text to a bold/italic text that you can post to Facebook, Instagram ?

Here’s how it works:

  1. It looks through text for any parts that are wrapped in **bold text**.
  2. Using regex, it breaks up each segment into "normal" and "bold" parts.
  3. Each letter in the bold section gets replaced with its corresponding Unicode "bold" version. For example, A becomes a Unicode-bold 𝐀, and a becomes 𝐚.
  4. Finally, it puts everything back together and gives you the bolded version of the whole text.

This script is perfect for converting text so that it looks bold across platforms that don’t directly support rich text formatting, like some messaging apps. Simple and effective!

Code snippet

Side Notes:

  • If you need to get the Html output of some formatted text, use CopyQ. Windows have similar "buffer" tools like Free Clipboard Viewer

  • VSCode have "Paste" extension that allows you to paste different format of the Clipboard content.

  • Also, for VSCode, you have extensions for converting Markdown to Html and vice verse.

  • Take a look at the code comment if you want to extent the script to process Italic or Bold and Italic text.

Image of Datadog

Master Mobile Monitoring for iOS Apps

Monitor your app’s health with real-time insights into crash-free rates, start times, and more. Optimize performance and prevent user churn by addressing critical issues like app hangs, and ANRs. Learn how to keep your iOS app running smoothly across all devices by downloading this eBook.

Get The eBook

Top comments (0)

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more