promptprep.formatters module
Makes your code look nice in different output formats.
- class promptprep.formatters.BaseFormatter[source]
Bases:
ABCThe foundation for all our formatters.
- abstract format_code_content(content: str, file_path: str) str[source]
Format code content with line numbers.
- class promptprep.formatters.CustomTemplateFormatter(template_file: str, base_format: str = 'plain')[source]
Bases:
BaseFormatterLets you design your own output format using a template file.
Your template can use these placeholders: - ${DIRECTORY_TREE} - Shows your folder structure - ${FILE_HEADER:path} - Adds a header for each file - ${FILE_CONTENT:path} - Puts in the actual code - ${METADATA} - Adds stats about your codebase - ${SKIPPED_FILES} - Lists any files that were too big - ${FILES} - All your files with headers and content - ${TITLE} - The main title
- __init__(template_file: str, base_format: str = 'plain')[source]
Initialize custom template formatter.
- Parameters:
template_file – Path to the template file
base_format – The base format to use for sections not defined in the template (plain, markdown, html, highlighted)
- format_code_content(content: str, file_path: str) str[source]
Format code content using the base formatter.
- format_metadata(metadata: Dict[str, Any]) str[source]
Format metadata section using the base formatter.
- format_skipped_files(skipped_files: List[tuple]) str[source]
Format skipped files section using the base formatter.
- render_template(directory_tree: str, files_content: Dict[str, str], metadata: Dict[str, Any], skipped_files: List[tuple], title: str = 'Code Aggregation') str[source]
Render the template with the provided content.
- Parameters:
directory_tree – ASCII representation of the directory tree
files_content – Dictionary mapping file paths to their content
metadata – Dictionary of metadata about the codebase
skipped_files – List of (file_path, size) tuples for skipped files
title – Title of the output (default: “Code Aggregation”)
- Returns:
The rendered template content
- class promptprep.formatters.HighlightedFormatter(html_output: bool = True)[source]
Bases:
BaseFormatterAdds syntax highlighting to make your code pop.
- __init__(html_output: bool = True)[source]
Gets ready to highlight your code.
- Parameters:
html_output – True for web pages, False for terminal colors
- class promptprep.formatters.HtmlFormatter[source]
Bases:
BaseFormatterCreates a nice-looking webpage with your code.
- class promptprep.formatters.MarkdownFormatter[source]
Bases:
BaseFormatterMakes your code look great in Markdown documents.
- class promptprep.formatters.PlainTextFormatter[source]
Bases:
BaseFormatterKeeps things simple with plain text output.
- promptprep.formatters.get_formatter(output_format: str = 'plain', template_file: str | None = None, base_format: str = 'plain') BaseFormatter[source]
Picks the right formatter for your needs.
- Parameters:
output_format – How you want it to look (plain, markdown, html, highlighted, custom)
template_file – Your template file (needed for custom format)
base_format – Backup format for custom templates (defaults to plain)
- Returns:
The formatter that’ll do the job
- Raises:
ValueError – If format is unknown or template is missing when needed