vp-markdown.vue 776 B

123456789101112131415161718192021222324252627282930
  1. <script lang="ts" setup>
  2. import { computed } from 'vue'
  3. import MarkdownIt from 'markdown-it'
  4. const md = new MarkdownIt()
  5. const props = defineProps({
  6. content: { type: String, required: true },
  7. })
  8. const attr = 'rel="noreferrer noopenner" target="_blank"'
  9. const parsed = computed(() => {
  10. // Note this is relatively arbitrary so that this could be buggy.
  11. return md
  12. .render(props.content)
  13. .replace(/#([0-9]+) by/g, `<a href="https://github.com/element-plus/element-plus/pull/$1" ${attr}>#$1</a> by`)
  14. .replace(/@([A-Za-z0-9_-]+)/g, `<a href="https://github.com/$1" ${attr}>@$1</a>`)
  15. })
  16. </script>
  17. <template>
  18. <div class="markdown-wrapper" v-html="parsed"></div>
  19. </template>
  20. <style>
  21. .markdown-wrapper h3 {
  22. margin-top: 1rem;
  23. }
  24. </style>