index.js 2.1 KB

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