Skip to content
Docs

Target Factories

Target factories generate targets programmatically. Instead of specifying every target in your config, a factory can add multiple targets from an external data source or file list.

Say you have a folder of .md files and want a separate PDF for each. Without factories, you’d need a target for each file. With a target factory, add a new target by just adding a new .md file — no config change needed.

The glob factory creates a target for each file matching a pattern:

target_factories:
- glob:
path: "*.md"
- glob:
name_levels: 2
path: "*/*.md"
glob_variables:
jinja_template: template.jinja
ParameterDescription
pathGlob pattern (e.g., *.md, */*.md)
name_levelsDirectory levels in target name (default: 0)
inherit_fromOptional target to inherit settings from
glob_variablesAdditional variables for generated targets

Create your own factories as Python packages.

def my_factory(cfg):
"""Return a dict of target_name: target_config pairs."""
targets = {}
for item in get_items():
targets[item.name] = {
'jinja_template': 'template.jinja',
'output_file': f'{item.name}.pdf',
'data': {'variables': {'title': item.title}}
}
return targets

In pyproject.toml:

[project.entry-points."markmeld.factories"]
my_factory = "mypackage:my_factory"
target_factories:
- my_factory:
custom_param: value