facebook / docusaurus

Easy to maintain open source documentation websites.
https://docusaurus.io
MIT License
55.79k stars 8.36k forks source link

Codeblocks inside tabs doesn't work #3890

Closed MarvinSzyperski closed 3 years ago

MarvinSzyperski commented 3 years ago

🐛 Bug Report

Codeblocks with ``` does not work inside a JSX . Even with a 1:1 copied Text from the docusaurus doc

Have you read the Contributing Guidelines on issues?

Yes, just read it.

To Reproduce

  1. Create a mdx file and paste the code from https://v2.docusaurus.io/docs/2.0.0-alpha.69/markdown-features#multi-language-support-code-blocks

  2. start docusaurus

Expected behavior

Docusaurus should compile normaly and show the code like it does the docs site.

Actual Behavior

Docusaurus compiles with error and the site shows an error aswell. grafik

The same error appears on the browser. I just set up a new docusaurus on the latest version and did the same. Same error.

It seems like a closing tag of TabItem is commented out/ inside a string. When not using codeblocks but normal text or other markdown (with a newline), the error still appears.

Your Environment

Reproducible Demo

(Paste the link to an example repo, including a siteConfig.js, and exact instructions to reproduce the issue.) https://github.com/MarvinSzyperski/docus

I really don't know what a siteConfig.js does, sorry.

I found a mdx issue similar to that, with the same error: https://github.com/mdx-js/mdx/issues/1239

slorber commented 3 years ago

Hi,

The MDX parser is quite sensitive to formatting, for example white spaces are important.

I can't help you more because you do not give here. the exact content of your markdown file, and the setup/testx.mdx file is not present in your repro either.

But it works for me:

image

slorber commented 3 years ago

You can validate your mdx content against the mdx parser here to debug issues: https://mdxjs.com/playground

MarvinSzyperski commented 3 years ago

Oh that was my bad the setup/test.mdx file is from the old project, on the repo its under docs/doc.mdx.

Anyway with the playgroud i realized that my IDE changed the indents when pasted and the MDX parser couldnt handle that. It would be nice to mention this somewhere. Now that I changed my IDE to 2 spaces indents it just works fine.

slorber commented 3 years ago

It would be nice to mention this somewhere.

Totally agree, but I'm not sure where exactly.

If you have any suggestion please submit a doc PR.

Closing as you were able to find a solution

antonygibbs commented 2 years ago

Hi,

The MDX parser is quite sensitive to formatting, for example white spaces are important.

I can't help you more because you do not give here. the exact content of your markdown file, and the setup/testx.mdx file is not present in your repro either.

But it works for me:

image

@slorber Can you please share how you acheived this? I and trying to do the same to no avail...

armano2 commented 2 years ago

formatting is important for mdx files

your example:

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

<Tabs
    defaultValue="js"
    values={[
        { label: 'JavaScript', value: 'js', },
        { label: 'Python', value: 'py', },
        { label: 'Java', value: 'java', },
    ]
    }>
    <TabItem value="js">

        ```js
        function helloWorld() {
        console.log('Hello, world!');
    }
</TabItem>
<TabItem value="py">

    ```py
    def hello_world():
    print 'Hello, world!'
    ```

</TabItem>
<TabItem value="java">

    ```java
    class HelloWorld {
    public static void main(String args[]) {
    System.out.println("Hello, World");
}
}
    ```

</TabItem>


and what you want to have is

````mdx
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

<Tabs
  defaultValue="js"
  values={[
      { label: 'JavaScript', value: 'js', },
      { label: 'Python', value: 'py', },
      { label: 'Java', value: 'java', },
  ]}
>
<TabItem value="js">

```js
function helloWorld() {
  console.log('Hello, world!');
}

```py def hello_world(): print 'Hello, world!' ``` ```java class HelloWorld { public static void main(String args[]) { System.out.println("Hello, World"); } } ```


bdw, you can use shorter syntax for this:
label property can be applied on `TabItem`, and if `defaultValue` is not present first tab is going to be chosen

````mdx
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

<Tabs>
<TabItem value="js" label="JavaScript">

```js
function helloWorld() {
  console.log('Hello, world!');
}

```py def hello_world(): print 'Hello, world!' ``` ```java class HelloWorld { public static void main(String args[]) { System.out.println("Hello, World"); } } ```

lylest commented 1 year ago

still not working

dupenodi commented 1 week ago

formatting is important for mdx files

your example:

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

<Tabs
    defaultValue="js"
    values={[
        { label: 'JavaScript', value: 'js', },
        { label: 'Python', value: 'py', },
        { label: 'Java', value: 'java', },
    ]
    }>
    <TabItem value="js">

        ```js
        function helloWorld() {
        console.log('Hello, world!');
    }
</TabItem>
<TabItem value="py">

    ```py
    def hello_world():
    print 'Hello, world!'
    ```

</TabItem>
<TabItem value="java">

    ```java
    class HelloWorld {
    public static void main(String args[]) {
    System.out.println("Hello, World");
}
}
    ```

</TabItem>


and what you want to have is

```mdx
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

<Tabs
  defaultValue="js"
  values={[
      { label: 'JavaScript', value: 'js', },
      { label: 'Python', value: 'py', },
      { label: 'Java', value: 'java', },
  ]}
>
<TabItem value="js">

```js
function helloWorld() {
  console.log('Hello, world!');
}

```py def hello_world(): print 'Hello, world!' ``` ```java class HelloWorld { public static void main(String args[]) { System.out.println("Hello, World"); } } ```


bdw, you can use shorter syntax for this: label property can be applied on `TabItem`, and if `defaultValue` is not present first tab is going to be chosen

```mdx
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

<Tabs>
<TabItem value="js" label="JavaScript">

```js
function helloWorld() {
  console.log('Hello, world!');
}

```py def hello_world(): print 'Hello, world!' ``` ```java class HelloWorld { public static void main(String args[]) { System.out.println("Hello, World"); } } ```

you're truly a saviour!! thank godd for youuu!!!