Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Whitespace Required Between React Component and Fenced Code Block #607

Closed
gchallen opened this issue Jun 18, 2019 · 1 comment
Closed

Whitespace Required Between React Component and Fenced Code Block #607

gchallen opened this issue Jun 18, 2019 · 1 comment

Comments

@gchallen
Copy link

gchallen commented Jun 18, 2019

Subject of the issue

Extra new lines seem to be required to include fenced code blocks inside React components using MDX. This would technically violate the CommonMark spec, although that spec obviously doesn't define how Markdown and React components should mix 😄.

Your environment

  • Mac OS 18.6.0
  • Latest my-mdx-starter project created using Gatsby
  • See above. Chrome browser.

Steps to reproduce

This works:

<SomeComponent>

```
public class Test {
    public static void main() {
    }
}
```

</SomeComponent>

But this produces a parse error:

<SomeComponent>
```
public class Test {
    public static void main() {
    }
}
```
</SomeComponent>

Expected behaviour

MDX should parse the fenced code block without the extra whitespace. While this seems like a fairly small issue, fenced code blocks already introduce extra whitespace, and the additional blank line starts to lose some of the terseness benefits we were hoping to gain through MDX.

It would be even better if something like this would work:

<SomeComponent>```
public class Test {
    public static void main() {
    }
}
```</SomeComponent>

Or even:

<SomeComponent source=```
public class Test {
    public static void main() {
    }
}
```/>

Actual behaviour

A parse error.

Additional information

We're trying to use MDX for examples that need to render 2 or sometimes 3 separate code snippets. We've tried a variety of different ways to do this, but our attempts using JS template literals are bumping up against this previous issue which still seems unresolved.

For example, this causes a parsing error due to the blank line:

<Example reference={`
public class Test {
    public static void main() {

    }
}
`} />

Either this or the inline fenced blocks shown above would probably be our preferred approach if it did work. The above is an attempt at a workaround.

@gchallen
Copy link
Author

As an addendum to the issue reported above, this seems like it is expected behavior when mixing HTML (/React?) components and Markdown. So not something that can be addressed in MDX.

I'll close this and go +1 the open issue involving empty lines in template literals.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant