Hello,
I use markdown-it module to parse .md
files, with this component to convert internal links :
<template>
<div v-html="content">
</div>
</template>
<script>
export default {
props: ['content'],
mounted() {
this.addListeners()
},
beforeDestroy() {
this.removeListeners()
},
watch: {
'content': 'contentUpdated'
},
methods: {
navigate(event) {
const href = event.target.getAttribute('href')
if (href && href[0] === '/') {
event.preventDefault()
this.$router.push(href)
}
},
contentUpdated() {
this.removeListeners()
this.$nextTick(() => {
this.addListeners()
})
},
addListeners() {
this._links = this.$el.getElementsByTagName('a')
for (let i = 0; i < this._links.length; i++) {
this._links[i].addEventListener('click', this.navigate, false)
}
},
removeListeners() {
for (let i = 0; i < this._links.length; i++) {
this._links[i].removeEventListener('click', this.navigate, false)
}
this._links = []
}
}
}
</script>
It works fine but the content of the .md
is not html rendered with nuxt generate
, but instead stored in the js...
Any idea?
Thanks!
<!--cmty--><!--cmty_prevent_hook--><div align="right"><sub><em>This question is available on <a href="https://nuxtjs.cmty.io">Nuxt.js</a> community (<a href="https://nuxtjs.cmty.io/nuxt/nuxt.js/issues/c2488">#c2488</a>)</em></sub></div>