InputEditorPreview.vue 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <template>
  2. <div class='input_editor_preview__markdownHTML'>
  3. <div v-html='HTML' style='margin-top: -0.5rem;'></div>
  4. <div v-if='!value.trim().length' class='input_editor_preview__markdownHTML--empty'>
  5. Nothing to preview
  6. </div>
  7. </div>
  8. </template>
  9. <script>
  10. import throttle from 'lodash.throttle'
  11. import Marked from 'marked'
  12. Marked.setOptions({
  13. highlight: function (code) {
  14. return require('highlight.js').highlightAuto(code).value;
  15. },
  16. sanitize: true
  17. });
  18. let usernames = {}
  19. export default {
  20. name: 'InputEditorPreview',
  21. props: ['value', 'mentions'],
  22. computed: {
  23. HTML () {
  24. let replacedMd = this.value
  25. ;(this.mentions || []).forEach(mention => {
  26. let regexp = new RegExp('(^|\\s)@' + mention + '($|\\s)')
  27. replacedMd = replacedMd.replace(regexp, `$1[@${mention}](/user/${mention})$2`)
  28. })
  29. return Marked(replacedMd);
  30. }
  31. }
  32. }
  33. </script>
  34. <style lang='scss' scoped>
  35. @import '../assets/scss/variables.scss';
  36. .input_editor_preview {
  37. @at-root #{&}__markdownHTML {
  38. height: 8.2rem;
  39. overflow: auto;
  40. word-break: break-word;
  41. padding: 0.5rem;
  42. @at-root #{&}--empty {
  43. @include text($font--role-emphasis, 1rem);
  44. display: flex;
  45. margin-top: 0.5rem;
  46. align-content: center;
  47. @include user-select(none);
  48. cursor: default;
  49. color: $color__gray--darker;
  50. }
  51. }
  52. }
  53. </style>