Skip to content

Commit a3feae0

Browse files
authored
feat: add split view & YAML support to CLI viewer (#407)
Signed-off-by: Panos Vagenas <[email protected]>
1 parent 1a023da commit a3feae0

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

docling_core/cli/view.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,17 @@ def view(
3939
typer.Argument(
4040
...,
4141
metavar="source",
42-
help="Docling JSON file to view.",
42+
help="Docling JSON or YAML file to view.",
4343
),
4444
],
45+
split_view: Annotated[
46+
bool,
47+
typer.Option(
48+
"--split-view",
49+
"-s",
50+
help="Split view of the document.",
51+
),
52+
] = False,
4553
version: Annotated[
4654
Optional[bool],
4755
typer.Option(
@@ -52,11 +60,19 @@ def view(
5260
),
5361
] = None,
5462
):
55-
"""Display a Docling JSON file on the default browser."""
63+
"""Display a DoclingDocument file on the default browser."""
5664
path = resolve_source_to_path(source=source)
57-
doc = DoclingDocument.load_from_json(filename=path)
58-
target_path = Path(tempfile.mkdtemp()) / "out.html"
59-
html_output = doc.export_to_html(image_mode=ImageRefMode.EMBEDDED)
65+
if path.suffix == ".json":
66+
doc = DoclingDocument.load_from_json(filename=path)
67+
elif path.suffix in [".yaml", ".yml"]:
68+
doc = DoclingDocument.load_from_yaml(filename=path)
69+
else:
70+
raise ValueError(f"Unsupported file type: {path.suffix}")
71+
target_path = Path(tempfile.mkdtemp()) / f"{path.stem}.html"
72+
html_output = doc.export_to_html(
73+
image_mode=ImageRefMode.EMBEDDED,
74+
split_page_view=split_view,
75+
)
6076
with open(target_path, "w", encoding="utf-8") as f:
6177
f.write(html_output)
6278
webbrowser.open(url=f"file://{target_path.absolute().resolve()}")

0 commit comments

Comments
 (0)