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

Fix newline issue in paragraphs #413

Merged
merged 1 commit into from
Feb 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/mdx/mdx-hast-to-jsx.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,13 @@ MDXContent.isMDXComponent = true`
if (node.type === 'text') {
// Don't wrap newlines unless specifically instructed to by the flag,
// to avoid issues like React warnings caused by text nodes in tables.
if (node.value === '\n' && !preserveNewlines) {
const shouldPreserveNewlines =
preserveNewlines || parentNode.tagName === 'p'
johno marked this conversation as resolved.
Show resolved Hide resolved

if (node.value === '\n' && !shouldPreserveNewlines) {
return node.value
}

return '{`' + node.value.replace(/`/g, '\\`').replace(/\$/g, '\\$') + '`}'
}

Expand Down
18 changes: 18 additions & 0 deletions packages/mdx/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,24 @@ Some text <!-- an inline comment -->
expect(result).toContain('<!-- a template literal -->')
})

it('Should turn a newline into a space with adjacent anchors', async () => {
const result = await renderWithReact(`
[foo](/foo)
[bar](/bar)
`)

expect(result).toContain('<a href="/foo">foo</a>\n<a href="/bar">bar</a>')
})

it('Should turn a newline into a space with other adjacent phrasing content', async () => {
const result = await renderWithReact(`
*foo*
\`bar\`
`)

expect(result).toContain('<em>foo</em>\n<code>bar</code>')
})

it('Should convert style strings to camelized objects', async () => {
const result = await mdx(
`
Expand Down