跳转到内容
GitHub

Markdown

输入:

```js title="foo.js"
console.log('Hello, world!')
```

输出:

foo.js
console.log('Hello, world!')

输入:

import { CodeTabs } from 'starlight-theme-nova/components'

<CodeTabs>

```js title="foo.js"
function foo() {
  console.log('Foo!')
}
```

```ts title="bar.ts"
function bar() {
  console.log('Bar!')
}
```

</CodeTabs>

输出:

foo.js
function foo() {
  console.log('Foo!')
}

输入:

```js {1,3-4}
console.log('1')
console.log('2')
console.log('3')
console.log('4')
```

```ts
console.log('Not highlighted')
console.log('Highlighted') // [!code highlight]
console.log('Not highlighted')
```

输出:

console.log('1')
console.log('2')
console.log('3')
console.log('4')
console.log('Not highlighted')
console.log('Highlighted') 
console.log('Not highlighted')

输入:

```js /Hello/
const msg = 'Hello World'
console.log(msg)
console.log(msg) // prints Hello World
```

```ts
// [\!code word:World]
const message = 'Hello World'
console.log(message) // prints Hello World
```

输出:

const msg = 'Hello World'
console.log(msg)
console.log(msg) // prints Hello World
const message = 'Hello World'
console.log(message) // prints Hello World

输入:

```ts
console.log('hewwo') // [!code --]
console.log('hello') // [!code ++]
console.log('goodbye')
```

输出:

console.log('hewwo') 
console.log('hello') 
console.log('goodbye')

Nova 开箱即支持 Twoslash. 将鼠标悬停在代码块上, 即可看到内联类型.

输入:

```ts twoslash
// @errors: 2551
const div = document.createElement('h1')
div.style.colour = 'red' // Incorrect CSS property name
```

输出:

const divconst div: HTMLHeadingElement = documentvar document: Document
[MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/document)
.createElementDocument.createElement<"h1">(tagName: "h1", options?: ElementCreationOptions): HTMLHeadingElement (+2 overloads)
Creates an instance of the element for the specified tag.
@paramtagName The name of an element. [MDN Reference](https://developer.mozilla.org/docs/Web/API/Document/createElement)
('h1')
divconst div: HTMLHeadingElement.styleElementCSSInlineStyle.style: CSSStyleDeclaration
[MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLElement/style)
.colour = 'red' // Incorrect CSS property name
Property 'colour' does not exist on type 'CSSStyleDeclaration'. Did you mean 'color'?
NameAgeCity
John25New York
Jane30Los Angeles
Jim35Chicago

有序列表

  1. Number 1
  2. Number 2
  3. Number 3

无序列表

  • Bullet 1
  • Bullet 2
  • Bullet 3

任务列表

  • Checkbox 1
  • Checkbox 2
  • Checkbox 3

在 Markdown 中使用标题会自动为您提供锚链接, 这样您就可以直接链接到页面的某些部分. 详情请参阅 自动生成标题锚点链接.

此外,您还可以通过在标题中添加 {#heading-id} 为标题手动添加锚链接.

### Hello World {#my-custom-id}

或者在 MDX 中:

### Hello World \{#my-custom-id\}

示例: