Skip to content

Commit 3f3d938

Browse files
committed
readme
1 parent 1d9ddd5 commit 3f3d938

File tree

6 files changed

+135
-69
lines changed

6 files changed

+135
-69
lines changed

README-CN.md

Lines changed: 47 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ module: {
4545
{
4646
loader: '@tianyong90/vue-markdown-loader',
4747
options: {
48-
// sourceDir: ''
4948
contentCssClass: 'markdown-body',
5049
markdown: {
5150
lineNumbers: true, // 启用行号
@@ -98,21 +97,12 @@ module: {
9897
test: /\.md$/,
9998
use: [
10099
{
101-
loader: 'vue-loader',
102-
options: {
103-
compilerOptions: {
104-
preserveWhiteSpace: false
105-
}
106-
}
100+
loader: 'html-loader',
107101
},
108102
{
109103
loader: '@tianyong90/vue-markdown-loader',
110104
options: {
111-
// sourceDir: ''
112-
contentCssClass: 'markdown-body',
113-
markdown: {
114-
lineNumbers: true, // 启用行号
115-
}
105+
mode: 'html', // 重要
116106
}
117107
}
118108
]
@@ -124,28 +114,59 @@ module: {
124114
125115
2. 将 `.md` 文件作为 vue 单文件组件导入
126116
127-
```html
128-
<template>
129-
<Hello />
130-
</template>
131-
132-
<script scoped>
117+
```js
133118
import Hello from 'hello.md'
134119
135-
export default {
136-
components: { Hello }
137-
}
138-
</script>
139-
140-
<style>
141-
// 为解析出来的 markdown 元素添加样式
142-
</style>
120+
console.log(Hello)
143121
```
144122
123+
加载的 Hello 结果如下:
124+
125+
![加载后的 html](./images/md-html-string.png)
145126
146127
### 单独使用
147128
129+
vue-markdown-loader 也可以解析 markdown 文件,并返回一个包含 html 字符串供 html-loader 加载。
130+
131+
1. 配置
132+
133+
在 webpack.config.js 中为 .md 文件添加加载规则
134+
135+
```js
136+
module: {
137+
rules: [
138+
{
139+
test: /\.vue$/,
140+
loader: 'vue-loader'
141+
},
142+
{
143+
test: /\.md$/,
144+
use: [
145+
{
146+
loader: '@tianyong90/vue-markdown-loader',
147+
options: {
148+
mode: 'raw', // 重要
149+
contentCssClass: 'markdown-body',
150+
}
151+
}
152+
]
153+
}
154+
]
155+
},
156+
// other options
157+
```
158+
159+
2. 将 `.md` 文件作为一个对象导入
160+
161+
```js
162+
import Hello from 'hello.md'
163+
164+
console.log(Hello)
165+
```
166+
167+
加载后的对象包含 attributes(frontmatter 数据)和 html(解析后的 html 内容),如下图:
148168
169+
![加载后的对象](./images/md-raw-object.png)
149170
150171
## License
151172

images/md-html-string.png

189 KB
Loading

images/md-raw-object.png

44.9 KB
Loading

packages/example/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"babel-loader": "^8.0.5",
1818
"babel-plugin-syntax-dynamic-import": "^6.18.0",
1919
"css-loader": "^3.0.0",
20+
"html-loader": "^0.5.5",
2021
"html-webpack-plugin": "^3.2.0",
2122
"node-sass": "^4.11.0",
2223
"sass-loader": "^8.0.0",

packages/vue-markdown-loader/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
"@typescript-eslint/eslint-plugin": "^2.0.0",
5252
"@typescript-eslint/parser": "^2.0.0",
5353
"babel-loader": "^8.0.5",
54-
"eslint": "^6.0.1",
54+
"eslint": "^6.3.0",
5555
"eslint-config-prettier": "^6.0.0",
5656
"eslint-config-standard": "^14.1.0",
5757
"eslint-friendly-formatter": "^4.0.1",

0 commit comments

Comments
 (0)