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

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.

Top comments (0)