• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

netgusto/upndown: HTML to Markdown javascript converter

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

netgusto/upndown

开源软件地址(OpenSource Url):

https://github.com/netgusto/upndown

开源编程语言(OpenSource Language):

JavaScript 99.0%

开源软件介绍(OpenSource Introduction):

upndown

Javascript HTML to Markdown converter, for Node.js and the browser.

Live demo here.

About

upndown converts HTML documents to Markdown documents.

upndown is designed to offer a fast, reliable and whitespace perfect conversion for HTML documents.

Install / Usage

Browser

Standard loading

Download the zip archive on github, unzip, copy in your web folder, and in your HTML:

<script type="text/javascript" src="/assets/upndown/lib/upndown.bundle.min.js"></script>
<script type="text/javascript">

    var und = new upndown();
    und.convert('<h1>Hello, World !</h1>', function(err, markdown) {
        if(err) { console.err(err); }
        else { console.log(markdown); } // Outputs: # Hello, World !
    });

</script>

Using RequireJS

Download the zip archive on github, unzip, copy in your web folder, and in your HTML:

<script type="text/javascript" src="http://requirejs.org/docs/release/2.1.11/minified/require.js"></script>
<script type="text/javascript">

require.config({
    paths: {
        'upndown': '/assets/upndown/lib/upndown.bundle.min'
    }
});

require(['upndown'], function(upndown) {
    var und = new upndown();
    und.convert('<h1>Hello, World !</h1>', function(err, markdown) {
        if(err) { console.err(err);
        else { console.log(markdown); } // Outputs: # Hello, World !
    });
});
</script>

Nodejs

Install

npm install upndown

Use

var upndown = require('upndown');

var und = new upndown();
und.convert('<h1>Hello, World !</h1>', function(err, markdown) {
    if(err) { console.err(err);
    else { console.log(markdown); } // Outputs: # Hello, World !
});

Warning: With Node < 0.12.8, you'll have to require a polyfill for the Promise functionnality (like https://www.npmjs.com/package/bluebird); see #10 on how to do that.

Options

decodeEntities

By default Updown will decode all html entities, so source HTML like this:

<p>I'm an escaped &lt;em&gt;code sample&lt;/em&gt;.</p>

Will become:

I'm an escaped *code sample*.

If your use case does not call for that behavior and you wish HTML entities to stay encoded, you can pass an option to the constructor:

var und = new upndown({decodeEntities: false})

Then just use as normal.

Test

In the browser

Navigate to test/browser/ inside the upndown folder. Browser tests are executed by QUnit.

Nodejs

To run the tests, simply execute:

npm test

Nodejs tests are executed using mocha.

Maintainer

upndown is produced by Net Gusto. Drop us a line at [email protected]




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap