index.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. import Vditor from '../src/index'
  2. import '../src/assets/less/index.less'
  3. // new VConsole()
  4. let toolbar
  5. if (window.innerWidth < 768) {
  6. toolbar = [
  7. 'emoji',
  8. 'headings',
  9. 'bold',
  10. 'italic',
  11. 'strike',
  12. 'link',
  13. '|',
  14. 'list',
  15. 'ordered-list',
  16. 'check',
  17. 'outdent',
  18. 'indent',
  19. '|',
  20. 'quote',
  21. 'line',
  22. 'code',
  23. 'inline-code',
  24. 'insert-before',
  25. 'insert-after',
  26. '|',
  27. 'upload',
  28. 'record',
  29. 'table',
  30. '|',
  31. 'undo',
  32. 'redo',
  33. '|',
  34. 'edit-mode',
  35. 'content-theme',
  36. 'code-theme',
  37. 'export',
  38. {
  39. name: 'more',
  40. toolbar: [
  41. 'fullscreen',
  42. 'both',
  43. 'preview',
  44. 'info',
  45. 'help',
  46. ],
  47. }]
  48. }
  49. const initVditor = (language) => {
  50. window.vditor = new Vditor('vditor', {
  51. // _lutePath: `http://192.168.31.194:9090/lute.min.js?${new Date().getTime()}`,
  52. _lutePath: 'src/js/lute/lute.min.js',
  53. cdn: '',
  54. toolbar,
  55. lang: language,
  56. mode: 'wysiwyg',
  57. height: window.innerHeight + 100,
  58. outline: {
  59. enable: true,
  60. position: 'right',
  61. },
  62. debugger: true,
  63. typewriterMode: true,
  64. placeholder: 'Hello, Vditor!',
  65. preview: {
  66. markdown: {
  67. toc: true,
  68. mark: true,
  69. footnotes: true,
  70. autoSpace: true,
  71. },
  72. math: {
  73. engine: 'KaTeX',
  74. inlineDigit: true,
  75. },
  76. },
  77. toolbarConfig: {
  78. pin: true,
  79. },
  80. counter: {
  81. enable: true,
  82. type: 'text',
  83. },
  84. hint: {
  85. emojiPath: 'https://cdn.jsdelivr.net/npm/[email protected]/dist/images/emoji',
  86. emojiTail: '<a href="https://ld246.com/settings/function" target="_blank">设置常用表情</a>',
  87. emoji: {
  88. 'sd': '💔',
  89. 'j': 'https://cdn.jsdelivr.net/npm/[email protected]/dist/images/emoji/j.png',
  90. },
  91. parse: false,
  92. extend: [
  93. {
  94. key: '@',
  95. hint: (key) => {
  96. console.log(key)
  97. if ('vanessa'.indexOf(key.toLocaleLowerCase()) > -1) {
  98. return [
  99. {
  100. value: '@Vanessa',
  101. html: '<img src="https://avatars0.githubusercontent.com/u/970828?s=60&v=4"/> Vanessa',
  102. }]
  103. }
  104. return []
  105. },
  106. },
  107. {
  108. key: '#',
  109. hint: (key) => {
  110. console.log(key)
  111. if ('vditor'.indexOf(key.toLocaleLowerCase()) > -1) {
  112. return [
  113. {
  114. value: '#Vditor',
  115. html: '<span style="color: #999;">#Vditor</span> ♏ 一款浏览器端的 Markdown 编辑器,支持所见即所得(富文本)、即时渲染(类似 Typora)和分屏预览模式。',
  116. }]
  117. }
  118. return []
  119. },
  120. }],
  121. },
  122. tab: '\t',
  123. upload: {
  124. accept: 'image/*,.mp3, .wav, .rar',
  125. token: 'test',
  126. url: '/api/upload/editor',
  127. linkToImgUrl: '/api/upload/fetch',
  128. filename(name) {
  129. return name.replace(/[^(a-zA-Z0-9\u4e00-\u9fa5\.)]/g, '').replace(/[\?\\/:|<>\*\[\]\(\)\$%\{\}@~]/g, '').replace('/\\s/g', '')
  130. },
  131. },
  132. })
  133. }
  134. initVditor('zh_CN')
  135. window.setLang = (language) => {
  136. window.vditor.destroy()
  137. initVditor(language)
  138. }