You could look at Capitalize.py from the PyUNO examples for an example of how to modify document content. There is a lot of boilerplate there, but I guess it could be abstracted away? From the documentation about development of extensions it looks like extensions are really just macros.