Markdown JS庫
Markdown作為一門書寫語言,比HTML簡單很多。GitHub使用它做項目顯示,StackOverflow也使用的是Markdown編輯器,還可以做博客。Markdown能通過一些方法轉換為HTML,進而增加樣式。可以通過編譯生成,也可以在WEB上通過JS來做顯示。本文涉及三個開源的JS庫來編輯、顯示Markdown。
Markdown-js
項目地址:https://github.com/evilstreak/markdown-js
使用方法:
<!DOCTYPE html> <html> <body> <textarea id="text-input" oninput="this.editor.update()" rows="6" cols="60">Type **Markdown** here.</textarea> <div id="preview"> </div> <script src="lib/markdown.js"></script> <script> function Editor(input, preview) { this.update = function () { preview.innerHTML = markdown.toHTML(input.value); }; input.editor = this; this.update(); } var $ = function (id) { return document.getElementById(id); }; new Editor($("text-input"), $("preview")); </script> </body> </html>
評價:使用比較簡單,但顯示的樣式使用的是默認樣式。需要自己添加樣式。
Strapdown.js
項目地址:http://strapdownjs.com/
使用方法:
<!DOCTYPE html> <html> <title>Hello Strapdown</title> <xmp theme="united" style="display:none;"> # Markdown text goes in here ## Chapter 1 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. ## Chapter 2 Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. </xmp> <script src="http://strapdownjs.com/v/0.2/strapdown.js"></script> </html>
評價:Strapdown.js幫你定義好了頁面顯示的樣式,不能直接嵌入到自己的頁面。比較適合用Mardown記錄內容。
Editer.md
項目地址:https://pandao.github.io/editor.md/examples/index.html
使用方法:
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>Simple example - Editor.md examples</title> <link rel="stylesheet" href="css/style.css" /> <link rel="stylesheet" href="../css/editormd.css" /> <link rel="shortcut icon" /> </head> <body> <div id="layout"> <header> <h1>Simple example</h1> </header> <div id="test-editormd"> <textarea style="display:none;">[TOC] #### Disabled options - TeX (Based on KaTeX); - Emoji; - Task lists; - HTML tags decode; - Flowchart and Sequence Diagram; #### Editor.md directory editor.md/ lib/ css/ scss/ tests/ fonts/ images/ plugins/ examples/ languages/ editormd.js ... ```html <!-- English --> <script src="../dist/js/languages/en.js"></script> <!-- ???? --> <script src="../dist/js/languages/zh-tw.js"></script> ``` </textarea> </div> </div> <script src="js/jquery.min.js"></script> <script src="../editormd.min.js"></script> <script type="text/javascript"> var testEditor; $(function() { testEditor = editormd("test-editormd", { width : "90%", height : 640, syncScrolling : "single", path : "../lib/" }); /* // or testEditor = editormd({ id : "test-editormd", width : "90%", height : 640, path : "../lib/" }); */ }); </script> </body> </html>
評價:Editer.md能夠完成幾乎所有你能想到是事情,甚至能夠幫助你生成流程圖。Editer.md自帶的顯示樣式也不錯。但是項目文件很多,依賴也很多。不像前面兩個只有一個JS文件。
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!