-
-
Notifications
You must be signed in to change notification settings - Fork 11
Open
Description
- Operating System: MacOS
- Node Version: 12.18.3
- NPM Version: 6.14.6
- webpack Version: 5.35.0
- remark-loader Version: 4.0.0
Expected Behavior
The examples in readme show console.log()
but not what might be returned.
This might also be a bug, but I can't tell at the moment.
Do we expect...
- Importing a markdown doc returns module.default that is raw html content?
OR
- Importing a markdown doc returns module.default that is a path/URL to a compiled markdown file (e.g. raw as html, when using RemarkHTML). The path can then be returned using something like
fetch()
?
Actual Behavior
Importing a markdown doc returns a path to a compiled JS file, so accessing the raw html requires a double import. Though webpack IIRC won't handle double imports (too dynamic to know what the path will be).
Code
// webpack.config.js
{
test: /\.md$/,
use: [
{
loader: require.resolve("html-loader"),
},
{
loader: require.resolve("remark-loader"),
options: {
remarkOptions: {
plugins: [RemarkHTML],
},
},
},
],
},
// currently trying to do something like this, except this displays JS code instead of HTML:
const Body = React.lazy(() =>
import("../../assets/documents/" + doc + ".md")
.then((url) => fetch(url.default))
.then((res) => res.text())
.then((content) => {
console.log(content); // 1
return ({
default: () => (
<div dangerouslySetInnerHTML={{__html: content}}/>
),
});
}),
// content string at 1 looks like:
// module
var code = "<h1>lorem ipsum....";
export default code;
NB There are some other webpack module rules applied (fairly standard rules for handling images, css, JS), but at the moment I can't see how/if they impact on the remark-loader behaviour.
aidanm1999 and freshgum-bubbles
Metadata
Metadata
Assignees
Labels
No labels