index.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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: 'http://localhost:9000',
  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. },
  75. },
  76. toolbarConfig: {
  77. pin: true,
  78. },
  79. counter: {
  80. enable: true,
  81. type: 'text',
  82. },
  83. hint: {
  84. emojiPath: 'https://unpkg.com/[email protected]/dist/images/emoji',
  85. emojiTail: '<a href="https://ld246.com/settings/function" target="_blank">设置常用表情</a>',
  86. emoji: {
  87. 'sd': '💔',
  88. 'j': 'https://unpkg.com/[email protected]/dist/images/emoji/j.png',
  89. },
  90. parse: false,
  91. extend: [
  92. {
  93. key: '@',
  94. hint: (key) => {
  95. console.log(key)
  96. if ('vanessa'.indexOf(key.toLocaleLowerCase()) > -1) {
  97. return [
  98. {
  99. value: '@Vanessa',
  100. html: '<img src="https://avatars0.githubusercontent.com/u/970828?s=60&v=4"/> Vanessa',
  101. }]
  102. }
  103. return []
  104. },
  105. },
  106. {
  107. key: '#',
  108. hint: (key) => {
  109. console.log(key)
  110. if ('vditor'.indexOf(key.toLocaleLowerCase()) > -1) {
  111. return [
  112. {
  113. value: '#Vditor',
  114. html: '<span style="color: #999;">#Vditor</span> ♏ 一款浏览器端的 Markdown 编辑器,支持所见即所得(富文本)、即时渲染(类似 Typora)和分屏预览模式。',
  115. }]
  116. }
  117. return []
  118. },
  119. }],
  120. },
  121. tab: '\t',
  122. upload: {
  123. accept: 'image/*,.mp3, .wav, .rar',
  124. token: 'test',
  125. url: '/api/upload/editor',
  126. linkToImgUrl: '/api/upload/fetch',
  127. filename(name) {
  128. return name.replace(/[^(a-zA-Z0-9\u4e00-\u9fa5\.)]/g, '').replace(/[\?\\/:|<>\*\[\]\(\)\$%\{\}@~]/g, '').replace('/\\s/g', '')
  129. },
  130. },
  131. })
  132. }
  133. initVditor('zh_CN')
  134. window.setLang = (language) => {
  135. window.vditor.destroy()
  136. initVditor(language)
  137. }