Markdown and Vue SFC

Each Markdown file is first compiled into HTML, and then converted to a Vue SFC. In other words, you can take Markdown as Vue SFC:

  • Blocks <script> and <style> are treated as Vue SFC blocks as they are. In other words, they are hoisted from the <template> block to the top-level of SFC.
  • Everything outside <script> and <style> will be compiled into HTML, and be treated as Vue SFC <template> block.

Here comes an example:

Input

  1. _Hello, {{ msg }}_
  2. <RedDiv>
  3. _Current count is: {{ count }}_
  4. </RedDiv>
  5. <button @click="count++">Click Me!</button>
  6. <script>
  7. import { h, ref } from 'vue'
  8. const RedDiv = (_, ctx) => h(
  9. 'div',
  10. {
  11. class: 'red-div',
  12. },
  13. ctx.slots.default()
  14. )
  15. export default {
  16. components: {
  17. RedDiv,
  18. },
  19. setup() {
  20. const msg = 'Vue in Markdown'
  21. const count = ref(0)
  22. return {
  23. msg,
  24. count,
  25. }
  26. }
  27. }
  28. </script>
  29. <style>
  30. .red-div {
  31. color: red;
  32. }
  33. </style>

Output

Hello, Vue in Markdown

Current count is: 0

Click Me!