html-preview-markdown-to-html-custom-toc-container.html 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <!DOCTYPE html>
  2. <html lang="zh">
  3. <head>
  4. <meta charset="utf-8" />
  5. <title>HTML Preview (markdown to html) - Editor.md examples</title>
  6. <link rel="stylesheet" href="css/style.css" />
  7. <link rel="stylesheet" href="../css/editormd.preview.css" />
  8. <link rel="shortcut icon" href="https://pandao.github.io/editor.md/favicon.ico" type="image/x-icon" />
  9. <style>
  10. body {padding: 40px;}
  11. #layout > header, .btns {
  12. width: auto;
  13. }
  14. #sidebar {
  15. width: 400px;
  16. height: 100%;
  17. position: fixed;
  18. top: 0;
  19. right: 0;
  20. overflow: hidden;
  21. background: #fff;
  22. z-index: 100;
  23. padding: 18px;
  24. border: 1px solid #ddd;
  25. border-top: none;
  26. border-bottom: none;
  27. }
  28. #sidebar:hover {
  29. overflow: auto;
  30. }
  31. #sidebar h1 {
  32. font-size: 16px;
  33. }
  34. #custom-toc-container {
  35. padding-left: 0;
  36. }
  37. #test-editormd-view, #test-editormd-view2 {
  38. padding-left: 0;
  39. padding-right: 430px;
  40. margin: 0;
  41. }
  42. </style>
  43. </head>
  44. <body>
  45. <div id="layout">
  46. <header>
  47. <h1>Markdown转HTML的显示处理之自定义 ToC 容器</h1>
  48. <p>即:非编辑情况下的HTML预览</p>
  49. <p>HTML Preview (markdown to html and custom ToC container)</p>
  50. </header>
  51. <div class="btns">
  52. <button onclick="location.href='./html-preview-markdown-to-html.html';">返回 Back</button>
  53. </div>
  54. <div id="sidebar">
  55. <h1>Table of Contents</h1>
  56. <div class="markdown-body editormd-preview-container" id="custom-toc-container">#custom-toc-container</div>
  57. </div>
  58. <div id="test-editormd-view">
  59. <textarea style="display:none;" name="test-editormd-markdown-doc">###Hello world!</textarea>
  60. </div>
  61. <div id="test-editormd-view2">
  62. <textarea id="append-test" style="display:none;">
  63. ###科学公式 TeX(KaTeX)
  64. $$E=mc^2$$
  65. 行内的公式$$E=mc^2$$行内的公式,行内的$$E=mc^2$$公式。
  66. $$\(\sqrt{3x-1}+(1+x)^2\)$$
  67. $$\sin(\alpha)^{\theta}=\sum_{i=0}^{n}(x^i + \cos(f))$$
  68. $$X^2 > Y$$
  69. #####上标和下标
  70. 上标:X&lt;sup&gt;2&lt;/sup&gt;
  71. 下标:O&lt;sub&gt;2&lt;/sub&gt;
  72. ##### 代码块里包含的过滤标签及属性不会被过滤
  73. ```html
  74. &lt;style type="text/style"&gt;
  75. body{background:red;}
  76. &lt;/style&gt;
  77. &lt;script type="text/javscript"&gt;
  78. alert("script");
  79. &lt;/script&gt;
  80. &lt;iframe height=498 width=510 src="http://player.youku.com/embed/XMzA0MzIwMDgw" frameborder=0 allowfullscreen&gt;&lt;/iframe&gt;
  81. ```
  82. #####Style
  83. &lt;style&gt;
  84. body{background:red;}
  85. &lt;/style&gt;
  86. &lt;style type="text/style"&gt;
  87. body{background:red;}
  88. &lt;/style&gt;
  89. #####Script
  90. &lt;script&gt;
  91. alert("script");
  92. &lt;/script&gt;
  93. &lt;script type="text/javscript"&gt;
  94. alert("script");
  95. &lt;/script&gt;</textarea>
  96. </div>
  97. </div>
  98. <!-- <script src="js/zepto.min.js"></script>
  99. <script>
  100. var jQuery = Zepto; // 为了避免修改flowChart.js和sequence-diagram.js的源码,所以使用Zepto.js时想支持flowChart/sequenceDiagram就得加上这一句
  101. </script> -->
  102. <script src="js/jquery.min.js"></script>
  103. <script src="../lib/marked.min.js"></script>
  104. <script src="../lib/prettify.min.js"></script>
  105. <script src="../lib/raphael.min.js"></script>
  106. <script src="../lib/underscore.min.js"></script>
  107. <script src="../lib/sequence-diagram.min.js"></script>
  108. <script src="../lib/flowchart.min.js"></script>
  109. <script src="../lib/jquery.flowchart.min.js"></script>
  110. <script src="../editormd.js"></script>
  111. <script type="text/javascript">
  112. $(function() {
  113. var testEditormdView, testEditormdView2;
  114. $.get("test.md", function(markdown) {
  115. testEditormdView = editormd.markdownToHTML("test-editormd-view", {
  116. markdown : markdown ,//+ "\r\n" + $("#append-test").text(),
  117. //htmlDecode : true, // 开启 HTML 标签解析,为了安全性,默认不开启
  118. htmlDecode : "style,script,iframe", // you can filter tags decode
  119. //toc : false,
  120. tocm : true, // Using [TOCM]
  121. tocContainer : "#custom-toc-container", // 自定义 ToC 容器层
  122. //gfm : false,
  123. //tocDropdown : true,
  124. // markdownSourceCode : true, // 是否保留 Markdown 源码,即是否删除保存源码的 Textarea 标签
  125. emoji : true,
  126. taskList : true,
  127. tex : true, // 默认不解析
  128. flowChart : true, // 默认不解析
  129. sequenceDiagram : true, // 默认不解析
  130. });
  131. //console.log("返回一个 jQuery 实例 =>", testEditormdView);
  132. // 获取Markdown源码
  133. //console.log(testEditormdView.getMarkdown());
  134. //alert(testEditormdView.getMarkdown());
  135. });
  136. testEditormdView2 = editormd.markdownToHTML("test-editormd-view2", {
  137. htmlDecode : "style,script,iframe", // you can filter tags decode
  138. emoji : true,
  139. taskList : true,
  140. tex : true, // 默认不解析
  141. flowChart : true, // 默认不解析
  142. sequenceDiagram : true, // 默认不解析
  143. });
  144. });
  145. </script>
  146. </body>
  147. </html>