I actually started with subclassing code-block. But it's not a straightforward task. The way I have it now is from the recommendation from sphinx documentation. The directive registration is a kind of black-art. I have to dig deeper into both sphinx and docutils source to come up with the solution.