Hi,

At present, Sphinx assigns numbers to code-blocks having a caption. So
this is intended behavior.

>If true, figures, tables and code-blocks are automatically numbered if they 
>have a caption. The numref role is enabled. Obeyed so far only by HTML and 
>LaTeX builders. Default is False.
>https://www.sphinx-doc.org/en/master/usage/configuration.html?highlight=numref#confval-numfig

Thanks,
Takeshi KOMIYA

2020年5月24日(日) 20:38 Stefano David <[email protected]>:
>
> Hi,
>
>
> I am not sure if the behaviour of the numref role has changed in recent 
> times; I refer to this old issue by jfbu: 
> https://github.com/sphinx-doc/sphinx/issues/3012
> In Sphinx v3.0.3, the snippet in the issue does not not compile as expected, 
> because there is no :name: attached to the code-block. So far so good, given 
> the explanation in the issue.
>
>
>
> However, to my wonder, that code does not compile even if I replace :content: 
> foo with :name: foo! It is necessary to add both :caption: AND :name: to 
> code-block, for numref to work (they can have different values, by the way).
>
>
> With examples:
>
>
> ***** code 1 *****
>
> .. code-block:: python
>    :name: foo
>
>       def foo():
>           return None
>
> ***** code 2 *****
>
> .. code-block:: python
>    :name: foo
>    :caption: foo bar
>
>       def foo():
>           return None
> *****
>
> Code 1 shows a warning and does not create a reference, while code 2 works. 
> Is this the correct behaviour and I am missing something, or is it a bug? In 
> the first case, then the documentation at [1] (which is the same text as 
> mentioned by Jean Francois [2]) is misleading or wrong, in the second case I 
> would open an issue.
>
> Cheers,
> Stefano
>
> [1] 
> https://www.sphinx-doc.org/en/stable/usage/restructuredtext/directives.html#showing-code-examples
>
> [2] https://www.sphinx-doc.org/en/1.4/markup/code.html
>
> --
> 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 [email protected].
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/sphinx-users/5494546c-180f-43ae-af90-2e91a474ab01%40googlegroups.com.

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sphinx-users/CAFmkQANVD7KkO%3D8ifXDmJKU_GVEM7et4B6vxDT4yWW86-uuoYg%40mail.gmail.com.

Reply via email to