I want to achieve the following say i the MD as
JavaScript
x
2
1
md:'#H1'
2
I want to render it as
JavaScript
1
2
1
<h1>H1</h1>
2
I was able to achieve this using VueShowdown
but I want add default class to every h1 tag like
JavaScript
1
2
1
<h1 class="custom">H1</h1>
2
I got something similar to this here.
But I don’t know how to use this in Vue.
Is it even possible in VueShowdown?
Is there any better library which has this functionality?
Advertisement
Answer
You can create a simple directive:
JavaScript
1
9
1
Vue.directive('default-classes', (parentElement) {
2
const els = parentElement.querySelectorAll('h1')
3
4
els.forEach((el) => {
5
el.classList.add('custom')
6
})
7
8
})
9
Then apply that directive to the VueShowdown
component:
JavaScript
1
2
1
<VueShowdown v-default-classes :markdown="markdownBinding" />
2