11import mimetypes
22import os
33import platform
4+ import shutil
45import subprocess
56import tempfile
67import webbrowser
@@ -115,9 +116,9 @@ def load_template(self) -> str:
115116 """
116117 return ""
117118
118- def open (self , file : Path ) -> Any :
119+ def open (self , file : Path ) -> None :
119120 """Open a file, generated with converter, using appropriate application."""
120- raise NotImplementedError
121+ open_with_default ( file )
121122
122123 @classmethod
123124 def from_string (cls , s : str ) -> type ["Converter" ]:
@@ -126,6 +127,7 @@ def from_string(cls, s: str) -> type["Converter"]:
126127 "html" : RevealJS ,
127128 "pdf" : PDF ,
128129 "pptx" : PowerPoint ,
130+ "zip" : HtmlZip ,
129131 }[s ]
130132
131133
@@ -380,8 +382,8 @@ def load_template(self) -> str:
380382
381383 return resources .files (templates ).joinpath ("revealjs.html" ).read_text ()
382384
383- def open (self , file : Path ) -> bool :
384- return webbrowser .open (file .absolute ().as_uri ())
385+ def open (self , file : Path ) -> None :
386+ webbrowser .open (file .absolute ().as_uri ())
385387
386388 def convert_to (self , dest : Path ) -> None :
387389 """
@@ -452,6 +454,24 @@ def prefix(i: int) -> str:
452454 f .write (content )
453455
454456
457+ class HtmlZip (RevealJS ):
458+ def open (self , file : Path ) -> None :
459+ super (RevealJS , self ).open (file ) # Override opening with web browser
460+
461+ def convert_to (self , dest : Path ) -> None :
462+ """
463+ Convert this configuration into a zipped RevealJS HTML presentation, saved to
464+ DEST.
465+ """
466+ with tempfile .TemporaryDirectory () as directory_name :
467+ directory = Path (directory_name )
468+
469+ html_file = directory / dest .with_suffix (".html" ).name
470+
471+ super ().convert_to (html_file )
472+ shutil .make_archive (str (dest .with_suffix ("" )), "zip" , directory_name )
473+
474+
455475class FrameIndex (str , Enum ):
456476 first = "first"
457477 last = "last"
@@ -462,9 +482,6 @@ class PDF(Converter):
462482 resolution : PositiveFloat = 100.0
463483 model_config = ConfigDict (use_enum_values = True , extra = "forbid" )
464484
465- def open (self , file : Path ) -> None :
466- return open_with_default (file )
467-
468485 def convert_to (self , dest : Path ) -> None :
469486 """Convert this configuration into a PDF presentation, saved to DEST."""
470487 images = []
@@ -499,9 +516,6 @@ class PowerPoint(Converter):
499516 poster_frame_image : Optional [FilePath ] = None
500517 model_config = ConfigDict (use_enum_values = True , extra = "forbid" )
501518
502- def open (self , file : Path ) -> None :
503- return open_with_default (file )
504-
505519 def convert_to (self , dest : Path ) -> None :
506520 """Convert this configuration into a PowerPoint presentation, saved to DEST."""
507521 prs = pptx .Presentation ()
@@ -640,7 +654,7 @@ def callback(ctx: Context, param: Parameter, value: bool) -> None:
640654@click .argument ("dest" , type = click .Path (dir_okay = False , path_type = Path ))
641655@click .option (
642656 "--to" ,
643- type = click .Choice (["auto" , "html" , "pdf" , "pptx" ], case_sensitive = False ),
657+ type = click .Choice (["auto" , "html" , "zip" , " pdf" , "pptx" ], case_sensitive = False ),
644658 metavar = "FORMAT" ,
645659 default = "auto" ,
646660 show_default = True ,
0 commit comments