0๐
If you are using VuePress 1.x you can use a MarkDown Slot and a Vue component to mimic the directory structure you referenced. It gets tricky because the VuePress style theme overwrites some of the css, so you need to get hacky with it in the mounted()
Vue lifecycle hook. To get this working first create the Directory.vue
component and second create a MarkDown Slot in a .md
file and consume it with the <Directory slotKey='slot-name' />
component.
docs
โโ src
โโ .vueress
| โโ components
| | โโ Directory.vue
| |
| โโ config.js
|
โโ consumer
โโ README.md
- Directory.vue
<template>
<div ref="directory" class="directory">
<Content v-bind:slot-key="slotKey" />
</div>
</template>
<script>
export default {
props: {
slotKey: String,
codeColor: {
type: String,
default: 'azure'
},
codeBackground: {
type: String,
default: 'rgb(87, 87, 87)'
}
},
mounted() {
// Get the div ref named directory
const directory = this.$refs.directory
// Remove all the <br> tags that get added
directory.innerHTML = directory.innerHTML.replace(/<br>/g, '')
const first = directory.firstChild // <div class="content__vue">
const second = first.firstChild // <p>
const codes = second.getElementsByTagName('code') // all the <code> tags
// Change style here to overwrite the theme
Array.from(codes).forEach((el) => {
el.style.color = this.codeColor
el.style.backgroundColor = this.codeBackground
})
}
}
</script>
<style scoped>
.directory {
padding: 10px;
border-radius: 10px;
font-family: monospace;
white-space: pre;
background-color: rgb(48, 48, 48);
color: rgb(184, 184, 184);
}
</style>
- README.md
<!-- Here we consume the MarkDown Slot in the Directory Vue component -->
<Directory slotKey="my-dir" />
<!-- Here is the MarkDown Slot -->
::: slot my-dir
.
โโโ docs
โโโ .vuepress _(**Optional**)_
โโโ `components` _(**Optional**)_
โโโ `theme` _(**Optional**)_
:::
Note that the MarkDown Slot needs to be in the same file that it is being consumed in. The Slot will not be rendered unless you consume it with the native VuePress component Content
.
By the way I think you meant to use the ::: v-pre
referenced VuePress/Escaping
Source:stackexchange.com