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.

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay