From f1b0829b16c004bbc3cba71e5678d5a853be77d3 Mon Sep 17 00:00:00 2001 From: baztian Date: Mon, 27 Feb 2023 16:28:33 +0100 Subject: [PATCH 1/2] Make json2html a command line tool --- json2html/jsonconv.py | 12 ++++++++++++ setup.py | 3 +++ 2 files changed, 15 insertions(+) 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'] + } ) From c6c6fcb3be03d0b1a91583d8a3fe56b9d376e00f Mon Sep 17 00:00:00 2001 From: baztian Date: Mon, 27 Feb 2023 16:33:54 +0100 Subject: [PATCH 2/2] Add some documentation to the README --- README.rst | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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:
glossary
GlossDiv
GlossList
GlossEntry
GlossDef
GlossSeeAlso
  • GML
  • XML
paraA meta-markup language, used to create markup languages such as DocBook.
GlossSeemarkup
AcronymSGML
GlossTermStandard Generalized Markup Language
AbbrevISO 8879:1986
SortAsSGML
IDSGML
titleS
titleexample glossary
+**Example 6:** + +.. code-block:: bash + + echo '{"key":"value"}'|json2html + +Output: + +.. code-block:: bash + +
keyvalue
+ Tests ------