Loading src/coliverter/convert.py +24 −7 Original line number Diff line number Diff line Loading @@ -5,6 +5,10 @@ import typer from coliverter.FileFormat import FileFormat from coliverter.app import app from coliverter.io import read, write from coliverter.steps.html_to_pdf import html_to_pdf from coliverter.steps.md_to_html import md_to_html @app.command() Loading @@ -21,7 +25,7 @@ def convert( help="Path to the output file. If None, write output to STDOUT." ), ] = None, file_format: Annotated[ output_format: Annotated[ FileFormat | None, typer.Option( help="Format of the output file. If None, infer from extension in output path. If inferring is not possible, default to html." Loading @@ -31,11 +35,24 @@ def convert( """ Convert Markdown files into other formats, using the organization identity of Fachschaft Computerlinguistik. """ if file_format is None: if output_format is None: try: file_format = FileFormat[output_path.suffix if output_path else None] except KeyError: file_format = FileFormat.HTML output_format = FileFormat( output_path.suffix.removeprefix(".") if output_path else None ) except ValueError: output_format = FileFormat.HTML markdown = read(markdown_path) html = md_to_html(markdown) if output_format == FileFormat.HTML: write(html, output_path) return pdf = html_to_pdf(html) # TODO Implement this print(markdown_path, output_path, file_format) if output_format == FileFormat.PDF: write(pdf, output_path) return Loading
src/coliverter/convert.py +24 −7 Original line number Diff line number Diff line Loading @@ -5,6 +5,10 @@ import typer from coliverter.FileFormat import FileFormat from coliverter.app import app from coliverter.io import read, write from coliverter.steps.html_to_pdf import html_to_pdf from coliverter.steps.md_to_html import md_to_html @app.command() Loading @@ -21,7 +25,7 @@ def convert( help="Path to the output file. If None, write output to STDOUT." ), ] = None, file_format: Annotated[ output_format: Annotated[ FileFormat | None, typer.Option( help="Format of the output file. If None, infer from extension in output path. If inferring is not possible, default to html." Loading @@ -31,11 +35,24 @@ def convert( """ Convert Markdown files into other formats, using the organization identity of Fachschaft Computerlinguistik. """ if file_format is None: if output_format is None: try: file_format = FileFormat[output_path.suffix if output_path else None] except KeyError: file_format = FileFormat.HTML output_format = FileFormat( output_path.suffix.removeprefix(".") if output_path else None ) except ValueError: output_format = FileFormat.HTML markdown = read(markdown_path) html = md_to_html(markdown) if output_format == FileFormat.HTML: write(html, output_path) return pdf = html_to_pdf(html) # TODO Implement this print(markdown_path, output_path, file_format) if output_format == FileFormat.PDF: write(pdf, output_path) return