1 | # Json_ml [![NPM version][npm-image]][npm] [![Build Status][travis-image]][travis] [![Coverage Status][coveralls-image]][coveralls]
|
2 | [![Sauce Test Status][sauce-image]][sauce]
|
3 |
|
4 | > JsonML parse/stringify function
|
5 |
|
6 | ## Installation
|
7 | ### Via npm
|
8 | ```bash
|
9 | $ npm install json_ml --save
|
10 | ```
|
11 | ```js
|
12 | var JsonML= require('json_ml');
|
13 | console.log(JsonML); //object
|
14 | ```
|
15 |
|
16 | ### Via bower
|
17 | ```bash
|
18 | $ bower install json_ml --save
|
19 | ```
|
20 | ```html
|
21 | <script src="bower_components/json_ml/json_ml.min.js"></script>
|
22 | <script>
|
23 | console.log(JsonML); //object
|
24 | </script>
|
25 | ```
|
26 |
|
27 | ## API
|
28 |
|
29 | > See: http://www.jsonml.org/
|
30 |
|
31 | ### `JsonML.parse(html, trim=true)` -> [Element,Element,...]
|
32 |
|
33 | Convert `HTML string` to `JsonML Elements`.
|
34 |
|
35 | ```js
|
36 | JsonML.parse('<ul><li style="color:red">First Item</li><li title="Some hover text." style="color:green">Second Item</li><li><span class="code-example-third">Third</span>Item</li></ul>');
|
37 | //[
|
38 | // [
|
39 | // "ul",
|
40 | // [
|
41 | // "li",
|
42 | // {
|
43 | // "style": "color:red"
|
44 | // }
|
45 | // ],
|
46 | // [
|
47 | // "li",
|
48 | // {
|
49 | // "title": "Some hover text.",
|
50 | // "style": "color:green"
|
51 | // }
|
52 | // ],
|
53 | // [
|
54 | // "li",
|
55 | // [
|
56 | // "span",
|
57 | // {
|
58 | // "class": "code-example-third"
|
59 | // }
|
60 | // ]
|
61 | // ]
|
62 | // ]
|
63 | //]
|
64 | ```
|
65 |
|
66 | ### `JsonML.stringify(object, replacer, indent)` -> HTML
|
67 |
|
68 | Convert `JsonML Elements` to `HTML string`.
|
69 |
|
70 | ```js
|
71 | JsonML.stringify([['ul',['li',{style:"color:red"}],['li',{title:"Some hover text.",style:"color:green"}],['li',['span',{class:'code-example-third'}]]]],null,2);
|
72 | //<ul>
|
73 | // <li style="color:red"></li>
|
74 | // <li title="Some hover text." style="color:green"></li>
|
75 | // <li><span class="code-example-third"></span></li>
|
76 | //</ul>
|
77 | ```
|
78 |
|
79 | License
|
80 | ---
|
81 | [MIT][License]
|
82 |
|
83 | [License]: http://59naga.mit-license.org/
|
84 |
|
85 | [sauce-image]: http://soysauce.berabou.me/u/59798/json_ml.svg
|
86 | [sauce]: https://saucelabs.com/u/59798
|
87 | [npm-image]:https://img.shields.io/npm/v/json_ml.svg?style=flat-square
|
88 | [npm]: https://npmjs.org/package/json_ml
|
89 | [travis-image]: http://img.shields.io/travis/59naga/json-ml.svg?style=flat-square
|
90 | [travis]: https://travis-ci.org/59naga/json-ml
|
91 | [coveralls-image]: http://img.shields.io/coveralls/59naga/json-ml.svg?style=flat-square
|
92 | [coveralls]: https://coveralls.io/r/59naga/json-ml?branch=master
|