question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Backslash doesn't insert a br

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
alexandernanbergcommented, Mar 29, 2019

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!

0reactions
wooormcommented, Mar 1, 2019

That could be it!

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

console.log(`a\
b`)
//=> 'ab'
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to insert a line break <br> in markdown - Stack Overflow
Try adding 2 spaces (or a backslash \ ) after the first line: [Name of link](url) My line of text\. Visually: [Name of...
Read more >
Automatic line break with backslash in listings - TeX
I have found two answers to my question, both of which allow backslashes to be correctly styled when used for automatic line-breaking with ......
Read more >
HTML Line Break – How to Break a Line with the HTML <br ...
You can insert line breaks in HTML with the <br> tag, which is equivalent to a carriage return on a keyboard. Be aware...
Read more >
Make line breaks work when you render text in a React or Vue ...
... if you were to put it into a React (or Vue) component, like this: ... is split up the string and then...
Read more >
How to Get Line Breaks In Markdown
If you do not use spaces or backslashes, your line break will not render in the HTML output even though you have a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found