Le 27/10/23 à 06h52, Shengyu Zhang a écrit :

> 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

Very nice indeed!

The only problem for me is that my sources are primarily in (MyST)
Markdown. But you gave me the idea: creating a custom directive.

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/87jzr79smh.fsf%40example.com.

Reply via email to