### Install md2pdf CLI with uv Source: https://github.com/jmaupetit/md2pdf/blob/main/README.md Use uv to install the md2pdf command-line interface with optional features. ```bash $ uv tool install md2pdf[cli] ``` -------------------------------- ### Install md2pdf with CLI support Source: https://context7.com/jmaupetit/md2pdf/llms.txt Instructions for installing the md2pdf package with the necessary extras for command-line interface usage. ```bash # Install with CLI support uv tool install md2pdf[cli] # or: pip install md2pdf[cli] ``` -------------------------------- ### Bootstrap md2pdf Development Environment Source: https://github.com/jmaupetit/md2pdf/blob/main/README.md Install md2pdf and its dependencies using the provided Makefile and uv. ```bash cd md2pdf $ make bootstrap ``` -------------------------------- ### Print Version Information Source: https://context7.com/jmaupetit/md2pdf/llms.txt Use the --version flag to display the installed version of md2pdf. ```bash md2pdf --version ``` -------------------------------- ### Markdown with Jinja Template Frontmatter Source: https://github.com/jmaupetit/md2pdf/blob/main/README.md Example of a Markdown file using Jinja templating syntax within its frontmatter for variable injection. ```markdown --- groceries: - name: apple quantity: 4 - name: orange quantity: 10 - name: banana quantity: 6 --- ``` -------------------------------- ### md2pdf CLI Usage Help Source: https://github.com/jmaupetit/md2pdf/blob/main/README.md Displays the help message for the md2pdf command-line tool, outlining available options and their descriptions. ```bash Usage: md2pdf [OPTIONS] Markdown to PDF conversion tool with styles… and templates! ╭─ Options ──────────────────────────────────────────────────────────────────────────────────────────╮ │ --input -i PATH Markdown source file path (can be used multiple times). │ │ --output -o PATH PDF output file path (when a single md input is used). │ │ --css -c PATH Input CSS file. │ │ --extras -e TEXT Extra markdown extension to activate (cam be used multiple │ │ times). │ │ --config -C TEXT Markdown extensions configuration (as a JSON string). │ │ --workers -W INTEGER Number of parallel workers to start. [default: 4] │ │ --version -V Display program version. │ │ --install-completion Install completion for the current shell. │ │ --show-completion Show completion for the current shell, to copy it or │ │ customize the installation. │ │ --help Show this message and exit. │ ╰────────────────────────────────────────────────────────────────────────────────────────────────────╯ ``` -------------------------------- ### Convert Markdown to PDF using md2pdf library Source: https://context7.com/jmaupetit/md2pdf/llms.txt Demonstrates basic conversion of a Markdown file or raw string to PDF using the md2pdf library. Ensure the output directory exists. ```python from pathlib import Path from md2pdf.core import md2pdf from md2pdf.exceptions import ValidationError # 1. Convert a Markdown file to PDF (output path mirrors input name) md2pdf( pdf=Path("output/report.pdf"), md=Path("docs/report.md"), ) # 2. Convert raw Markdown string to PDF md2pdf( pdf=Path("output/hello.pdf"), raw="# Hello World\n\nThis is a **bold** statement.", ) ``` -------------------------------- ### Display md2pdf Makefile Help Source: https://github.com/jmaupetit/md2pdf/blob/main/README.md View available tasks and commands automated by the md2pdf Makefile. ```bash $ make help ``` -------------------------------- ### Docker Usage Source: https://github.com/jmaupetit/md2pdf/blob/main/README.md Instructions for using the md2pdf tool with Docker, including pulling the image and running conversions. ```APIDOC ## Docker Usage ### Description Run `md2pdf` using Docker containers for consistent environment execution. ### Pulling the Image ```bash $ docker pull jmaupetit/md2pdf:latest ``` ### Running a Conversion Mount the current directory to `/wrk` inside the container and run the conversion. ```bash $ docker run --rm -t \ -v $PWD:/wrk \ -u "$(id -u):$(id -g)" \ -w /wrk \ jmaupetit/md2pdf:latest -i README.md ``` _Note:_ An Alpine-based image is also available tagged as `alpine`. ``` -------------------------------- ### Run md2pdf Test Suite Source: https://github.com/jmaupetit/md2pdf/blob/main/README.md Execute the test suite for the md2pdf project. ```bash $ make test ``` -------------------------------- ### Convert Markdown to PDF with custom CSS and extensions Source: https://context7.com/jmaupetit/md2pdf/llms.txt Shows how to apply custom CSS and enable Markdown extensions like footnotes and emoji. The `base_url` is useful for resolving relative paths in images. ```python from pathlib import Path from md2pdf.core import md2pdf from md2pdf.exceptions import ValidationError # 3. Convert with a custom CSS stylesheet and extra Markdown extensions md2pdf( pdf=Path("output/styled.pdf"), md=Path("docs/report.md"), css=Path("styles/custom.css"), base_url=Path("docs/"), # resolve relative image paths extras=["footnotes", "pymdownx.emoji"], extras_config={ "footnotes": {"BACKLINK_TEXT": "↩"} }, ) ``` -------------------------------- ### Generate PDF from Markdown CLI Source: https://github.com/jmaupetit/md2pdf/blob/main/README.md Basic usage of the md2pdf CLI to convert a README.md file to README.pdf. ```bash $ md2pdf -i README.md ``` -------------------------------- ### Generate PDF with Markdown Extensions CLI Source: https://github.com/jmaupetit/md2pdf/blob/main/README.md Converts Markdown to PDF, enabling PyMdown extensions like emoji and using a specific CSS file. ```bash $ md2pdf \ --css examples/custom-styles-with-pygments.css \ --extras 'pymdownx.emoji' \ -i README.md ``` -------------------------------- ### Run md2pdf with Docker Source: https://github.com/jmaupetit/md2pdf/blob/main/README.md Executes the md2pdf conversion using a Docker container, mounting the current directory and specifying the input file. ```bash $ docker run --rm -t \ -v $PWD:/wrk \ -u "$(id -u):$(id -g)" \ -w /wrk \ jmaupetit/md2pdf:latest -i README.md ``` -------------------------------- ### Render Jinja2 template with programmatic context Source: https://context7.com/jmaupetit/md2pdf/llms.txt Illustrates rendering a Markdown string as a Jinja2 template using variables provided programmatically. Ensure the `context` dictionary keys match the template variables. ```python from pathlib import Path from md2pdf.core import md2pdf from md2pdf.exceptions import ValidationError # 4. Render a Jinja2 template via programmatic context md2pdf( pdf=Path("output/invoice.pdf"), raw="# Invoice\n\nCustomer: {{ name }}\nAmount: ${{ amount }}", context={"name": "Acme Corp", "amount": 1500}, ) ``` -------------------------------- ### Basic CLI conversion of a single Markdown file Source: https://context7.com/jmaupetit/md2pdf/llms.txt Converts a single Markdown file to PDF using the md2pdf CLI. The output PDF will be named similarly to the input file. ```bash # Basic: convert a single Markdown file (output: README.pdf) md2pdf -i README.md ``` -------------------------------- ### Convert Markdown to PDF using md2pdf CLI Source: https://github.com/jmaupetit/md2pdf/blob/main/README.md Use this command to convert a Jinja2 templated Markdown file to a PDF using a specified CSS stylesheet. ```bash $ md2pdf \ --css examples/gutenberg-modern.min.css \ -i examples/my-music.md.j2 \ -o examples/my-music.pdf ``` -------------------------------- ### CLI conversion with Markdown extensions Source: https://context7.com/jmaupetit/md2pdf/llms.txt Enables PyMdown extensions for Markdown processing during PDF conversion via the CLI. Multiple extensions can be specified. ```bash # Enable PyMdown extensions (stackable) md2pdf \ --css examples/custom-styles-with-pygments.css \ --extras 'pymdownx.emoji' \ --extras 'pymdownx.highlight' \ -i README.md ``` -------------------------------- ### Core Library API: md2pdf function Source: https://context7.com/jmaupetit/md2pdf/llms.txt The `md2pdf` function is the primary entry point for the library. It converts Markdown content (from a file or raw string) to a PDF file, with options for custom CSS, Jinja2 templating, and Markdown extensions. ```APIDOC ## md2pdf(pdf, raw, md, css, base_url, extras, extras_config, context) ### Description Converts Markdown content to a PDF file. Accepts a Markdown file path or raw string, an optional CSS stylesheet, optional Jinja2 context variables, and optional Markdown extension configuration, then renders the result to a PDF file at the given output path. Raises `md2pdf.exceptions.ValidationError` when no markdown content is provided. ### Parameters - **pdf** (Path) - Required - The output path for the generated PDF file. - **raw** (str) - Optional - Raw Markdown content as a string. - **md** (Path) - Optional - Path to the input Markdown file. - **css** (Path) - Optional - Path to a custom CSS stylesheet. - **base_url** (Path) - Optional - Base URL to resolve relative paths (e.g., for images). - **extras** (list[str]) - Optional - List of Markdown extensions to enable. - **extras_config** (dict) - Optional - Configuration for the enabled Markdown extensions. - **context** (dict) - Optional - Jinja2 template variables. ### Request Example ```python from pathlib import Path from md2pdf.core import md2pdf # Convert a Markdown file to PDF md2pdf( pdf=Path("output/report.pdf"), md=Path("docs/report.md"), ) # Convert raw Markdown string to PDF with custom CSS and extensions md2pdf( pdf=Path("output/styled.pdf"), raw="# Hello World", css=Path("styles/custom.css"), extras=["footnotes", "pymdownx.emoji"], extras_config={ "footnotes": {"BACKLINK_TEXT": "↩"} }, ) # Render a Jinja2 template via programmatic context md2pdf( pdf=Path("output/invoice.pdf"), raw="Customer: {{ name }}", context={"name": "Acme Corp"}, ) ``` ### Response No explicit response schema is defined, but a PDF file is generated at the specified `pdf` path. Errors during conversion will raise exceptions like `md2pdf.exceptions.ValidationError`. ``` -------------------------------- ### CLI Usage Source: https://github.com/jmaupetit/md2pdf/blob/main/README.md The md2pdf tool can be used from the command line to convert Markdown files to PDF. It supports various options for input, output, styling, and markdown extensions. ```APIDOC ## CLI Usage ### Description Convert Markdown files to PDF with styles and templates. ### Command `md2pdf` ### Options - `--input` or `-i` (PATH): Markdown source file path (can be used multiple times). - `--output` or `-o` (PATH): PDF output file path (when a single md input is used). - `--css` or `-c` (PATH): Input CSS file. - `--extras` or `-e` (TEXT): Extra markdown extension to activate (can be used multiple times). - `--config` or `-C` (TEXT): Markdown extensions configuration (as a JSON string). - `--workers` or `-W` (INTEGER): Number of parallel workers to start. [default: 4] - `--version` or `-V`: Display program version. - `--install-completion`: Install completion for the current shell. - `--show-completion`: Show completion for the current shell. - `--help`: Show this message and exit. ### Examples Convert README.md to README.pdf: ```bash $ md2pdf -i README.md ``` Convert with custom CSS: ```bash $ md2pdf \ --css examples/custom-styles.css \ -i README.md ``` Convert with CSS and markdown extensions: ```bash $ md2pdf \ --css examples/custom-styles-with-pygments.css \ --extras 'pymdownx.emoji' \ -i README.md ``` ``` -------------------------------- ### Generate PDF with Custom CSS CLI Source: https://github.com/jmaupetit/md2pdf/blob/main/README.md Converts a Markdown file to PDF using a specified external CSS file for styling. ```bash $ md2pdf \ --css examples/custom-styles.css \ -i README.md ``` -------------------------------- ### Configure Markdown Extensions Programmatically Source: https://context7.com/jmaupetit/md2pdf/llms.txt Use the Python library to enable and configure Markdown extensions like footnotes, emoji, and table of contents. The `extras` argument takes a list of extension names, and `extras_config` allows detailed configuration. ```python from pathlib import Path from md2pdf.core import md2pdf # Default base extensions (always active): # - markdown.extensions.tables # - pymdownx.magiclink # - pymdownx.betterem # - pymdownx.superfences # Add footnotes + emoji extensions md2pdf( pdf=Path("output/extended.pdf"), md=Path("docs/article.md"), extras=["footnotes", "pymdownx.emoji"], ) # Configure an extension programmatically md2pdf( pdf=Path("output/configured.pdf"), md=Path("docs/article.md"), extras=["footnotes", "toc"], extras_config={ "footnotes": {"BACKLINK_TEXT": "↩"}, "toc": {"title": "Table of Contents", "toc_depth": 3}, }, ) # Equivalent CLI invocation # md2pdf \ # -e footnotes -e toc \ # -C '{"footnotes": {"BACKLINK_TEXT": "↩"}, "toc": {"title": "Table of Contents", "toc_depth": 3}}' \ # -i docs/article.md \ # -o output/configured.pdf ``` -------------------------------- ### md2pdf Library Usage Source: https://github.com/jmaupetit/md2pdf/blob/main/README.md Demonstrates how to use the md2pdf function from the core library within a Python project. ```python from md2pdf.core import md2pdf md2pdf(pdf, md=None, raw=None, css=None, base_url=None, extras=[], context={"foo": 1} ) ``` -------------------------------- ### CLI conversion with JSON extension configuration Source: https://context7.com/jmaupetit/md2pdf/llms.txt Passes JSON-encoded configuration options to Markdown extensions using the `-C` flag in the md2pdf CLI. This is useful for extensions with complex settings. ```bash # Pass JSON configuration for an extension md2pdf \ -e footnotes \ -C '{"footnotes": {"BACKLINK_TEXT": "↩"}}' \ -i docs/report.md \ -o output/report.pdf ``` -------------------------------- ### CLI Usage: md2pdf command-line interface Source: https://context7.com/jmaupetit/md2pdf/llms.txt The `md2pdf` CLI tool provides a command-line interface for converting Markdown files to PDF, supporting various options for styling, extensions, and parallel processing. ```APIDOC ## md2pdf command-line interface ### Description The CLI wraps the core library with a Typer-powered interface supporting single/multiple file conversion, CSS styling, Markdown extension activation, JSON-encoded extension configuration, parallel workers, and a watch mode that automatically re-renders on file changes. ### Usage Examples ```bash # Install with CLI support # uv tool install md2pdf[cli] # or: pip install md2pdf[cli] # Basic: convert a single Markdown file (output: README.pdf) md2pdf -i README.md # Specify a custom output path md2pdf -i docs/report.md -o output/report.pdf # Apply a CSS stylesheet md2pdf --css examples/custom-styles.css -i README.md # Enable PyMdown extensions md2pdf \ --css examples/custom-styles-with-pygments.css \ --extras 'pymdownx.emoji' \ --extras 'pymdownx.highlight' \ -i README.md # Pass JSON configuration for an extension md2pdf \ -e footnotes \ -C '{"footnotes": {"BACKLINK_TEXT": "↩"}}' \ -i docs/report.md \ -o output/report.pdf # Convert multiple files in parallel (4 workers by default) md2pdf -i chapter1.md -i chapter2.md -i chapter3.md -W 8 ``` ### CLI Options - **-i, --input** (Path) - Input Markdown file(s). - **-o, --output** (Path) - Output PDF file path. - **--css** (Path) - Path to a custom CSS stylesheet. - **-e, --extras** (str) - Enable Markdown extensions (can be used multiple times). - **-C, --extras-config** (str) - JSON-encoded configuration for extensions. - **-W, --workers** (int) - Number of parallel workers for conversion. - **--watch** - Enable live file watching mode. ``` -------------------------------- ### CLI parallel conversion of multiple Markdown files Source: https://context7.com/jmaupetit/md2pdf/llms.txt Converts multiple Markdown files to PDF concurrently using multiple worker processes. The `-W` flag controls the number of workers. ```bash # Convert multiple files in parallel (4 workers by default) md2pdf -i chapter1.md -i chapter2.md -i chapter3.md -W 8 ``` -------------------------------- ### Creating Raw URL Links in Markdown Source: https://github.com/jmaupetit/md2pdf/blob/main/tests/assets/input.md Enclose URLs in angle brackets to create raw links. This is useful for displaying clickable URLs directly. ```markdown Sometimes you just want a URL like . ``` -------------------------------- ### CLI conversion with custom output path Source: https://context7.com/jmaupetit/md2pdf/llms.txt Specifies a custom output path and filename for the PDF generated by the md2pdf CLI. ```bash # Specify a custom output path md2pdf -i docs/report.md -o output/report.pdf ``` -------------------------------- ### Use YAML frontmatter for Jinja2 templating Source: https://context7.com/jmaupetit/md2pdf/llms.txt Shows how to inject template variables into Markdown using a YAML frontmatter block. Frontmatter variables take precedence over programmatic context. ```python from pathlib import Path from md2pdf.core import md2pdf # Input file: groceries.md # --- # groceries: # - name: apple # quantity: 4 # - name: orange # quantity: 10 # --- # # # Groceries # # | Item | Quantity | # | ---- | -------- | # {% for item in groceries -%} # | {{ item.name }} | {{ item.quantity }} | # {% endfor %} md2pdf( pdf=Path("output/groceries.pdf"), md=Path("templates/groceries.md"), css=Path("styles/gutenberg-modern.min.css"), ) ``` ```python from pathlib import Path from md2pdf.core import md2pdf # Programmatic context can complement (but not override) frontmatter variables raw = "\n".join([ "---", "name: Jane", "id: 42", "---", "Hello {{ name }} 👋", "", "Your ID is: {{ id }}", ]) md2pdf( pdf=Path("output/greeting.pdf"), raw=raw, context={"name": "John"}, # "Jane" from frontmatter takes precedence ) # Rendered PDF text: "Hello Jane 👋\nYour ID is: 42" ``` -------------------------------- ### CLI conversion with custom CSS stylesheet Source: https://context7.com/jmaupetit/md2pdf/llms.txt Applies a custom CSS stylesheet to the PDF output using the `--css` option in the md2pdf CLI. ```bash # Apply a CSS stylesheet md2pdf --css examples/custom-styles.css -i README.md ``` -------------------------------- ### Displaying Code Blocks in Markdown Source: https://github.com/jmaupetit/md2pdf/blob/main/tests/assets/input.md Use four spaces or a tab to indent code blocks. This is useful for displaying code or plain text. ```markdown Code blocks are very useful for developers and other people who look at code or other things that are written in plain text. As you can see, it uses a fixed-width font. ``` -------------------------------- ### Clone md2pdf Project Repository Source: https://github.com/jmaupetit/md2pdf/blob/main/README.md Clone the md2pdf project from GitHub to contribute or for local development. ```bash $ git clone git@github.com:jmaupetit/md2pdf.git ``` -------------------------------- ### Creating Named Links in Markdown Source: https://github.com/jmaupetit/md2pdf/blob/main/tests/assets/input.md Create named links by enclosing the link text in square brackets and the URL in parentheses. This is useful for creating references within the document. ```markdown A named link to [MarkItDown][3]. The easiest way to do these is to select what you want to make a link and hit `Ctrl+L`. ``` ```markdown Another named link to [MarkItDown](http://www.markitdown.net/) ``` -------------------------------- ### Enable Watch Mode for Automatic Re-rendering Source: https://context7.com/jmaupetit/md2pdf/llms.txt Use the --watch flag to automatically re-render the PDF when source files change. This is useful for iterative development. ```bash md2pdf --css styles.css -i README.md -o README.pdf --watch ``` -------------------------------- ### Run md2pdf via Docker Source: https://context7.com/jmaupetit/md2pdf/llms.txt Execute md2pdf within a Docker container, mounting the current directory for file access. This avoids the need for a local Python environment. ```bash docker run --rm -t \ -v $PWD:/wrk \ -u "$(id -u):$(id -g)" \ -w /wrk \ jmaupetit/md2pdf:latest -i README.md ``` ```bash docker run --rm -t \ -v $PWD:/wrk \ -u "$(id -u):$(id -g)" \ -w /wrk \ jmaupetit/md2pdf:latest \ --css examples/custom-styles.css \ -i README.md \ -o docs/README.pdf ``` ```bash docker run --rm -t \ -v $PWD:/wrk \ -u "$(id -u):$(id -g)" \ -w /wrk \ jmaupetit/md2pdf:latest \ --css examples/gutenberg-modern.min.css \ -i examples/my-music.md.j2 \ -o examples/my-music.pdf ``` -------------------------------- ### Pull md2pdf Docker Image Source: https://github.com/jmaupetit/md2pdf/blob/main/README.md Pulls the latest Debian-based md2pdf Docker image from Docker Hub. ```bash $ docker pull jmaupetit/md2pdf:latest ``` -------------------------------- ### Pull md2pdf Docker Images Source: https://context7.com/jmaupetit/md2pdf/llms.txt Pull the latest Debian-based or lighter Alpine-based Docker images for md2pdf. These images include all WeasyPrint system dependencies. ```bash docker pull jmaupetit/md2pdf:latest ``` ```bash docker pull jmaupetit/md2pdf:alpine ``` -------------------------------- ### Python Library Usage Source: https://github.com/jmaupetit/md2pdf/blob/main/README.md The md2pdf functionality can be integrated into Python projects by importing the `md2pdf` function. ```APIDOC ## Python Library Usage ### Description Use `md2pdf` as a library in your Python projects for programmatic Markdown to PDF conversion. ### Function Signature ```python md2pdf(pdf, md=None, raw=None, css=None, base_url=None, extras=[], context={}) ``` ### Parameters - `pdf` (str): Output PDF file path. - `raw` (str, optional): Input markdown raw string content (can contain Jinja instructions). - `md` (str, optional): Input markdown file path (can contain Jinja instructions). - `css` (str, optional): Input styles path (CSS). - `base_url` (str, optional): Absolute base path for markdown linked content (as images). - `extras` (list, optional): List of markdown extra extensions to activate. - `context` (dict, optional): Variables to inject to rendered Jinja template. ### Example ```python from md2pdf.core import md2pdf md2pdf(pdf='output.pdf', md='input.md', css='styles.css', extras=['pymdownx.emoji'], context={'variable': 'value'}) ``` ``` -------------------------------- ### Jinja2 Frontmatter Templates Source: https://context7.com/jmaupetit/md2pdf/llms.txt Markdown files can include YAML frontmatter to inject Jinja2 template variables. These variables are merged with programmatic context, with frontmatter values taking precedence. ```APIDOC ## YAML frontmatter context injection in Markdown files ### Description Markdown input files can include a YAML frontmatter block (delimited by `---`) that provides template variables. md2pdf parses the frontmatter and merges it with any programmatic context before rendering the Jinja2 template. Frontmatter values take precedence over values supplied via the `context` argument. ### Request Example ```python from pathlib import Path from md2pdf.core import md2pdf # Example using a Markdown file with frontmatter md2pdf( pdf=Path("output/groceries.pdf"), md=Path("templates/groceries.md"), css=Path("styles/gutenberg-modern.min.css"), ) # Example using raw Markdown with frontmatter and programmatic context raw = "\n".join([ "---", "name: Jane", "id: 42", "---", "Hello {{ name }}", "Your ID is: {{ id }}", ]) md2pdf( pdf=Path("output/greeting.pdf"), raw=raw, context={"name": "John"}, # "Jane" from frontmatter takes precedence ) ``` ### Response No explicit response schema is defined. PDF files are generated with content rendered from the Markdown and Jinja2 template, incorporating frontmatter variables. ``` -------------------------------- ### Creating Quotes in Markdown Source: https://github.com/jmaupetit/md2pdf/blob/main/tests/assets/input.md Use the greater-than symbol to create blockquotes. Quotes are automatically indented. ```markdown > Here is a quote. What this is should be self explanatory. Quotes are automatically indented when they are used. ``` -------------------------------- ### Lint md2pdf Code Source: https://github.com/jmaupetit/md2pdf/blob/main/README.md Lint the code of the md2pdf project to ensure code quality and style consistency. ```bash $ make lint ``` -------------------------------- ### Creating Horizontal Rules in Markdown Source: https://github.com/jmaupetit/md2pdf/blob/main/tests/assets/input.md Use three or more hyphens, asterisks, or underscores to create a horizontal rule. This is useful for visually separating content. ```markdown --- ``` -------------------------------- ### Inline Code Formatting in Markdown Source: https://github.com/jmaupetit/md2pdf/blob/main/tests/assets/input.md Use single backticks to format inline code within a paragraph. This is useful for highlighting code snippets or commands. ```markdown `inline code` ``` -------------------------------- ### Handle ValidationError for missing Markdown content Source: https://context7.com/jmaupetit/md2pdf/llms.txt Demonstrates error handling for cases where no Markdown content is provided to the `md2pdf` function, which raises a `ValidationError`. ```python from pathlib import Path from md2pdf.core import md2pdf from md2pdf.exceptions import ValidationError # 5. Error handling — no content supplied try: md2pdf(pdf=Path("output/empty.pdf")) except ValidationError as exc: print(f"Conversion failed: {exc}") # Output: Conversion failed: No markdown content to process (empty file or raw string) ``` -------------------------------- ### Handle Validation Errors Source: https://context7.com/jmaupetit/md2pdf/llms.txt Catch `ValidationError` exceptions, which are raised when md2pdf cannot proceed due to invalid input, such as missing markdown content or malformed configuration. ```python from pathlib import Path from md2pdf.core import md2pdf from md2pdf.exceptions import ValidationError # Case 1: No content provided try: md2pdf(pdf=Path("output/test.pdf")) except ValidationError as exc: print(exc) # No markdown content to process (empty file or raw string) # Case 2: Empty raw string try: md2pdf(pdf=Path("output/test.pdf"), raw="") except ValidationError as exc: print(exc) # No markdown content to process (empty file or raw string) # Case 3: Invalid --config JSON (CLI) # md2pdf -C "not valid json" -i README.md # Error: Invalid input configuration string (should be valid JSON) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.