How to make an internal link to a heading in sphinx restructuredtext without creating arbitrary labels?

后端 未结 4 659
臣服心动
臣服心动 2020-12-29 03:01

I have a document with many headings and sub-headings. Further into the text I want to link back to one of the headings. How can I do this without the redundancy of :r

4条回答
  •  盖世英雄少女心
    2020-12-29 03:30

    New, better answer for 2016!

    The autosection extension lets you do this easily, with real cross references.

    =============
    Some Document
    =============
    
    
    Internal Headline
    =================
    

    then, later...

    ===============
    Some Other Doc
    ===============
    
    
    A link-  :ref:`Internal Headline`
    

    This extension is built-in, so all you need is to edit conf.py

    extensions = [
        .
        . other
        . extensions
        . already
        . listed
        .
        'sphinx.ext.autosectionlabel',
    ]
    

    The only thing you have to be careful of is that now you can't duplicate internal headlines across the doc collection. (Worth it.)

提交回复
热议问题