A Markdown implement in browser
来源:互联网 发布:水仙花数java三位数 编辑:程序博客网 时间:2024/06/05 15:59
https://github.com/wuyisheng/pagedown
最近还在在写kotlin社区,在写网站的东西,社区需要一个基本的博客编辑器,今天动手做了一下。
Markdown编辑器是有一些现成的,具体的有参考
showdown: 28KB. Basically the gold standard; it is the basis for pagedown.
pagedown: 8KB. This is what powers StackExchange, so you can see for yourself which features it supports. It is pretty comprehensive and extremely robust. In addition to the 8KB converter script, it also offers editor and sanitizer scripts, both of which StackExchange also uses.
markdown-it: 104KB. Follows the CommonMark spec; supports syntax extensions. Fast; may actually be as robust as showdown, but very large. Is the basis for http://dillinger.io/.
marked: 19KB. Comprehensive; tested against unit test suite; supports custom lexer rules.
micromarkdown: 5KB. Supports a lot of features, but is missing some common ones like unordered lists using * and some common ones that aren’t strictly part of the spec like fenced code blocks. Many bugs, throws exceptions on most longer documents. I consider it experimental.
nano-markdown: 1.9KB. Feature scope limited to things used by most documents; more robust than micromarkdown but not perfect; uses its own very basic unit test. Reasonably robust but breaks on many edge cases.
drawdown: 1.3KB. Full disclosure, I wrote it. Broader feature scope and more robust than nano-markdown while smaller; handles most but not all of the CommonMark spec. Handles a few edge cases incorrectly; not recommended for user edited documents but very useful for presenting information in web apps. No inline HTML.
mmd.js: 800 bytes. The result of an effort to make the smallest possible parser that is still functional. Supports a small subset; document needs to be tailored for it.
markdown-js: 54KB (not available for download minified; would probably minify to ~20KB). Looks pretty comprehensive and includes tests, but I’m not very familiar with it.
meltdown: 41KB (not available for download minified; would probably minify to ~15KB). jQuery plugin; Markdown Extra (tables, definition lists, footnotes).
了解了一下, showdown 、pagedown 用的人挺多的,好多博客网站都是用这两个的,pagedown 是StackExchange fork showdown 做的一个精简版,能支持到showdown的很多配置。然后我就拉代码下来看,pagedown只提供了js转化的东西,样式表没有,代码高亮和表格支持也没有。
然后我找了一个提供代码高亮的插件
https://github.com/jmcmanus/pagedown-extra
再调整了一下布局什么的,最终效果就是这样的了
所以我fork pagedown 下来了,所以,几行代码就可以用了
Include
<link rel="stylesheet" type="text/css" href="demo.css" /><script type="text/javascript" src="../../Markdown.Converter.js"></script><script type="text/javascript" src="../../Markdown.Sanitizer.js"></script><script type="text/javascript" src="../../Markdown.Editor.js"></script><script type="text/javascript" src="../../Markdown.Extra.js"></script><script type="text/javascript" src="prettify.js"></script>
Call
(function() { var converter = new Markdown.Converter(); converter.hooks.chain("preConversion", function(text) { return text.replace(/\b(a\w*)/gi, "*$1*"); }); converter.hooks.chain("plainLinkText", function(url) { return "This is a link to " + url.replace(/^https?:\/\//, ""); }); Markdown.Extra.init(converter, { highlighter: "prettify" }); var editor = new Markdown.Editor(converter); editor.hooks.chain("onPreviewRefresh", prettyPrint); editor.run();})();
https://github.com/wuyisheng/pagedown
- A Markdown implement in browser
- stopping popup windows in a web browser
- Detecting a mobile browser in ASP.NET
- Detecting a mobile browser in ASP.NET
- Disable HTML a links in different browser
- How To: Implement A Server Plug-in
- what happens when you type in a URL in browser
- A way to implement a general purpose LinkedList in C
- [LeetCode] Implement strstr() to Find a Substring in a String
- AJAX - Handling White Space in a Cross-Browser Way
- Opening URL in a browser from JavaFX Desktop Application
- Plan Would Put a Bank in Every Browser
- What happens when you type a URL in browser
- what happens when you type a url in browser
- 解决“requires a Promise polyfill in this browser”错误
- PE Binary File Analysis in the browser, without a backend.
- 解决“requires a Promise polyfill in this browser”错误
- vuex requires a Promise polyfill in this browser
- springboot调用外部接口FeignClient
- Android 组件冲突
- mongo-connector导入数据到Elasticsearch
- Scikit-learn 秘籍 第三章 使用距离向量构建模型
- 2017网易春招 消除重复元素(set)
- A Markdown implement in browser
- JSP学习笔记之二——关于中文乱码
- 数论之路慢慢之GCD性质
- 剑指offer27---将二叉搜索树转换成一个排序的双向链表
- Strategy
- together项目进度报告5
- C++仿函数
- 赛码网3月31号模拟试题(C++)
- Stack源码解析及用LinkedList实现Stack