index.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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: true,
  56. debugger: true,
  57. typewriterMode: true,
  58. placeholder: 'Hello, Vditor!',
  59. preview: {
  60. markdown: {
  61. toc: true,
  62. },
  63. },
  64. toolbarConfig: {
  65. pin: true,
  66. },
  67. counter: {
  68. enable: true,
  69. type: 'text',
  70. },
  71. hint: {
  72. emojiPath: 'https://cdn.jsdelivr.net/npm/[email protected]/dist/images/emoji',
  73. emojiTail: '<a href="https://hacpai.com/settings/function" target="_blank">设置常用表情</a>',
  74. emoji: {
  75. 'sd': '💔',
  76. 'j': 'https://unpkg.com/[email protected]/dist/images/emoji/j.png',
  77. },
  78. at: (key) => {
  79. if ('vanessa'.indexOf(key.toLocaleLowerCase()) > -1) {
  80. return [
  81. {
  82. value: '@Vanessa',
  83. html: '<img src="https://avatars0.githubusercontent.com/u/970828?s=60&v=4"/> Vanessa',
  84. }]
  85. }
  86. return []
  87. },
  88. },
  89. tab: '\t',
  90. upload: {
  91. accept: 'image/*,.mp3, .wav, .rar',
  92. token: 'test',
  93. url: '/api/upload/editor',
  94. linkToImgUrl: '/api/upload/fetch',
  95. filename (name) {
  96. return name.replace(/[^(a-zA-Z0-9\u4e00-\u9fa5\.)]/g, '').
  97. replace(/[\?\\/:|<>\*\[\]\(\)\$%\{\}@~]/g, '').
  98. replace('/\\s/g', '')
  99. },
  100. },
  101. })