markdown.html 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. const App = {
  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. }
  23. Vue.createApp().mount(App, '#editor')
  24. </script>
  25. <style>
  26. html, body, #editor {
  27. margin: 0;
  28. height: 100%;
  29. font-family: 'Helvetica Neue', Arial, sans-serif;
  30. color: #333;
  31. }
  32. textarea, #editor div {
  33. display: inline-block;
  34. width: 49%;
  35. height: 100%;
  36. vertical-align: top;
  37. -webkit-box-sizing: border-box;
  38. -moz-box-sizing: border-box;
  39. box-sizing: border-box;
  40. padding: 0 20px;
  41. }
  42. textarea {
  43. border: none;
  44. border-right: 1px solid #ccc;
  45. resize: none;
  46. outline: none;
  47. background-color: #f6f6f6;
  48. font-size: 14px;
  49. font-family: 'Monaco', courier, monospace;
  50. padding: 20px;
  51. }
  52. code {
  53. color: #f66;
  54. }
  55. </style>