I wrote an extension that allows users to create directives according reStructuredText template.
In this case, you can create a wrapper directive like "code-block2", and the wrapper generates a real "code-block" with fixed caption and linenos flag. conf.py:: from sphinxnotes.any import Schema, Field as F extensions = ['sphinxnotes.any'] any_schemas = [ Schema('code-block2', attrs={'language': F(referenceable=True)}, content=F(form=F.Form.LINES), description_template=''' .. code-block:: {{ language }} :caption: Your fixed caption :linenos: {% for line in content %}{{ line }} {% endfor %}'''), ] in your documentation:: .. code-block2:: :language: python print('hello, world!') For more details, please check https://github.com/sphinx-notes/any 在2023年10月26日星期四 UTC+8 01:07:36<denis....@gmail.com> 写道: > Hi, > > is there a way to configure Sphinx in order the default code blocks (I > mean the ones for the default language specified thanks to > `highlight_language`) should have: > > - a (fixed) caption ⟨caption⟩, > - and/or lines numbers enabled? > > Indeed, it's boring to have to specifiy each time: > > ┌──── > │ .. code-block:: > │ :caption: ⟨caption⟩ > └──── > > or: > > ┌──── > │ .. code-block:: > │ :linenos: > └──── > > Thanks. > -- > Denis > -- You received this message because you are subscribed to the Google Groups "sphinx-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to sphinx-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sphinx-users/d7b22e41-d8b6-441b-bc12-7a28f34f16e3n%40googlegroups.com.