docs: add mdx-code-block around tabs; use JS example for magic comments (#7307)

This commit is contained in:
Joshua Chen 2022-05-04 20:29:09 +08:00 committed by GitHub
parent 0466dbcf3f
commit 977ef7121b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -282,6 +282,7 @@ Below, we will introduce how the magic comment system can be extended to define
You can declare custom magic comments through theme config. For example, you can register another magic comment that adds a `code-block-error-line` class name:
`````mdx-code-block
<Tabs>
<TabItem value="docusaurus.config.js">
@ -325,32 +326,31 @@ module.exports = {
<TabItem value="myDoc.md">
````md
In TypeScript, types help prevent runtime errors.
In JavaScript, trying to access properties on `null` will error.
```ts
function greet(name: string) {
// This will error
console.log(name.toUpper());
// .toUpper doesn't exist on string
}
```js
const name = null;
// This will error
console.log(name.toUpperCase());
// Uncaught TypeError: Cannot read properties of null (reading 'toUpperCase')
```
````
</TabItem>
</Tabs>
`````
````mdx-code-block
<BrowserWindow>
In TypeScript, types help prevent runtime errors.
In JavaScript, trying to access properties on `null` will error.
```ts
function greet(name: string) {
// This will error
console.log(name.toUpper());
// .toUpper doesn't exist on string
}
```js
const name = null;
// This will error
console.log(name.toUpperCase());
// Uncaught TypeError: Cannot read properties of null (reading 'toUpperCase')
```
</BrowserWindow>