Skip to content

Commit ef0c3a0

Browse files
z-ZYS-sQingWei-Li
authored andcommitted
feat: append resourceQuery (QingWei-Li#28)
* append resourceQuery * Add wrapper option
1 parent 2f0a40f commit ef0c3a0

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,20 @@ Since `v2.0.0`, this loader will automatically extract script and style tags fr
6464
}
6565
```
6666

67+
### wrapper
68+
69+
You can customize wrapper tag no matter html element tag or vue component tag. Default is 'section'
70+
71+
```js
72+
{
73+
test: /\.md$/,
74+
loader: 'vue-markdown-loader',
75+
options: {
76+
wrapper: 'article',
77+
}
78+
}
79+
```
80+
6781
### markdownIt
6882

6983
reference [markdown-it](https://github.com/markdown-it/markdown-it#init-with-presets-and-options)

lib/core.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module.exports = function (source) {
1111
var filePath = this.resourcePath
1212

1313
var result = 'module.exports = require(' +
14-
loaderUtils.stringifyRequest(this, '!!vue-loader!' + markdownCompilerPath + '?raw!' + filePath) +
14+
loaderUtils.stringifyRequest(this, '!!vue-loader!' + markdownCompilerPath + '?raw!' + filePath + this.resourceQuery) +
1515
');'
1616

1717
return result

lib/markdown-compiler.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ var renderHighlight = function(str, lang) {
3232
* @param {[type]} html [description]
3333
* @return {[type]} [description]
3434
*/
35-
var renderVueTemplate = function(html) {
35+
var renderVueTemplate = function(html, wrapper) {
3636
var $ = cheerio.load(html, {
3737
decodeEntities: false,
3838
lowerCaseAttributeNames: false,
@@ -49,9 +49,9 @@ var renderVueTemplate = function(html) {
4949
$("script").remove();
5050

5151
result =
52-
"<template><section>" +
52+
`<template><${wrapper}>` +
5353
$.html() +
54-
"</section></template>\n" +
54+
`</${wrapper}></template>\n` +
5555
output.style +
5656
"\n" +
5757
output.script;
@@ -81,7 +81,8 @@ module.exports = function(source) {
8181
{
8282
preset: "default",
8383
html: true,
84-
highlight: renderHighlight
84+
highlight: renderHighlight,
85+
wrapper: 'section'
8586
},
8687
opts
8788
);
@@ -154,7 +155,7 @@ module.exports = function(source) {
154155
source = source.replace(/@/g, "__at__");
155156

156157
var content = parser.render(source).replace(/__at__/g, "@");
157-
var result = renderVueTemplate(content);
158+
var result = renderVueTemplate(content, opts.wrapper);
158159

159160
if (opts.raw) {
160161
return result;

0 commit comments

Comments
 (0)