Learn about our RFC process, Open RFC meetings & more.Join in the discussion! »

json_ml

0.0.1-alpha.3 • Public • Published

Json_ml NPM version Build Status Coverage Status

Sauce Test Status

JsonML parse/stringify library

Installation

Via npm

$ npm install json_ml --save
var JSONML= require('json_ml');
console.log(JSONML); //function

Via bower

$ bower install json_ml --save
<script src="bower_components/json_ml/json-ml.min.js"></script>
<script>
  console.log(JSONML); //function
</script> 

API

See: http://www.jsonml.org/

JSONML.parse(html, trim=true)

Convert HTML string to JsonML object.

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>');
//[
//  [
//    "ul",
//    [
//      "li",
//      {
//        "style": "color:red"
//      }
//    ],
//    [
//      "li",
//      {
//        "title": "Some hover text.",
//        "style": "color:green"
//      }
//    ],
//    [
//      "li",
//      [
//        "span",
//        {
//          "class": "code-example-third"
//        }
//      ]
//    ]
//  ]
//]

JSONML.stringify(object, replacer, indent)

Convert JsonML object to HTML string.

JSONML.stringify([['ul',['li',{style:"color:red"}],['li',{title:"Some hover text.",style:"color:green"}],['li',['span',{class:'code-example-third'}]]]],null,2);
//<ul>
//  <li style="color:red"></li>
//  <li title="Some hover text." style="color:green"></li>
//  <li><span class="code-example-third"></span></li>
//</ul>

CLI

$ npm install json_ml --global
$ jsonml -V
# 0.0.0-beta 
 
echo '<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>' | jsonml
# [["ul",["li",{"style":"color:red"}],["li",{"title":"Some hover text.","style":"color:green"}],["li",["span",{"class":"code-example-third"}]]]] 
 
$ jsonml ul.json
# <ul> 
#   <li style="color:red"></li> 
#   <li title="Some hover text." style="color:green"></li> 
#   <li><span class="code-example-third"></span></li> 
# </ul> 

License

MIT

Install

npm i [email protected]

Version

0.0.1-alpha.3

License

MIT

Last publish

Collaborators

  • avatar