Skip to content

Markdown Quickstart

This tutorial is for people interested in contributing to JS Training Grounds.

JS Training Grounds is built using a documentation generator called Starlight. Starlight is built on top of Astro, and allows you to use Markdown to write your content. It also includes a plugin called Expressive Code that enables some really nice syntax highlighting features. This tutorial will show you how to write Markdown and the different Expressive Code features we use on JS Training Grounds to highlight our code snippets.

This tutorial assumes you’re already familiar with VS Code.

Markdown is a lightweight markup language. It lets you write your content in a simple format that can be converted into HTML. The file extension for Markdown files is .md or .markdown. On JS Training Grounds, we also use .mdx files. MDX is a superset of Markdown that allows you to use React components inside your Markdown files.

In the first half of this quickstart, you can toggle between the Markdown snippets and what they look like after being converted to HTML.

If you prefer to work online, you can open the Starlight training ground repo on Stackblitz and start coding right away in your browser. You don’t have to run any of the npm commands if you use Stackblitz. (NOTE: This Stackblitz link works best in Chrome.)

If you prefer to work locally, you can follow these steps (you will need Node and npm installed).

First, visit the Starlight training ground repo. Press the green Code button and click Download ZIP. Unzip the file and then open it in your editor. Then, run this command in the terminal to install the packages listed in package.json.

Terminal window
npm install

Then run this command to start the dev server.

Terminal window
npm run dev

You should see something like this in your terminal.

Terminal window
astro v5.3.1 ready in 656 ms
Local http://localhost:4321/
Network use --host to expose
01:11:49 watching for file changes...

Visit localhost:4321 in your browser, then click on the Example Guide button.

In your editor, you’ll see several files. However, for now you’ll mainly be working in src/content/docs/guides/example.md.

You can use hashtags to create different headings. You can also create a level 1 heading by underlining the text with equals signs and a level 2 heading by underlining the text with dashes. On JS Training Grounds, we use hashtags for headings.

# Heading 1
## Heading 2
### Heading 3
#### Heading 4
##### Heading 5
###### Heading 6
Heading 1
=========
Heading 2
---------

Make sure you follow the same rules for headings that you use for HTML.

NOTE: The level 1 heading in JS Training Grounds is actually created using the title attribute at the top of the page. This is a Starlight feature and not specific to Markdown. This means you should skip the level 1 heading and start with level 2 headings when adding content to JS Training Grounds.

---
title: Main Heading
---

You don’t need any special symbols to create a paragraph in Markdown. To create multiple paragraphs, separate them with a blank line.

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut.

You can use dashes or asterisks to create unordered lists. On JS Training Grounds, we use dashes.

- Item
- Item
- Item
* Item
* Item
* Item

You can use numbers with periods or parentheses to create ordered lists. On JS Training Grounds, we use periods.

1. Item
2. Item
3. Item
1) Item
2) Item
3) Item

You can use a single set of asterisks or underscores to make text italic. On JS Training Grounds, we use asterisks.

*Italic*
_Italic_

This is what it would look like in a sentence:

This is some *italic* text.

You can use 2 pairs of asterisks or underscores to make text bold. On JS Training Grounds, we use asterisks.

**Bold**
__Bold__

This is what it would look like in a sentence:

This is some **bold** text.

You can use square brackets and parentheses to create links. You can also use the second notation if you don’t want the URLs to clutter up your content. On JS Training Grounds, we use the first method.

