-
Notifications
You must be signed in to change notification settings - Fork 918
[feature] A smart way to support markdown template language #847
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
If I remember correctly, markdown should support nested (html & markdown) syntax. |
I think it's too coupled with the template compiler. How about creating a markdown custom block to doing this job? That's more flexible. |
Actually I know that my solution is not very suitable for vue-loader. I've tried to use markdown filter in some template engines (e.g pug), but vue-loader can not detect the changes of markdown files which is imported by template engine. It's a critical problem when using webpack-dev-server and I found no way to treat it. |
I've read the documentation of custom block, I think it's no so convenient for my case. HTML and markdown and value bindings mixed everywhere, no such a single custom block can hold it. for example: <template lang="md">
# {{title}}
## {{subtitle}} - The first Component
<x-component></x-component>
## {{subtitle}} - The Second Component
<y-component></y-component>
... and so on
</template>
<script>
import {XComponent, YComponent} from 'somewhere'
export default {
props: ['title', 'subtitle'],
components: {
XComponent,
YComponent
}
}
</script> |
Anyway, I think you also could try to use markdown |
I have tried to create a markdown-loader like: const compiler = require('vue-template-compiler')
const marked = require('marked')
module.exports = function (markdown, map) {
// markdown -> html
const html = marked(markdown)
// html -> render functions
const { render, staticRenderFns } = compiler.compile(`<div>\n${html}</div>`)
return `
module.exports = function (Component) {
Component.options.render = function () {${render}}
Component.options.staticRenderFns = [${staticRenderFns.join(',')}]
}`
} And it worked well with: <markdown>
# {{title}}
## {{subtitle}} - The first Component
</markdown>
<script>
export default {
data () {
return {
title: 'Hello',
subtitle: 'Welcome to Your Vue.js App'
}
}
}
</script> I think that can help you enough. Thanks. |
Well, I got it. It seems perfect. |
Additionally I found another way in our test to have a look: Line 648 in aaf724d
|
Problem
I met a critical problem when I followed #595 to compile markdown template in vue components.
While compiling markdown template with more than single line, the component template won't contain a root element, and the markdown specification doesn't allowed us to add a wrapper.
Input
<-- Case 1 --> <template> # Hello world! ## FooBar </template> <-- Case 2 --> <template> <div> # Hello world! ## FooBar </div> </template>
Expect Output
Actual Output
Solution
As far as I know, the dependency consolidate.js of template compiler has no plan to support markdown syntax (See details: tj/consolidate.js#45). I has added a dependency markdown-it to treat this case, because other famous markdown parsers (e.g. marked) will overwrite ids of
h1 - h6
elements.Usage
I think this is a smart way to use markdown template.