When attempting to post code on platforms that do not support syntax highlighting (such as Medium, Quora, and others), a tool called ‘Carbon’ comes in helpful. It is a wonderful tool for presenting code. It generates a visually appealing source code graphic.
It contains numerous choices for formatting code:

It Supports Many Languages:

Plus, it has decent Export options:

If you are using a Mac, you can also use CodeShot: https://codeshotapp.com