markdown_test.html 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. {{template "main" .}}
  2. <!-- Navbar -->
  3. <nav class="main-header navbar navbar-expand navbar-white navbar-light">
  4. <!-- Left navbar links -->
  5. <ul class="navbar-nav">
  6. <li class="nav-item">
  7. <a class="nav-link" data-widget="pushmenu" href="#" role="button"><i class="fas fa-bars"></i></a>
  8. </li>
  9. <li class="nav-item d-none d-sm-inline-block">
  10. <a href="/markdowntest" class="nav-link">模板管理</a>
  11. </li>
  12. </ul>
  13. </nav>
  14. <!-- /.navbar -->
  15. <!-- Content Wrapper. Contains page content -->
  16. <div class="content-wrapper">
  17. <!-- Content Header (Page header) -->
  18. <section class="content-header">
  19. <div class="container-fluid">
  20. <div class="row mb-2">
  21. <div class="col-sm-6">
  22. <h1>Markdown测试</h1>
  23. </div>
  24. </div>
  25. </div><!-- /.container-fluid -->
  26. </section>
  27. <!-- Main content -->
  28. <section class="content">
  29. <!-- Default box -->
  30. <div class="card">
  31. <div class="card-header">
  32. <h3 class="card-title" style="color:red">** 用于查看模版渲染效果</h3>
  33. <div class="card-tools">
  34. <button type="button" class="btn btn-tool" data-card-widget="collapse" title="Collapse">
  35. <i class="fas fa-minus"></i>
  36. </button>
  37. <button type="button" class="btn btn-tool" data-card-widget="remove" title="Remove">
  38. <i class="fas fa-times"></i>
  39. </button>
  40. </div>
  41. </div>
  42. <div class="card-body">
  43. <form class="form-horizontal" method="POST" action="##" enctype="multipart/form-data" onsubmit="return false" id="formtpl">
  44. <label>*Json内容: 原始Json内容文本</label>
  45. <br />
  46. <textarea id="jsoncontent" name="jsoncontent" class="form-control" style="color:white;background-color:black" cols="30" rows="10" placeholder="原始Json内容文本"></textarea>
  47. <br />
  48. <label>*模版内容: 自定义模版内容文本</label>
  49. <br />
  50. <textarea id="tplcontent" name="tplcontent" class="form-control" style="color:#dc1aa9;background-color:black" cols="30" rows="10" placeholder="自定义模版内容文本"></textarea>
  51. <br />
  52. <div class="text-right">
  53. <a class="btn btn-app bg-success" onclick="showHtml();">
  54. <i class="fas fa-bullhorn"></i> 查看效果
  55. </a>
  56. </div>
  57. </form>
  58. </div>
  59. </div>
  60. <!-- /.card -->
  61. <!-- Default box -->
  62. <div class="card">
  63. <div class="card-header">
  64. <h3 class="card-title">显示效果: 效果仅供参考,因部分机器人对markdown的支持不同,可能渲染的结果会不尽相同</h3>
  65. <div class="card-tools">
  66. <button type="button" class="btn btn-tool" data-card-widget="collapse" title="Collapse">
  67. <i class="fas fa-minus"></i>
  68. </button>
  69. <button type="button" class="btn btn-tool" data-card-widget="remove" title="Remove">
  70. <i class="fas fa-times"></i>
  71. </button>
  72. </div>
  73. </div>
  74. <div class="card-body" id='MarkdownHtml'>
  75. <!-- /.Show MarkdownHtml -->
  76. </div>
  77. <!-- /.card-body -->
  78. </div>
  79. <!-- /.card -->
  80. </section>
  81. <!-- /.content -->
  82. </div>
  83. <!-- /.content-wrapper -->
  84. {{template "endhtml"}}
  85. <script>
  86. function showHtml(){
  87. var jsoncontent=document.getElementById("jsoncontent");
  88. var tplcontent=document.getElementById("tplcontent");
  89. if (jsoncontent.value.length==0){
  90. alert('原始Json内容文本不能为空');
  91. return
  92. };
  93. if (tplcontent.value.length==0){
  94. alert('自定义模版内容文本不能为空');
  95. return
  96. };
  97. $.ajax({
  98. type: "POST",
  99. dataType: "json",
  100. url: '{{ urlfor "MainController.MarkdownTest"}}',
  101. data: $('#formtpl').serialize(),
  102. success: function (result) {
  103. console.log(result);
  104. $("#MarkdownHtml").html(marked(result));
  105. },
  106. });
  107. };
  108. </script>
  109. {{template "jshtml"}}