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

Absolute path to the @mdx-js/tag #234

Closed
wants to merge 3 commits into from
Closed
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
12 changes: 9 additions & 3 deletions packages/loader/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,19 @@ const mdx = require('@mdx-js/mdx')

module.exports = async function(content) {
const callback = this.async()
const options = getOptions(this)
const options = getOptions(this) || {}

const result = await mdx(content, options || {})
const result = await mdx(content, options)

let modulePath = '@mdx-js/tag'

if (options.absolutePath) {
modulePath = require.resolve(modulePath)
}

const code = `
import React from 'react'
import { MDXTag } from '@mdx-js/tag'
import { MDXTag } from '${modulePath}'
${result}
`

Expand Down
4 changes: 4 additions & 0 deletions packages/loader/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,7 @@ module: {
]
}
```

## Options

`absolutePath` - use absolute path to `@mdx-js/tag` instead relative
7 changes: 6 additions & 1 deletion packages/loader/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ const testFixture = (fixture, options = {}) => {
}
},
{
loader: path.resolve(__dirname, '..')
loader: path.resolve(__dirname, '..'),
options
}
]
}
Expand All @@ -52,3 +53,7 @@ const testFixture = (fixture, options = {}) => {
test('it loads markdown and returns a component', async () => {
await testFixture('fixture.md')
})

test('it loads markdown with adsolute path to the @mdx-js/tag', async () => {
await testFixture('fixture.md', { absolutePath: true })
})