DEV Community

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

Posted on • Updated on

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:




Top comments (0)