pretty-doc
from __future__ import annotations
from dataclasses import dataclass
import pretty_doc as doc
import json
@dataclass
class Block:
name: str
contents: list[Block] | str = ""
def to_doc(self):
return to_doc(self)
def to_doc(self: Block) -> doc.Doc:
if isinstance(self.contents, list):
return doc.vsep([
doc.seg(self.name) + doc.seg("{"),
doc.indent(4, doc.vsep(
list(map(to_doc, self.contents)))),
doc.seg("}")
])
return doc.seg(self.name) + doc.seg(json.dumps(self.contents))
doc = Block(
"A",
[
Block("C", "ccc"),
Block("B",
[
Block("C", "ccc"),
]
),
Block("C", "ccc"),
Block("C", "ccc"),
]
).to_doc()
print(doc.show())
# out:
A {
C "ccc"
B {
C "ccc"
}
C "ccc"
C "ccc"
}
import sys
doc.render(sys.stdout.write)
# out:
A {
C "ccc"
B {
C "ccc"
}
C "ccc"
C "ccc"
}
Metadata
Release files for pretty-doc 0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pretty_doc-0.3-py3-none-any.whl | Python 3 | none | any | Details |
Release files / pretty_doc-0.3-py3-none-any.whl
| Download URL | pretty_doc-0.3-py3-none-any.whl |
|---|---|
| Size | 4.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8cd18226deb2944d1e064d0d7e4519a562bf0532c31b3e098fd11f2244b5f03b
|
|
BLAKE2b-256 checksum How to use checksums |
9e48a07ec456ffe3d7885d48efee8a0fdc00e97f31df144dfa3326bfc6ee7062
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.7.1 importlib_metadata/3.10.0 pkginfo/1.8.2 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.8
|