[Link](http://example.com/)
[Link][1]
Other stuff goes here...
[1]: http://example.com/

This is what it would look like in a sentence:

This is some [link](http://example.com/) text.

You can use the greater than sign to create a blockquote.

> This is a blockquote.

You can use 3 dashes or asterisks to create a horizontal rule. On JS Training Grounds, we use dashes.

Lorem ipsum dolor.
---
Ut enim ad.
Lorem ipsum dolor.
***
Ut enim ad.

Use backticks to create inline code.

`Inline code`

This is what it would look like in a sentence:

This is some `inline code` text.

Use 3 backticks to open and close a code block.

```
function greeting() {
console.log("Hello World");
}
```

The snippet above will look like this when rendered in the browser:

function greeting() {
console.log("Hello World");
}

To enable syntax highlighting, add the correct abbreviation after the top 3 backticks. Since this is a JavaScript snippet, we added js.

```js
function greeting() {
console.log("Hello World");
}
```
function greeting() {
console.log("Hello World");
}

To highlight a word or words, wrap the word(s) in double quotes after the abbreviation. In this example, we’re highlighting the word function.

```js "function"
// Javascript code with syntax highlighting.
function greeting() {
console.log("Hello World");
}
```
// Javascript code with syntax highlighting.
function greeting() {
console.log("Hello World");
}

You can highlight multiple words or phrases by adding more words or phrases in quotes. If the phrase you’re trying to highlight includes double quotes, you can include them inside the double quotes. In this example, we’re also highlighting "Hello World".

```js "function" ""Hello World""
// Javascript code with syntax highlighting.
function greeting() {
console.log("Hello World");
}
```
// Javascript code with syntax highlighting.
function greeting() {
console.log("Hello World");
}

To highlight a line, wrap the line number you want to highlight in curly braces. In this example, we’re highlighting the first line.

```js {1}
// Javascript code with syntax highlighting.
function greeting() {
console.log("Hello World");
}
```
// Javascript code with syntax highlighting.
function greeting() {
console.log("Hello World");
}

You can highlight a range of lines by using a dash. In this example, we’re highlighting the first, second, and third lines.

```js {1-3}
// Javascript code with syntax highlighting.
function greeting() {
console.log("Hello World");
}
```
// Javascript code with syntax highlighting.
function greeting() {
console.log("Hello World");
}

You can highlight different groups of lines by separating them by a comma inside the curly braces. In this example, we’re highlighting the first and second lines as well as the fourth line.

```js {1-2, 4}
// Javascript code with syntax highlighting.
function greeting() {
console.log("Hello World");
}
```
// Javascript code with syntax highlighting.
function greeting() {
console.log("Hello World");
}

You can highlight words and lines. Just separate them with a space after the abbreviation. In this example, we’re highlighting the same lines as before and also highlighting the words "Hello World".

```js {1-2, 4} ""Hello World""
// Javascript code with syntax highlighting.
function greeting() {
console.log("Hello World");
}
```
// Javascript code with syntax highlighting.
function greeting() {
console.log("Hello World");
}

To add a file name to the top of the code snippet, add the title attribute to the top of the snippet with the filename. In this example, we’re adding title="HelloWorld.js".

```js title="HelloWorld.js" {1-2, 4} ""Hello World""
// Javascript code with syntax highlighting.
function greeting() {
console.log("Hello World");
}
```
HelloWorld.js
// Javascript code with syntax highlighting.
function greeting() {
console.log("Hello World");
}

To collapse multiple lines of code, add the collapse attribute with a range of lines. In this example, we’re collapsing lines 2 through 4.

```js title="HelloWorld.js" collapse={2-4}
// Javascript code with syntax highlighting.
function greeting() {
console.log("Hello World");
}
```
HelloWorld.js
// Javascript code with syntax highlighting.
3 collapsed lines
function greeting() {
console.log("Hello World");
}

On JS Training Grounds, we turned on a setting so that line numbers show up on every code snippet by default. However, there are some situations where we do hide the line numbers on code snippets. To hide the line numbers, set the showLineNumbers attribute to false.

```js title="HelloWorld.js" showLineNumbers=false
// Javascript code with syntax highlighting.
function greeting() {
console.log("Hello World");
}
```
HelloWorld.js
// Javascript code with syntax highlighting.
function greeting() {
console.log("Hello World");
}

The tutorials on this site should follow this pattern for each section:

  1. Add a heading
  2. Explain the main concept in 1 sentence
  3. Explain in 1 sentence what code the user will write
  4. Show the code snippet (and use the Expressive Code features listed above where appropriate)
  5. Tell the user what they should see in the browser in 1 sentence

There are instances where you might have to use more than 1 sentence, but the goal is to be fairly terse. Also, you might have to repeat steps 3, 4, and 5 in a section depending on how complex the step is.

Here is an example from our Vue 3 tutorial:


You can add a style attribute to an element just like in normal HTML.

Task: Add style="color: red;" to the h1 element.

HelloWorld.vue
<template>
<h1 style="color: red;">Hello World</h1>
<p>Lorem ipsum dolor...</p>
</template>

After saving, you should see the <h1> element turn red in the browser.


You can see that it has the heading, the various explanations, and the code snippet.

Here is a summary of all the rules to follow when writing Markdown for JS Training Grounds:

  1. The main rule for our Markdown files is make sure you leave 1 blank line above and below an element. This goes for headings, paragraphs, code snippets, etc. You can view the raw Markdown in our GitHub repo to see examples of this.
  2. Use hashtags for headings.
  3. Use dashes for unordered lists.
  4. Use numbers and periods for ordered lists.
  5. Use 1 set of asterisks for marking text as italic.
  6. Use 2 sets of asterisks for marking text as bold.
  7. Use dashes for horizontal rules.