Starlight
pnpm dev
- start dev server at http://localhost:4321/
Markdown frontmatter
1title: top of page, browser tab, page metadata2description: page metadata, social media previews3
4slug: my-custom-slug/some/thing # use this in sidebar config as well5draft: false # not included in production build and autogenerated link groups6
7# Specify all <head> tags here8head:9 - tag: title10 content: Custom about title11
12sidebar:13 label: Taken from "title"14 order: Lower numbers displayed higher15 hidden: false # do not include the page in autogenerated sidebar16 badge:17 text: Experimental18 variant: caution19 attrs: # HTML attributes to add to page link i.e. <a> tag20 target: _blank # to open in new tab21
22editUrl: false # to disable "Edit page" link23tableOfContents: false # Disable table of contents24tableOfContents:25 minHeadingLevel: 226 maxHeadingLevel: 327template: doc | splash # "splash" uses no sidebar and table of contents28lastUpdated: false # or provide date lke "2022-08-09"29prev: false30next: false
Markdown
**bold**
- bold_italic*
- italic~~strikethrough~~
-strikethrough[link to home page](../../)
- link to homepage![image-alt-text](../../assets/profile.jpeg)
-[link to markdown headings](#markdown)
- link to markdown headings
Table
1| Syntax | Description |2| --------- | ----------- |3| Header | Title |4| Paragraph | Text |
Syntax | Description |
---|---|
Header | Title |
Paragraph | Text |
Blockquote
Blockquote used when quoting other people.
Use ’>’ at the start of line.
Footnote
Here’s a sentence with a footnote. 1
Definition List
1<dl>2 <dt>Second Term</dt>3 <dd>This is one definition of the second term. </dd>4 <dd>This is another definition of the second term.</dd>5</dl>
- First Term
- This is one definition of the second term.
- This is another definition of the second term.
Task list
- Write the press release
- Update the website
- Contact the media
Starlight Components
Asides/Admonitions/Callouts
Details/Accordion
Use to hide content that is not immediately relevant. Users can click >
to see the details.
1<details>2 <summary>Use standard HTML detail, summary tag.</summary>3 Here is more detailed information about this.4</details>
Use standard HTML detail, summary tag.
Here is more detailed information about this.Code Blocks
Expressive Code rehype plugin used for this.
Shiki
Shiki used for syntax highlighting.
List of all supported languages.
title/frame
-
Terminal window - Provide
title
with file name to create terminal like window.1```js title="test.js"2console.log('Create a terminal window for the codeblock');3```test.js 1console.log('Create a terminal window for the codeblock'); -
Code editor window - For
title
without a file name, the code editor window would be created.1```powershell title="PowerShell terminal example"2Write-Output "This one has a title!"3```PowerShell terminal example 1Write-Output "This one has a title!" -
Control the frame type by providing
frame
argument (code
,terminal
,none
,auto
).1```sh title="Something" frame="none"2echo "How are you doing?"3```1echo "How are you doing?"
Text and Line markers
-
Mark lines for highlighting
{4}
- single line{4, 8, 10}
- three lines{4-8}
- range of lines
1```js {1, 4, 7-8}2// Line 1 - targeted by line number3// Line 24// Line 35// Line 4 - targeted by line number6// Line 57// Line 68// Line 7 - targeted by range "7-8"9// Line 8 - targeted by range "7-8"10```1// Line 1 - targeted by line number2// Line 23// Line 34// Line 4 - targeted by line number5// Line 56// Line 67// Line 7 - targeted by range "7-8"8// Line 8 - targeted by range "7-8" -
Type of markers
mark
- defaultins
del
1```js title="Line markers" del={2} ins={3-4} {6}2// Line 1 - targeted by line number3// Line 24// Line 35// Line 4 - targeted by line number6// Line 57// Line 68// Line 7 - targeted by range "7-8"9// Line 8 - targeted by range "7-8"10```Line markers 1// Line 1 - targeted by line number2// Line 23// Line 34// Line 4 - targeted by line number5// Line 56// Line 67// Line 7 - targeted by range "7-8"8// Line 8 - targeted by range "7-8" -
Add single character labels to side of line markers to help with referencing specific parts of code.
labeled-line-markers.jsx 1```jsx {"1":5} del={"2":7-8} ins={"3":10-12}2<button3role='button'4{...props}5value={value}6className={buttonClassName}7disabled={disabled}8active={active}9>10{children &&11!active &&12(typeof children === 'string' ? <span>{children}</span> : children)}13</button>14```labeled-line-markers.jsx 1<button2role='button'3{...props}4value={value}5className={buttonClassName}6disabled={disabled}7active={active}8>9{children &&10!active &&11(typeof children === 'string' ? <span>{children}</span> : children)}12</button> -
Add long labels on separate lines. For this, leave an empty line above the marked line range.
labeled-line-markers.jsx 1<!-- prettier-ignore -->2```jsx {"1. Provide the value prop here:":5-6} del={"2. Remove the disabled and active states:":8-10} ins={"3. Add this to render the children inside the button:":12-15}3<button4role='button'5{...props}67value={value}8className={buttonClassName}910disabled={disabled}11active={active}12>1314{children &&15!active &&16(typeof children === 'string' ? <span>{children}</span> : children)}17</button>18```labeled-line-markers.jsx 1<button2role='button'3{...props}45value={value}6className={buttonClassName}78disabled={disabled}9active={active}10>1112{children &&13!active &&14(typeof children === 'string' ? <span>{children}</span> : children)}15</button> -
Use GitHub
diff
syntax. Add+
,-
to mark lines that are inserted and deleted.For syntax highlighting, provide the language using
lang="js"
.1```diff lang="js"2function thisIsJavaScript() {3// This entire block gets highlighted as JavaScript,4// and we can still add diff markers to it!5- console.log('Old code to be removed')6+ console.log('New and shiny code!')7}8```1function thisIsJavaScript() {2// This entire block gets highlighted as JavaScript,3// and we can still add diff markers to it!4console.log('Old code to be removed')5console.log('New and shiny code!')6} -
Mark text or regular expression in the code block.
1```js "return /true|false/;" ins="inserted" del="deleted"2function demo() {3console.log('These are inserted and deleted marker types');4// The return statement uses the default marker type5return true;6return false;7}8```1function demo() {2console.log('These are inserted anddeletedmarker types');3// The return statement uses the default marker type4return true;5return false;6}
Wrap lines
Add wrap
or wrap=true
to wrap code block and prevent horizontal scrolling.
By default, the wrapped line will start at the same indentation as the original line.
To wrap lines to the start i.e. column 1, add preserveIndent=false
. This is useful to reproduce terminal output.
1```js wrap2// Example with wrap3function getLongString() {4 return 'This is a very long string that will most probably not fit into the available space unless the container is extremely wide'5}
1// Example with wrap2function getLongString() {3 return 'This is a very long string that will most probably not fit into the available space unless the container is extremely wide';4}
Example, with wrapped line starting from column 1
1```js wrap preserveIndent=false2// Example with preserveIndent=false3function getLongString() {4 return 'This is a very long string that will most probably not fit into the available space unless the container is extremely wide'5}6```
1// Example with preserveIndent=false2function getLongString() {3 return 'This is a very long string that will most probably not fit into the available space unless the container is extremely wide';4}
Collapsible sections
Collapse the provided line number ranges. This helps reduce long code examples to relevant parts.
1```js collapse={1-5, 12-14}2// All this boilerplate setup code will be collapsed3import { someBoilerplateEngine } from '@example/some-boilerplate'4import { evenMoreBoilerplate } from '@example/even-more-boilerplate'5
6const engine = someBoilerplateEngine(evenMoreBoilerplate())7
8// This part of the code will be visible by default9engine.doSomething(1, 2, 3, calcFn)10
11function calcFn() {12 // You can have multiple collapsed sections13 const a = 114 const b = 215 return a + b16}17```
5 collapsed lines
1// All this boilerplate setup code will be collapsed2import { someBoilerplateEngine } from '@example/some-boilerplate';3import { evenMoreBoilerplate } from '@example/even-more-boilerplate';4
5const engine = someBoilerplateEngine(evenMoreBoilerplate());6
7// This part of the code will be visible by default8engine.doSomething(1, 2, 3, calcFn);9
10function calcFn() {11 // You can have multiple collapsed sections3 collapsed lines
12 const a = 1;13 const b = 2;14 return a + b;15}
Line numbers
showLineNumbers=false
- to hidestartLineNumbers=5
1```js startLineNumber=52console.log('Greetings from line 5!');3console.log('I am on line 6');4```
5console.log('Greetings from line 5!');6console.log('I am on line 6');
Custom theme
Instruction to create personal theme.
Site Search
PageFind is used.
Add pagefind: false
in markdown frontmatter to exclude page from search index.
Exclude parts of the page using
1<div data-pagefind-ignore>2This text will be hidden from search.3</div>
Sidebar
Internal links
Internal links to pages need to be relative to src/content/docs
with slug
property.
1starlight({2 sidebar: [3 { slug: 'constellations/andromeda' },4 { slug: 'constellations/orion' },5 ],6});
Or the shorthand without slug
1starlight({2 sidebar: ['constellations/andromeda', 'constellations/orion'],3});
Other links
For internal links, it is better to provide label
info from the frontmatter.
1starlight({2 sidebar: [3 // A link to a non-docs page on this site.4 { label: 'Meteor Store', link: '/shop/' },5 // An external link to the NASA website.6 { label: 'NASA', link: 'https://www.nasa.gov/' },7],8});
Groups
Collapse by providing collapsed: true
.
1starlight({2 sidebar: [3 // A group of links labelled "Constellations".4 {5 label: 'Constellations',6 items: [7 'constellations/carina',8 // A nested group of links for seasonal constellations.9 {10 label: 'Seasonal',11 items: [12 'constellations/andromeda',13 ],14 },15 ],16 },17 ],18});
Autogenerate groups
The collapsed
value of parent is used, if none is provided.
1starlight({2 sidebar: [3 {4 label: 'Constellations',5 // Autogenerate a group of links for the 'constellations' directory.6 autogenerate: { directory: 'constellations' },7 },8 ],9});
Badges
Display a small badge next to sidebar label. This can convey information like “New”, “Outdated”.
Use the following variants note
, tip
, danger
, caution
, success
.
1sidebar:2 label: Custom sidebar label3 order: 24 badge:5 text: New6 variant: tip
Footnotes
-
This is the footnote. ↩