Renderer plugins - Betty documentation

Hide navigation sidebar
Hide table of contents sidebar
Skip to content
Back to top
View this page
Toggle table of contents sidebar

# Renderer plugins

Type | `betty.render.Renderer` `&` `betty.plugin.Plugin`
Repository | `betty.render.RENDERER_REPOSITORY`

Renderers convert textual content to HTML. A renderer is often built to support one or more related source content types.

## Creating a renderer

1. Create a new class that extends both `betty.render.Renderer` and `betty.plugin.Plugin` and implements the abstract methods, for example:

       from typing import override
       from betty.machine_name import MachineName
       from betty.plugin import Plugin
       from betty.render import Renderer

       class MyRenderer(Renderer, Plugin):
         @override
         @classmethod
         def plugin_id(cls) -> MachineName:
             return "my-module-my-renderer"

         # Implement remaining abstract methods...
         ...

2. Tell Betty about your renderer by registering it as an entry point. Given the renderer above in a module `my_package.my_module`, add the following to your Python package:

pyproject.toml

    [project.entry-points.'betty.renderer']
    'my-module-my-renderer' = 'my_package.my_module.MyRenderer'

setup.py

    SETUP = {
        'entry_points': {
            'betty.renderer': [
                'my-module-my-renderer=my_package.my_module.MyRenderer',
            ],
        },
    }
    if __name__ == '__main__':
        setup(**SETUP)