@lauthieb/snippets
Published on

Code blocks en Markdown

451 mots2 min

Syntaxe de base

Utiliser 3 back ticks pour créer un bloc de code en Markdown.

```language
your code goes here
```

Exemple :

```javascript
function debounce(func, timeout = 300) {
  let timer;
  return (...args) => {
    clearTimeout(timer);
    timer = setTimeout(() => { func.apply(this, args); }, timeout);
  };
}
```

apparaîtra comme cela :

function debounce(func, timeout = 300) {
	let timer;
	return (...args) => {
		clearTimeout(timer);
		timer = setTimeout(() => {
			func.apply(this, args);
		}, timeout);
	};
}

Nom du fichier

Ajouter :filename.ext après language pour montrer le nom du fichier en haut du bloc de code.

Exemple :

```js:add.js
const add = (a, b) => {
  return a + b;
}
```

apparaîtra comme cela :

add.js
const add = (a, b) => {
  return a + b;
}

Surbrillance des lignes et numéros de lignes

  • Ajouter la propriété {numbers} après language pour mettre les lignes en surbrillance
  • Ajouter la propriété showLineNumbers après language pour afficher les numéros de ligne

Exemple :

```html {1,4-6,10} showLineNumbers
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Hello world</title>
  </head>
  <body>
    <h1>Hello world</h1>
  </body>
</html>
```

Apparaîtra comme cela :

<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<meta http-equiv="X-UA-Compatible" content="ie=edge" />
		<title>Bonjour le monde</title>
	</head>
	<body>
		<h1>Bonjour le monde</h1>
	</body>
</html>

Partager ce snippet