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

Backslash doesn't insert a br #421

Closed
alexandernanberg opened this issue Feb 28, 2019 · 5 comments
Closed

Backslash doesn't insert a br #421

alexandernanberg opened this issue Feb 28, 2019 · 5 comments

Comments

@alexandernanberg
Copy link

Subject of the issue

I've been using \ for new lines in my markdown files and it worked great with rehype etc. Migrated to MDX and noticed it didn't work the same way. Not 100% sure if this is a standard way of inserting new lines or not.

Your environment

  • MacOS 10.14.1
  • @mdx-js/mdx @ 0.18.1
  • Node @ v10.15.0

Steps to reproduce

(async () => {
  const result = await mdx(`
# Hello, MDX

**Hello**\
I <3 Markdown and JSX
`)
  console.log(result)
})()

Expected behaviour

Backslash (\) should be converted to a <br/> element

Actual behaviour

It's just omitted

@wooorm
Copy link
Member

wooorm commented Feb 28, 2019

Did you try passing commonmark: true? That should be needed with just remark as well.

It seems it’s passed down to remark-parse btw

@alexandernanberg
Copy link
Author

alexandernanberg commented Feb 28, 2019

I suppose you mean like this?

const result = await mdx(
  `
# Hello, MDX

**Hello**\ 
I <3 Markdown and JSX
`,
  {
    commonmark: true,
  },
)

Same output when trying that

@alexandernanberg
Copy link
Author

Did some digging and I think this is the cause. Not sure how to solve it though

@wooorm
Copy link
Member

wooorm commented Mar 1, 2019

That could be it!

Or maybe because you use a slash in a template literal:

console.log(`a\
b`)
//=> 'ab'

@alexandernanberg alexandernanberg changed the title Backslash don't insert a br Backslash doesn't insert a br Mar 27, 2019
@alexandernanberg
Copy link
Author

Oh my bad, had no idea that backslash didn't work in template strings. Adding commonmark: true in my gatsby-mdx options solved it for me!

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

2 participants