index.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /**
  2. * FeHelper HTML转Markdown
  3. */
  4. new Vue({
  5. el: '#pageContainer',
  6. data: {
  7. sourceContent: '',
  8. resultContent: '',
  9. previewHTML: '',
  10. showPreview: false,
  11. previewText: '效果预览',
  12. codeType: 'HTML',
  13. nextCodeType: 'Markdown',
  14. toolName: {
  15. HTML: 'HTML转Markdown',
  16. Markdown: 'Markdown转HTML'
  17. }
  18. },
  19. mounted: function () {
  20. this.$refs.srcText.focus();
  21. },
  22. methods: {
  23. convert: function () {
  24. let h2m = Tarp.require('../static/vendor/h2m/h2m');
  25. let markdown = Tarp.require('../static/vendor/h2m/markdown');
  26. if (this.codeType === 'HTML') {
  27. this.resultContent = h2m(this.sourceContent, {
  28. converter: 'CommonMark' // CommonMark | MarkdownExtra
  29. });
  30. this.previewHTML = markdown.toHTML(this.resultContent);
  31. } else {
  32. this.resultContent = this.previewHTML = markdown.toHTML(this.sourceContent);
  33. }
  34. },
  35. preview: function (event) {
  36. event && event.preventDefault();
  37. this.showPreview = !this.showPreview;
  38. this.previewText = this.showPreview ? '查看源码' : '效果预览';
  39. },
  40. trans: function () {
  41. this.codeType = {HTML: 'Markdown', Markdown: 'HTML'}[this.codeType];
  42. this.nextCodeType = {HTML: 'Markdown', Markdown: 'HTML'}[this.nextCodeType];
  43. this.preview();
  44. this.clear();
  45. },
  46. clear: function () {
  47. this.sourceContent = '';
  48. this.resultContent = '';
  49. this.resultContent = false;
  50. },
  51. getResult: function () {
  52. this.$refs.rstCode.select();
  53. },
  54. setDemo: function () {
  55. if (this.codeType === 'HTML') {
  56. this.sourceContent = this.$refs.htmlDemo.innerHTML;
  57. } else {
  58. this.sourceContent = '## FE助手\n' +
  59. '\n' +
  60. '- 字符串编解码\n' +
  61. '- `Json`串格式化\n' +
  62. '- 代码美化工具\n' +
  63. '- 代码压缩工具\n' +
  64. '- 二维码生成器\n' +
  65. '- 页面取色工具\n' +
  66. '- Js正则表达式\n' +
  67. '- 时间(戳)转换\n' +
  68. '- 图片Base64\n' +
  69. '- 编码规范检测\n' +
  70. '- 页面性能检测\n' +
  71. '- Html转`Markdown`\n' +
  72. '- Ajax调试:**关**';
  73. }
  74. this.convert();
  75. }
  76. }
  77. });