markdown.html 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <script src="../../../../node_modules/marked/marked.min.js"></script>
  2. <script src="../../../../node_modules/lodash/lodash.min.js"></script>
  3. <script src="../../dist/vue.global.js"></script>
  4. <div id="editor">
  5. <textarea :value="input" @input="update"></textarea>
  6. <div v-html="output"></div>
  7. </div>
  8. <script>
  9. const delay = window.location.hash === '#test' ? 16 : 300
  10. const { ref, computed } = Vue
  11. Vue.createApp({
  12. setup() {
  13. const input = ref('# hello')
  14. const output = computed(() => marked(input.value, { sanitize: true }))
  15. const update = _.debounce(e => { input.value = e.target.value }, delay)
  16. return {
  17. input,
  18. output,
  19. update
  20. }
  21. }
  22. }).mount('#editor')
  23. </script>
  24. <style>
  25. html, body, #editor {
  26. margin: 0;
  27. height: 100%;
  28. font-family: 'Helvetica Neue', Arial, sans-serif;
  29. color: #333;
  30. }
  31. textarea, #editor div {
  32. display: inline-block;
  33. width: 49%;
  34. height: 100%;
  35. vertical-align: top;
  36. -webkit-box-sizing: border-box;
  37. -moz-box-sizing: border-box;
  38. box-sizing: border-box;
  39. padding: 0 20px;
  40. }
  41. textarea {
  42. border: none;
  43. border-right: 1px solid #ccc;
  44. resize: none;
  45. outline: none;
  46. background-color: #f6f6f6;
  47. font-size: 14px;
  48. font-family: 'Monaco', courier, monospace;
  49. padding: 20px;
  50. }
  51. code {
  52. color: #f66;
  53. }
  54. </style>