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(tables) remove new line backtick wrapping #180

Merged
merged 1 commit into from
Jul 6, 2018
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: 6 additions & 0 deletions examples/next/md/markdown.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@ import Other from './other.md'
Here's a paragraph

https://c8r.imgix.net/028ab8c85da415103cb3b1eb/johno.png

Here's a table

| Test | Table |
| :--- | :---- |
| Col1 | Col2 |
4 changes: 2 additions & 2 deletions packages/mdx/mdx-hast-to-jsx.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ function toJSX(node, parentNode = {}) {
}${props ? ` props={${props}}` : ''}>${children}</MDXTag>`
}

// Wraps all text nodes inside template string, so that we don't run into escaping issues.
// Wraps all text nodes except new lines inside template string, so that we don't run into escaping issues.
if(node.type === 'text') {
return '{`' + node.value.replace(/`/g, '\\`').replace(/\$/g, '\\$') + '`}'
return node.value === '\n' ? node.value : '{`' + node.value.replace(/`/g, '\\`').replace(/\$/g, '\\$') + '`}'
}

if (
Expand Down
4 changes: 4 additions & 0 deletions packages/mdx/test/fixtures/blog-post.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,8 @@ module.exports = 'test'
npm i -g foo
```

| Test | Table |
| :--- | :---- |
| Col1 | Col2 |

export default ({children}) => <div>{children}</div>
16 changes: 12 additions & 4 deletions packages/mdx/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,24 @@ it('Should render HTML inside inlineCode correctly', async () => {
).toBeTruthy()
})

it('Should recognize components as propertiess', async () => {
const result = await mdx('# Hello\n\n<MDX.Foo />')

it('Should recognize components as properties', async () => {
const result = await mdx('# Hello\n\n<MDX.Foo />')
expect(
result.includes(
'<MDXTag name="h1" components={components}>{`Hello`}</MDXTag>{`\n`}<MDX.Foo />'
'<MDXTag name="h1" components={components}>{`Hello`}</MDXTag>\n<MDX.Foo />'
)
).toBeTruthy()
})

it('Should render elements without wrapping blank new lines', async () => {
const result = await mdx(`
| Test | Table |
| :--- | :---- |
| Col1 | Col2 |`)

expect(result.includes('{`\n`}')).toBe(false)
})

test('Should await and render async plugins', async () => {
const result = await mdx(fixtureBlogPost, {
hastPlugins: [
Expand Down
6 changes: 0 additions & 6 deletions packages/mdx/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,6 @@
lodash "^4.2.0"
to-fast-properties "^2.0.0"

"@mdx-js/mdxast@^0.7.2":
version "0.7.2"
resolved "https://registry.yarnpkg.com/@mdx-js/mdxast/-/mdxast-0.7.2.tgz#588e3ad617465ca4b67a50c0079f222fb2d65614"
dependencies:
unist-util-visit "^1.3.0"

abab@^1.0.4:
version "1.0.4"
resolved "https://registry.yarnpkg.com/abab/-/abab-1.0.4.tgz#5faad9c2c07f60dd76770f71cf025b62a63cfd4e"
Expand Down