DEV Community

Cover image for Enable syntax highlighting in your code snippets
Prathamesh Mali
Prathamesh Mali

Posted on • Edited on

1

Enable syntax highlighting in your code snippets

Photo by Chris Ried on Unsplash

I've noticed this on web on some sites they didn't have syntax highlighting for their code snippets the code is just white text on black background.
When you add your code snippets on the web or here on dev.to you can specify the language of the snippet in markdown while using it in that way the syntax highlighting is enabled.You can add it html and markdown.So it provides better readability. Hope this helps out someone.

Example code snippet without specified language:

const funYou = () => console.log("I am function 😃");
funYou();
Enter fullscreen mode Exit fullscreen mode
def add(n1,n2):
    return n1 + n2
Enter fullscreen mode Exit fullscreen mode
echo "Hello World"
Enter fullscreen mode Exit fullscreen mode
{
   "Name": "jack",
   "Age": 25,
   "Location":"Spain"
}
Enter fullscreen mode Exit fullscreen mode

You can add syntax highlighting by just adding the language name after 3rd backtick. just like following example:

Alt Text

Example code snippet with specified language:

const funYou = () => console.log("I am function 😃");
funYou();
Enter fullscreen mode Exit fullscreen mode
def add(n1,n2):
    return n1 + n2
Enter fullscreen mode Exit fullscreen mode
echo "Hello World"
Enter fullscreen mode Exit fullscreen mode
{
   "Name": "jack",
   "Age": 25,
   "Location":"Spain"
}
Enter fullscreen mode Exit fullscreen mode

Conclusion: All major languages are supported with markdown. This is just a suggestion that I want to make so if someone didn't know now you know. As always thanks for reading.

Connect with me:




Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

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

Okay