index.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. import Vditor from '../src/index'
  2. import '../src/assets/scss/index.scss'
  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. window.vditor = new Vditor('vditor', {
  50. _lutePath: `http://192.168.0.107:9090/lute.min.js?${new Date().getTime()}`,
  51. // _lutePath: 'src/js/lute/lute.min.js',
  52. toolbar,
  53. mode: 'wysiwyg',
  54. height: window.innerHeight + 100,
  55. outline: {
  56. enable: true,
  57. position: 'right',
  58. },
  59. debugger: true,
  60. typewriterMode: true,
  61. placeholder: 'Hello, Vditor!',
  62. preview: {
  63. markdown: {
  64. toc: true,
  65. mark: true,
  66. footnotes: true,
  67. autoSpace: true,
  68. },
  69. math: {
  70. engine: 'KaTeX',
  71. },
  72. },
  73. toolbarConfig: {
  74. pin: true,
  75. },
  76. counter: {
  77. enable: true,
  78. type: 'text',
  79. },
  80. hint: {
  81. emojiPath: 'https://cdn.jsdelivr.net/npm/[email protected]/dist/images/emoji',
  82. emojiTail: '<a href="https://ld246.com/settings/function" target="_blank">设置常用表情</a>',
  83. emoji: {
  84. 'sd': '💔',
  85. 'j': 'https://unpkg.com/[email protected]/dist/images/emoji/j.png',
  86. },
  87. extend: [
  88. {
  89. key: '@',
  90. hint: (key) => {
  91. console.log(key)
  92. if ('vanessa'.indexOf(key.toLocaleLowerCase()) > -1) {
  93. return [
  94. {
  95. value: '@Vanessa',
  96. html: '<img src="https://avatars0.githubusercontent.com/u/970828?s=60&v=4"/> Vanessa',
  97. }]
  98. }
  99. return []
  100. },
  101. },
  102. {
  103. key: '#',
  104. hint: (key) => {
  105. console.log(key)
  106. if ('vditor'.indexOf(key.toLocaleLowerCase()) > -1) {
  107. return [
  108. {
  109. value: '#Vditor',
  110. html: '<span style="color: #999;">#Vditor</span> ♏ 一款浏览器端的 Markdown 编辑器,支持所见即所得(富文本)、即时渲染(类似 Typora)和分屏预览模式。',
  111. }]
  112. }
  113. return []
  114. },
  115. }],
  116. },
  117. tab: '\t',
  118. upload: {
  119. accept: 'image/*,.mp3, .wav, .rar',
  120. token: 'test',
  121. url: '/api/upload/editor',
  122. linkToImgUrl: '/api/upload/fetch',
  123. filename (name) {
  124. return name.replace(/[^(a-zA-Z0-9\u4e00-\u9fa5\.)]/g, '').
  125. replace(/[\?\\/:|<>\*\[\]\(\)\$%\{\}@~]/g, '').
  126. replace('/\\s/g', '')
  127. },
  128. },
  129. })