markdown.html 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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.min.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 { ref, computed } = Vue
  10. new Vue({
  11. setup() {
  12. const input = ref('# hello')
  13. const output = computed(() => marked.marked(input.value))
  14. const update = _.debounce(e => {
  15. input.value = e.target.value
  16. }, 300)
  17. return {
  18. input,
  19. output,
  20. update
  21. }
  22. }
  23. }).$mount('#editor')
  24. </script>
  25. <style>
  26. html,
  27. body,
  28. #editor {
  29. margin: 0;
  30. height: 100%;
  31. font-family: 'Helvetica Neue', Arial, sans-serif;
  32. color: #333;
  33. }
  34. textarea,
  35. #editor div {
  36. display: inline-block;
  37. width: 49%;
  38. height: 100%;
  39. vertical-align: top;
  40. -webkit-box-sizing: border-box;
  41. -moz-box-sizing: border-box;
  42. box-sizing: border-box;
  43. padding: 0 20px;
  44. }
  45. textarea {
  46. border: none;
  47. border-right: 1px solid #ccc;
  48. resize: none;
  49. outline: none;
  50. background-color: #f6f6f6;
  51. font-size: 14px;
  52. font-family: 'Monaco', courier, monospace;
  53. padding: 20px;
  54. }
  55. code {
  56. color: #f66;
  57. }
  58. </style>