Skip to content

Commit e9c4a4f

Browse files
committed
Add basic readme to use the lexer
1 parent daafe6f commit e9c4a4f

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

README.rst

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,46 @@
1515
.. |CI| image:: https://github.com/python-jsonschema/jsonschema-lexer/workflows/CI/badge.svg
1616
:alt: Build status
1717
:target: https://github.com/python-jsonschema/jsonschema-lexer/actions?query=workflow%3ACI
18+
19+
20+
Introduction
21+
------------
22+
23+
`jsonschema-lexer` is a Python package that provides a JSON Schema lexer for syntax highlighting JSON Schema documents. It utilizes Pygments, a syntax highlighting library, to tokenize JSON Schema documents according to the JSON Schema specification.
24+
25+
Usage
26+
-----
27+
28+
Once installed, you can use it in your Python code to highlight JSON Schema documents.
29+
30+
Here's a simple example:
31+
32+
.. code-block:: python
33+
34+
from jsonschema_lexer.lexer import JSONSchemaLexer
35+
36+
from rich.syntax import Syntax
37+
console = Console()
38+
39+
code = """
40+
{
41+
"$schema": "https://json-schema.org/draft/2020-12/schema",
42+
"$id": "https://example.com/product.schema.json",
43+
"title": "Product",
44+
"description": "A product from Acme's catalog",
45+
"type": "object",
46+
"properties": {
47+
"productId": {
48+
"description": "The unique identifier for a product",
49+
"type": "integer"
50+
},
51+
"productName": {
52+
"description": "Name of the product",
53+
"type": "string"
54+
}
55+
}
56+
}
57+
"""
58+
59+
syntax = Syntax(code, lexer=JSONSchemaLexer(), background_color="default", word_wrap=True)
60+
console.print(syntax)

0 commit comments

Comments
 (0)