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
marginsection controls document margins (top, right, bottom, left) heading.1,heading.2,heading.3customize heading styles per leveltextdefines the default text appearanceemphasishandles italic text (text or text)strong_emphasiscontrols bold text styling (text or text)codeformats both inline code (code) and code blocks (or*)block_quotestyles quoted text (> quote)list_itemformats list entries (- item or * item)linkcontrols hyperlink appearance (text)imagestyles images ()
table.headerandtable.cellstyle table elements- A
horizontal_rulesection 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§
- Config
Source - 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.