FormidableLabs / FormidableLabs/spectacle

[docs] Markdown needs to be escaped in jsx

Open
#1,170 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
10.2k
Forks
700
PR merge metrics
No merged PRs in 30d

Description

### Prerequisites

**Feel free to delete this section if you have checked off all of the following.**

- [x] I've searched open [issues](https://www.github.com/FormidableLabs/spectacle/issues) to make sure I'm not opening a duplicate issue
- [x] I have read through the [docs](https://www.formidable.com/open-source/spectacle/docs) before asking a question
- [x] I am using the latest version of Spectacle

### Describe Your Environment

What version of Spectacle are you using? (can be found by running `npm list spectacle`)

9.3.0

What version of React are you using? (can be found by running `npm list react`)

18.2.0

What browser are you using?

firefox (not relevant)

What machine are you on?

mac (not relevant)

### Describe the Problem

Any text inside the Markdown component when used with jsx (ie. if slides are declared in multiple files and imported) will have its newlines killed during parsing. Since markdown is a newline/whitespace sensitive markup syntax, this kills the markdown.

eg. if i do this:

```jsx
export const MySlide = (

# Title

- List
- Items

)
```

will be rendered as

```html

Title - List -Items


```

This happens at the time of declaration as far as I can tell, as if I put a `console.log` just after declaring the variable it already shows its children as a collapsed string without newlines.

### Solution

To make it work, I needed to wrap the inside of a markdown component like this:

```jsx
export const MySlide = (

{`
# Title

- List
- Items
`}

)
```

Which properly preserves the newlines. This should be added to the docs!!!

### Additional Information

I'm using

- webpack (5.74.0)
- @babel/preset-react (7.18.6)

to parse the jsx

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.