HTML转为markdown工具

旧文存档 2个月前 (04-15) 1588次浏览

Remark 是一个将html转换成markdown格式的Java库,支持 Markdown, Markdown Extra以及MultiMarkdown格式。

简单用法:

<ol class="linenums"><li class="L0"><code class="lang-java"><span class="kwd">import</span><span class="pln"> com</span><span class="pun">.</span><span class="pln">overzealous</span><span class="pun">.</span><span class="pln">remark</span><span class="pun">.</span><span class="typ">Remark</span><span class="pun">;</span></code></li><li class="L1"><code class="lang-java"></code></li><li class="L2"><code class="lang-java"><span class="typ">Remark</span><span class="pln"> remark </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><span class="typ">Remark</span><span class="pun">();</span></code></li><li class="L3"><code class="lang-java"><span class="typ">String</span><span class="pln"> htmlInput </span><span class="pun">=</span><span class="pln"> </span><span class="pun">...;</span></code></li><li class="L4"><code class="lang-java"><span class="typ">String</span><span class="pln"> markdown </span><span class="pun">=</span><span class="pln"> remark</span><span class="pun">.</span><span class="pln">convertFragment</span><span class="pun">(</span><span class="pln">htmlImput</span><span class="pun">);</span></code></li></ol>

同时支持 PHP Markdown Extra MultiMarkdown Github Flavored Markdown Pegdown 等多种扩展格式的mardown,还是挺强大的

<ol class="linenums"><li class="L0"><code class="lang-java"><span class="kwd">import</span><span class="pln"> com</span><span class="pun">.</span><span class="pln">overzealous</span><span class="pun">.</span><span class="pln">remark</span><span class="pun">.</span><span class="typ">Remark</span><span class="pun">;</span></code></li><li class="L1"><code class="lang-java"><span class="kwd">import</span><span class="pln"> com</span><span class="pun">.</span><span class="pln">overzealous</span><span class="pun">.</span><span class="pln">remark</span><span class="pun">.</span><span class="typ">Options</span><span class="pun">;</span></code></li><li class="L2"><code class="lang-java"></code></li><li class="L3"><code class="lang-java"><span class="com">// PHP Markdown Extra</span></code></li><li class="L4"><code class="lang-java"><span class="typ">Remark</span><span class="pln"> markdownExtraRemark </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><span class="typ">Remark</span><span class="pun">(</span><span class="typ">Options</span><span class="pun">.</span><span class="pln">markdownExtra</span><span class="pun">());</span></code></li><li class="L5"><code class="lang-java"></code></li><li class="L6"><code class="lang-java"><span class="com">// MultiMarkdown</span></code></li><li class="L7"><code class="lang-java"><span class="typ">Remark</span><span class="pln"> multiMarkdownRemark </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><span class="typ">Remark</span><span class="pun">(</span><span class="typ">Options</span><span class="pun">.</span><span class="pln">multiMarkdown</span><span class="pun">());</span></code></li><li class="L8"><code class="lang-java"></code></li><li class="L9"><code class="lang-java"><span class="com">// Github Flavored Markdown</span></code></li><li class="L0"><code class="lang-java"><span class="typ">Remark</span><span class="pln"> githubMarkdown </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><span class="typ">Remark</span><span class="pun">(</span><span class="typ">Options</span><span class="pun">.</span><span class="pln">github</span><span class="pun">());</span></code></li><li class="L1"><code class="lang-java"></code></li><li class="L2"><code class="lang-java"><span class="com">// Pegdown with all extensions enabled</span></code></li><li class="L3"><code class="lang-java"><span class="typ">Remark</span><span class="pln"> pegdownMarkdown </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><span class="typ">Remark</span><span class="pun">(</span><span class="typ">Options</span><span class="pun">.</span><span class="pln">pegdownAllExtensions</span><span class="pun">());</span></code></li></ol>

同时支持多种定制功能,详情可看官网 http://remark.overzealous.com/manual/usage.html


版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:HTML转为markdown工具
喜欢 (0)