diff --git a/README.rst b/README.rst index aa7bb04..66d722a 100644 --- a/README.rst +++ b/README.rst @@ -33,6 +33,7 @@ Features * Generated table can be provided some ``attributes`` explicitly. Eg. giving an ``id``, ``class`` or any ``data-*`` attribute. * Python 3 compatible +* Can be used as a library in your code base or called from command line Live Demo ---------- @@ -195,6 +196,18 @@ Output: <table border="1"><tr><th>glossary</th><td><table border="1"><tr><th>GlossDiv</th><td><table border="1"><tr><th>GlossList</th><td><table border="1"><tr><th>GlossEntry</th><td><table border="1"><tr><th>GlossDef</th><td><table border="1"><tr><th>GlossSeeAlso</th><td><ul><li>GML</li><li>XML</li></ul></td></tr><tr><th>para</th><td>A meta-markup language, used to create markup languages such as DocBook.</td></tr></table></td></tr><tr><th>GlossSee</th><td>markup</td></tr><tr><th>Acronym</th><td>SGML</td></tr><tr><th>GlossTerm</th><td>Standard Generalized Markup Language</td></tr><tr><th>Abbrev</th><td>ISO 8879:1986</td></tr><tr><th>SortAs</th><td>SGML</td></tr><tr><th>ID</th><td>SGML</td></tr></table></td></tr></table></td></tr><tr><th>title</th><td>S</td></tr></table></td></tr><tr><th>title</th><td>example glossary</td></tr></table></td></tr></table> +**Example 6:** + +.. code-block:: bash + + echo '{"key":"value"}'|json2html + +Output: + +.. code-block:: bash + + <table border="1"><tr><th>key</th><td>value</td></tr></table> + Tests ------ diff --git a/json2html/jsonconv.py b/json2html/jsonconv.py index 9ef8c73..fafb90b 100644 --- a/json2html/jsonconv.py +++ b/json2html/jsonconv.py @@ -174,3 +174,15 @@ def convert_object(self, json_input): return converted_output json2html = Json2Html() + +def main(): + import argparse + parser = argparse.ArgumentParser() + parser.add_argument('infile', nargs='?', type=argparse.FileType('r'), + default=sys.stdin) + args = parser.parse_args() + data = args.infile.read() + print(json2html.convert(json = data)) + +if __name__ == "__main__": + main() diff --git a/setup.py b/setup.py index 43b404a..b1d60dd 100644 --- a/setup.py +++ b/setup.py @@ -23,4 +23,7 @@ 'Programming Language :: Python :: 3.7', 'Programming Language :: Python :: Implementation :: CPython', ], + entry_points = { + 'console_scripts': ['json2html = json2html:main'] + } )