Including additional processing rules directly into the document is an interesting idea. I guess something similar could be done in markdown’s YAML header blocks that many implementations use. However, documents with images and possible templates/CSS already depend on external files anyway, so it seems we can just as well write the additional rules in an external script.
In the markdown world, currently you can for example use pandoc and python or haskell scripts, and a proposal for directives has been discussed.