7

How to add code highlighting to your Dev.to posts.

 2 years ago
source link: https://dev.to/hoverbaum/how-to-add-code-highlighting-to-your-devto-posts-2lp6
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

The simple truth of the matter is that:

const turorialFunction = (name) => {
  console.log(`Hello ${name}`)
}
Enter fullscreen modeExit fullscreen mode

does look way nicer than:

const turorialFunction = (name) => {
  console.log(`Hello ${name}`)
}
Enter fullscreen modeExit fullscreen mode

when writing a post here on Dev.to.


How to do it

Dev.tos posts are based on Markdown. Within Markdown we can use identation or so called Code Blocks to specify sections of code. The later ones are indicated using ```. Read more about this in this cheatsheet.

Using the three ` variant we can also specify a language for the code block. A lot of tooling build on top of Markdown utilized this characteristic to implement richer features. But the simplest of them is code highlighting. The above nicely colored code snippet is achieved by starting the code block with ```javascript.

The full example for the above would be:

```javascript
const turorialFunction = (name) => {
  console.log(`Hello ${name}`)
}
```

And if you are now wondering how the hell I got that to display:

<pre>
```javascript
const turorialFunction = (name) => {
  console.log(`Hello ${name}`)
}
```
</pre>

and the inline code is: <code>```</code>.


Here is where my explanations stop and your colorful posts start.

The list of supported languages is impressive, though not all encompassing (check comments).


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK