Comments (1)
I understand how it can be confusing, but this is how Webpack loaders work.
JSX tags (both in MDX and React files) are rendered as-is, unprocessed, so it is your responsibility to ensure that the <a>
href
prop you provide to them is correct. For Markdown files.
For Markdown files, we make the assumption that a link with an extension is likely to download the file. This is fine because user still has the possibility to use JSX to opt-out of this Markdown link behavior, and having a different behavior for JSX is there on purpose.
Please consider the following JSX:
<div>
<a href={require('./test.csv').default}>Download test.csv</a>
</div>
<div>
The CSV file content is:
<pre>{require('./test.csv').default}
</div>
As you can see, requiring a CSV file can mean different things to different people. They might want to provide a link to that CSV, or they might want to display the content of the file itself. When using Markdown, the case is more limited because the 2nd case doesn't apply here.
It's impossible for Docusaurus to provide an opinion on how files should be loaded that would make all users happy, for that reason we only provide an opinion on the most common media files, and let users add their own opinions through custom Webpack config if they want to.
It's impossible for us to automatically support CSV as a downloadable format in Docusaurus, because many users will not want that. But if on your site, you are sure all CSV files are downloadable files and not rendered inline, you can use the configureWebpack
hook to register your own Webpack loader
Demo time
https://stackblitz.com/edit/github-a18bvz-rmfzbj?file=docs%2Fintro.md
<ul>
<li>{JSON.stringify(require('./test.docx'))}</li>
<li>{JSON.stringify(require('./test.csv'))}</li>
<li>{JSON.stringify(require('!file-loader?name=assets/files/[name]-[contenthash].[ext]!./test.csv'))}</li>
</ul>
An alternative to using configureWebpack
could be to use inline webpack loaders. In practice this is what we actually do with Markdown links.
You can provide a sensible default thanks to the Webpack global config, but you can also decide on a case-by-case basis what does it mean for Webpack to require a file, overriding that default config.
from docusaurus.
Related Issues (20)
- Updating to 3.2 breaks tailwind integration in production HOT 17
- Usage of polyfill configuration throws error HOT 6
- Code block highlighting in combination with showLineNumbers not rendering correctly HOT 1
- TOC items don't show words when they come from components HOT 2
- TOC shows comments in headings HOT 2
- HTML email addresses get rendered as nested links, ignoring `href` attribute HOT 2
- Allow codeblocks to show only part of the content HOT 2
- Broken anchors: page not scroll to the right section HOT 8
- Index pages cannot be generated with an automatically generated siderbar HOT 1
- Document solution to "docs last update" date being rendered incorrectly when published through Vercel
- Customizing admonitions not work HOT 3
- When testing on StrictMode, the bar remains on the top HOT 1
- Node.js building getting stuck HOT 2
- Updating to @mdx-js/react 3.0.1 causes admonition blocks to stop rendering colored box HOT 8
- The <!--truncate--> line in my long blog post on the initialized website is not causing the blog post size to be limited. HOT 1
- Add trailing slash to auto generated sitemap.xml for directories only HOT 3
- blogTitle not working HOT 4
- 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.