Python builder for generating OVAPortableText / Report Profile v1 JSON documents
Project description
OVAPortableText
A Python package for building JSON documents that conform to the OVAPortableText / Report Profile v1.0 protocol.
OVAPortableText 的目标不是直接渲染 PDF,而是让 Python 端以强类型、可校验、可维护的方式,生成符合协议的 JSON;再交给渲染器去渲染 PDF。
Current scope / 当前实现范围
Step 9 currently includes:
- top-level document / section skeleton
- content body items
- Portable Text
block/span - protocol-approved text styles for v1
- decorator marks + annotation
markDefs - list semantics:
listItem/level - first batch of inline objects:
hard_breakxrefcitation_reffootnote_refglossary_term
- first batch of block objects:
imagecharttablemath_blockcallout
- first typed registries:
assets.images / logos / backgrounds / icons / attachmentsdatasets.tables / charts(pie) / metricsbibliography / footnotes / glossary
- append-style builder APIs
- section / figure / table / equation numbering helpers
- global resolver / index builder
- structured document validation report with issue context
- detailed bilingual comments / 详细中英文双语注释
- round-trip helpers:
from_dict()/from_json()/save_json()/load_json()
Install / 安装
PIP
pip install OVAPortableText
Quick start / 快速开始
from ova_portable_text import create_document, section
report = create_document(
title="Patent Valuation Report",
language="en",
documentType="report",
)
intro = report.new_section(id="sec-1", level=1, title="Executive Summary")
intro.append_paragraph("This is the opening introduction of the chapter.")
background = intro.new_subsection(id="sec-1-1", title="Background")
background.append_paragraph("This is the body text of subsection 1.1.")
intro.append_paragraph("This is a concluding paragraph after subsection 1.1.")
report.assert_valid()
print(report.to_json())
Recommended workflow / 推荐工作流
- create one
Document - append sections and registries
- call
validate()during development - call
assert_valid()before exporting or handing off to Java - export with
to_dict()/to_json()
Common authoring patterns / 常见写法
1) Append sections naturally / 顺手追加章节
from ova_portable_text import create_document
report = create_document(title="Demo", language="en")
sec = report.new_section(id="sec-intro", level=1, title="Introduction")
sec.append_lead("This report summarises the project scope.")
sec.append_bullet_item("Point A")
sec.append_bullet_item("Point B")
2) Add registry resources, then reference them / 先放 registry,再在正文引用
from ova_portable_text import (
create_document,
image_asset,
pie_chart_from_parallel_arrays,
table_column,
table_dataset,
)
report = create_document(title="Data Demo", language="en")
report.add_image_asset(
image_asset(
id="img-cover",
src="https://example.com/cover.png",
alt="Cover image",
)
)
report.add_table_dataset(
table_dataset(
id="table-summary",
columns=[
table_column(key="year", header="Year"),
table_column(key="revenue", header="Revenue"),
],
rows=[
{"year": "2024", "revenue": "12.3M"},
{"year": "2025", "revenue": "13.8M"},
],
)
)
report.add_chart_dataset(
pie_chart_from_parallel_arrays(
id="chart-area-share",
area_en=["Technology", "Finance"],
area_zh=["技术", "金融"],
value=[60, 40],
)
)
3) Validate before export / 导出前校验
validation = report.validate()
print(validation.to_text())
report.assert_valid()
4) Save JSON to disk and read it back / 落盘 JSON 再读回
from pathlib import Path
from ova_portable_text import create_document, Document
report = create_document(title="Disk Round Trip", language="en")
report.new_section(id="sec-1", level=1, title="Intro").append_paragraph("Saved to disk.")
out_path = report.save_json(Path("build/report.json"))
restored = Document.load_json(out_path)
print(restored.meta.title)
Validation and resolver / 校验与解析器
validate() returns a structured ValidationReport.
validate() 会返回结构化的 ValidationReport。
Step 8 adds maintenance-friendly context in each issue, such as: 第 8 步开始,每条 issue 会尽量附带更适合维护的上下文,例如:
sectionIdsectionTitlecontextTypecontextIdcontextAnchorsuggestion
validation = report.validate()
for issue in validation.issues:
print(issue.code, issue.sectionId, issue.contextType, issue.suggestion)
Resolver usage:
resolver = report.build_resolver()
print(resolver.debug_summary())
print(resolver.resolve_xref(target_type="section", target_id="sec-1"))
Included docs / 附带文档
docs/QUICKSTART.mddocs/VALIDATION_AND_RESOLVER.mddocs/TEST_MATRIX.mddocs/REAL_WORLD_RECIPES.mddocs/USER_TESTING_CHECKLIST.mddocs/PROTOCOL_ALIGNMENT.md
Included examples / 附带样例
examples/minimal_report.pyexamples/inline_objects_report.pyexamples/registry_blocks_report.pyexamples/validation_report.pyexamples/marks_and_lists_report.pyexamples/builder_numbering_roundtrip_demo.pyexamples/extended_registries_demo.pyexamples/validation_context_demo.pyexamples/full_report_workflow_demo.pyexamples/save_and_load_json_demo.pyexamples/patent_valuation_style_report.py
Version / 版本
import ova_portable_text
print(ova_portable_text.__version__)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ovaportabletext-0.1.0.tar.gz.
File metadata
- Download URL: ovaportabletext-0.1.0.tar.gz
- Upload date:
- Size: 112.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
906853f3b5acc87a9b402404d96a97573db83fab56ead3644d9024695fcfd3f8
|
|
| MD5 |
d92e0b1c7e11f2f98df88bf91e3e3ab9
|
|
| BLAKE2b-256 |
a252e727ed4b865369c2eecb3402b2dac729c4efb76d934a5cf618d64b695460
|
File details
Details for the file ovaportabletext-0.1.0-py3-none-any.whl.
File metadata
- Download URL: ovaportabletext-0.1.0-py3-none-any.whl
- Upload date:
- Size: 54.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ae1d8eb45fb29ca69e7fd546deb926f1a9dabe2973f1d4b9eaeb0a3b8f10601f
|
|
| MD5 |
64b18a968a866d74f2a0425a929ebb34
|
|
| BLAKE2b-256 |
81407e6efdbc3232f5ab6c65dc0295365448ff3177c70eff49062fd90b58026a
|