markdown-renderer.blade.php 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. @props(['content' => '', 'class' => ''])
  2. <div
  3. class="markdown-content {{ $class }}"
  4. x-data="{
  5. init() {
  6. if (typeof window.renderMarkdown === 'function') {
  7. window.renderMarkdown(@js($content), this.$el);
  8. } else {
  9. // 如果渲染函数未加载,等待加载
  10. setTimeout(() => {
  11. if (typeof window.renderMarkdown === 'function') {
  12. window.renderMarkdown(@js($content), this.$el);
  13. }
  14. }, 100);
  15. }
  16. }
  17. }"
  18. x-init="init()"
  19. >
  20. <!-- Markdown 内容将在这里渲染 -->
  21. <div class="text-gray-500 italic">
  22. Loading markdown content...
  23. </div>
  24. </div>
  25. @once
  26. @push('scripts')
  27. <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>
  28. <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/github.min.css">
  29. <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.13.11/katex.min.css">
  30. @endpush
  31. @endonce