Comments (3)
Your issue is not super clear, so I'm going to clarify it.
You are using this tag in your Markdown content:
## Heading
<img src={testImg} />
As far as I understand you expect MDXComponents/Img
to be the component used to render it.
In practice it is not the case, right?
This is working as intended and is a MDX v2 breaking change, documented on our migration guide + the MDX docs/changelog.
We have documented this here:
https://docusaurus.io/docs/migration/v3#lower-case-mdxcomponent-mapping
If you provide a MDX component with key img
, it will now only be used to render Markdown images (![alt](src)
), and not anymore <img>
tags.
However if you provided a mapping for Img
, you would be able to write <Img src={testImg} />
Upper-case and lower-case components are now treated differently by MDX, on purpose.
This is briefly documented here as a breaking change of MDX v2:
We now โsandboxโ components, for lack of a better name. It means that when you pass a component for h1, it does get used for
# hi
but not for<h1>hi</h1>
Note: technically if you care about restoring the former MDX behavior, you can do it by writing a remark plugin to process the lowercase tag and upper-casing it.
An example:
import type {Transformer} from 'unified';
import type {MdxJsxFlowElement} from 'mdast-util-mdx';
export default function plugin(): Transformer {
return async (root) => {
const {visit} = await import('unist-util-visit');
visit(root, 'mdxJsxFlowElement', (node: MdxJsxFlowElement) => {
if (node.name === 'img') {
node.name = 'Img';
}
});
};
}
This is not standard MDX v2+ anymore so it's now your responsibility to figure out if this is a good idea or not.
from docusaurus.
@t1m0thyj i explained above that indeed the remark plugin is required.
That lowercase mapping will only work with md image syntax, not img tags.
That's not Docusaurus, that's how MDX v2+ works
Edit:I made a case typo in my comment just fixed it.
from docusaurus.
@slorber Thanks for providing guidance on how to migrate img
components in Docusaurus v3.
However if you provided a mapping for
Img
, you would be able to write<img src={testImg} />
By "providing a mapping", do you mean the following?
export default {
...MDXComponents,
img: MyCustomImageComponent,
Img: MyCustomImageComponent,
}
I expected this would register my custom image component for both Markdown images and the img
tag. But it didn't work for the img
tag until I added the Remark plugin that you suggested. So I have a workaround but am wondering if I'm missing something related to the mapping?
from docusaurus.
Related Issues (20)
- Updating to 3.2 breaks tailwind integration in production HOT 17
- Place screenshots in the themes documentation page in the site HOT 3
- Passing custom props to IdealImage HOT 2
- Spaces are no longer valid in links HOT 4
- Cannot load docs from outside local package root when running as a Yarn workspace HOT 8
- Mermaid diagram shift page when opening a link with anchor HOT 1
- An error occurred when importing a global component. The component cannot be found HOT 1
- Error messages set to `vfile` by Remark plugins are not reported. HOT 1
- Use pure examples in github action deployment examples HOT 1
- When multiple i18n are configured, the plug-in will report an error when using the Link tag. HOT 1
- Can't find component when using NX and NPM Workspaces HOT 2
- Add comparison to vitepress HOT 2
- Module not found: Error: Can't resolve 'react-loadable' in '.../node_modules/@docusaurus/core/lib/client/exports' HOT 1
- BrowserOnly, lazy, and useHistory result in infinite re-rendering HOT 1
- Output HTML contains NULL chracters in at least CJK languages HOT 10
- Documentation should also teach registering anchors in plugin code HOT 6
- The mdx-code-block is not compatible with Windows. HOT 3
- Using partial props in links causes false positive `onBrokenLinks` HOT 2
- SPA opt-out: make prefetching/preloading and routing configurable HOT 8
- The MDX compiler encounters an error when a listitem element appears directly before the closing </tab> tag without proper indentation HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from docusaurus.