W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
通過 remark 加載 markdown。
只需將 loader 添加到您的配置中,并設(shè)置 options。
import md from "markdown-file.md";
console.log(md);
webpack.config.js
import RemarkHTML from "remark-html";
module.exports = {
// ...
module: {
rules: [
{
test: /\.md$/,
use: [
{
loader: "html-loader",
},
{
loader: "remark-loader",
options: {
remarkOptions: {
plugins: [RemarkHTML],
},
},
},
],
},
],
},
};
下面是 remark plugins 的完整列表。
我們不再支持任何 react 的特殊功能。 如果您對在 JSX 中使用 Markdown 感興趣,請參閱很棒的 MDX 項目。
Name | Type | Default | Description |
---|---|---|---|
remarkOptions
|
{Object}
|
{}
|
Remark options |
removeFrontMatter
|
{Boolean}
|
true
|
Remove removeFrontMatter |
Name | Type | Default | Description |
---|---|---|---|
plugins
|
Array<String|Array>
|
[]
|
Allows to connect remark plugins |
settings
|
{Object}
|
undefined
|
Remark settings |
data
|
{Object}
|
undefined
|
Information available to all plugins |
Type: ?Array<String|Array>
? Default: []
可以和 remark plugins 一起使用
webpack.config.js
import RemarkFrontmatter from "remark-frontmatter";
module.exports = {
// ...
module: {
rules: [
{
test: /\.md$/,
use: [
{
loader: "remark-loader",
options: {
remarkOptions: {
plugins: [RemarkFrontmatter],
},
},
},
],
},
],
},
};
如果需要為插件指定 options,可以使用數(shù)組傳遞插件,其中第二個參數(shù)就是將要設(shè)置的 options。
webpack.config.js
import RemarkFrontmatter from "remark-frontmatter";
import RemarkBookmarks from "remark-bookmarks";
module.exports = {
// ...
module: {
rules: [
{
test: /\.md$/,
use: [
{
loader: "remark-loader",
options: {
remarkOptions: {
plugins: [
RemarkFrontmatter,
[
RemarkBookmarks,
{
bookmarks: {
npm: "https://npmjs.com/package/remark-bookmarks",
},
},
],
],
},
},
},
],
},
],
},
};
Type: ?Object
? Default: undefined
將 remark-stringify options 選項和 remark-parse options 選項傳遞給 remark。
webpack.config.js
module.exports = {
// ...
module: {
rules: [
{
test: /\.md$/,
use: [
{
loader: "remark-loader",
options: {
remarkOptions: {
settings: {
bullet: "+",
listItemIndent: "1",
},
},
},
},
],
},
],
},
};
Type: ?Object
? Default: undefined
使用所有插件通用的配置 remark。 配置信息存儲在內(nèi)存中的鍵值存儲中。
webpack.config.js
function examplePluginUsingData() {
console.log(this.data);
// { alpha: 'bravo', charlie: 'delta' }
}
module.exports = {
// ...
module: {
rules: [
{
test: /\.md$/,
use: [
{
loader: "remark-loader",
options: {
remarkOptions: {
plugins: [examplePluginUsingData],
data: {
alpha: "bravo",
charlie: "delta",
},
},
},
},
],
},
],
},
};
Type: ?Boolean
? Default: true
默認情況下,refortmatter 是被移除的。 如果要覆蓋這個配置,需要在插件中添加 remark-frontmatter,并設(shè)置 removeFrontMatter 為 false。
webpack.config.js
import RemarkFrontmatter from "remark-frontmatter";
module.exports = {
// ...
module: {
rules: [
{
test: /\.md$/,
use: [
{
loader: "remark-loader",
options: {
removeFrontMatter: false,
remarkOptions: {
plugins: [RemarkFrontmatter],
},
},
},
],
},
],
},
};
這個項目收到了以下開源作品的啟發(fā):
要獲得 html,需要在 remark 插件中添加 remark-html,并在 webpack.config 中添加 html-loader。
import md from "markdown-file.md";
console.log(md);
webpack.config.js
import RemarkHTML from "remark-html";
module.exports = {
// ...
module: {
rules: [
{
test: /\.md$/,
use: [
{
loader: "html-loader",
},
{
loader: "remark-loader",
options: {
remarkOptions: {
plugins: [RemarkHTML],
},
},
},
],
},
],
},
};
index.js
import md from "markdown-file.md";
console.log(md);
webpack.config.js
module.exports = {
// ...
module: {
rules: [
{
test: /\.md$/,
use: [
{
loader: "remark-loader",
},
],
},
],
},
};
如果您還沒有貢獻代碼,請花點時間閱讀我們的貢獻指南。
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: