Module config

Module config 

Source
Expand description

Configuration module for styling and formatting PDF output.

This module handles loading and parsing of styling configuration from TOML files. It provides functionality to customize text styles, colors, margins and other formatting options for different Markdown elements in the generated PDF.

§Configuration Structure

The configuration uses TOML format with sections for different element types:

  • The margin section controls document margins (top, right, bottom, left)
  • heading.1, heading.2, heading.3 customize heading styles per level
  • text defines the default text appearance
  • emphasis handles italic text (text or text)
  • strong_emphasis controls bold text styling (text or text)
  • code formats both inline code (code) and code blocks (or*)
  • block_quote styles quoted text (> quote)
  • list_item formats list entries (- item or * item)
  • link controls hyperlink appearance (text)
  • image styles images (alt)
  • table.header and table.cell style table elements
  • A horizontal_rule section styles divider lines (—)

§Code Block Styling (Default: Courier New)

By default, code blocks (or*) and inline code are rendered with Courier New, a fixed-width font suitable for displaying code. You can customize this in the TOML:

[code]
size = 10
fontfamily = "Courier New"  # Use your preferred monospace font
textcolor = { r = 100, g = 100, b = 100 }  # Dark gray
backgroundcolor = { r = 245, g = 245, b = 245 }  # Light gray background
beforespacing = 0.5
afterspacing = 0.5

§Style Properties

Each style section supports the following properties:

  • size - Font size in points (integer)
  • fontfamily - Font family name (string). Recommended monospace fonts: “Courier New”, “Courier”, “Monaco”, “Consolas”
  • textcolor - Text color as RGB tuple: { r = 0, g = 0, b = 0 }
  • backgroundcolor - Background color as RGB tuple: { r = 255, g = 255, b = 255 }
  • beforespacing - Space before element in points (float)
  • afterspacing - Space after element in points (float)
  • alignment - Text alignment: “left”, “center”, “right”, or “justify” (string)
  • bold - Bold text (boolean)
  • italic - Italic text (boolean)
  • underline - Underlined text (boolean)
  • strikethrough - Strikethrough text (boolean)

§Configuration Example

A complete configuration file might look like:

[margin]
top = 10.0
right = 10.0
bottom = 10.0
left = 10.0

[heading.1]
size = 20
bold = true
textcolor = { r = 0, g = 0, b = 0 }

[text]
size = 12
alignment = "left"

[code]
size = 10
fontfamily = "Courier New"  # Monospace font for code blocks (default)
backgroundcolor = { r = 245, g = 245, b = 245 }

The configuration processing follows a pipeline where the TOML file is parsed into style objects that control the PDF generation. The parser extracts style properties and creates corresponding style objects used during rendering.

A complete example configuration file can be found in markdown2pdfrc.example.toml which demonstrates all available styling options.

Enums§

ConfigSource
Configuration source for styling configuration. Determines where the TOML configuration should be loaded from.

Functions§

load_config_from_source
Loads and parses the complete styling configuration based on the provided source.
map_font_family 🔒
Maps a font family name to its corresponding font file path.
parse_alignment 🔒
Parses text alignment from TOML configuration.
parse_color 🔒
Parses an RGB color from a TOML configuration value.
parse_config_string
Parses a TOML configuration string and returns a complete StyleMatch.
parse_style 🔒
Parses a complete text style configuration from TOML.