How to add anchor in list element










3















I have a list in my rst file that looks like this:



- Item 1
- Item 2
- Item 3


It renders something like the following (which is exactly what I want):



  • Item 1

  • Item 2

  • Item 3

I would like to create links for each item, so I did



.. _item-1:

- Item 1

.. _item-1:

- Item 2

.. _item-1:

- Item 3


Now my list renders something like this:



  • Item 1


  • Item 2


  • Item 3

This is clearly happening because of the anchors I inserted between the elements. Is there a way to insert referenc-able anchors inline in sphinx/rST?










share|improve this question


























    3















    I have a list in my rst file that looks like this:



    - Item 1
    - Item 2
    - Item 3


    It renders something like the following (which is exactly what I want):



    • Item 1

    • Item 2

    • Item 3

    I would like to create links for each item, so I did



    .. _item-1:

    - Item 1

    .. _item-1:

    - Item 2

    .. _item-1:

    - Item 3


    Now my list renders something like this:



    • Item 1


    • Item 2


    • Item 3

    This is clearly happening because of the anchors I inserted between the elements. Is there a way to insert referenc-able anchors inline in sphinx/rST?










    share|improve this question
























      3












      3








      3








      I have a list in my rst file that looks like this:



      - Item 1
      - Item 2
      - Item 3


      It renders something like the following (which is exactly what I want):



      • Item 1

      • Item 2

      • Item 3

      I would like to create links for each item, so I did



      .. _item-1:

      - Item 1

      .. _item-1:

      - Item 2

      .. _item-1:

      - Item 3


      Now my list renders something like this:



      • Item 1


      • Item 2


      • Item 3

      This is clearly happening because of the anchors I inserted between the elements. Is there a way to insert referenc-able anchors inline in sphinx/rST?










      share|improve this question














      I have a list in my rst file that looks like this:



      - Item 1
      - Item 2
      - Item 3


      It renders something like the following (which is exactly what I want):



      • Item 1

      • Item 2

      • Item 3

      I would like to create links for each item, so I did



      .. _item-1:

      - Item 1

      .. _item-1:

      - Item 2

      .. _item-1:

      - Item 3


      Now my list renders something like this:



      • Item 1


      • Item 2


      • Item 3

      This is clearly happening because of the anchors I inserted between the elements. Is there a way to insert referenc-able anchors inline in sphinx/rST?







      python python-sphinx restructuredtext






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked May 2 '18 at 15:48









      Mad PhysicistMad Physicist

      38k1674108




      38k1674108






















          1 Answer
          1






          active

          oldest

          votes


















          4














          This is pretty close to the desired result, with funky white space.



           .. _item-1:

          - Item 1

          .. _item-2:

          - Item 2

          .. _item-3:

          - Item 3


          This yields the following output. Note the id attribute is on the parent <ul> instead of the first <li>, but effectively resolves to the same location on the page.



          <ul class="simple" id="item-1">
          <li>Item 1</li>
          <li id="item-2">Item 2</li>
          <li id="item-3">Item 3</li>
          </ul>





          share|improve this answer























          • That is pretty perfect. I really don't mind the "misplaced" ID for the first item. Any idea why this works?

            – Mad Physicist
            May 2 '18 at 20:30












          • White space has meaning in reStructuredText. Indentation of the arbitrary link directive to align with the first character of the list item associates the directive to the context of the list item. More info: docutils.sourceforge.net/docs/user/rst/…

            – Steve Piercy
            May 2 '18 at 22:33










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f50138672%2fhow-to-add-anchor-in-list-element%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          4














          This is pretty close to the desired result, with funky white space.



           .. _item-1:

          - Item 1

          .. _item-2:

          - Item 2

          .. _item-3:

          - Item 3


          This yields the following output. Note the id attribute is on the parent <ul> instead of the first <li>, but effectively resolves to the same location on the page.



          <ul class="simple" id="item-1">
          <li>Item 1</li>
          <li id="item-2">Item 2</li>
          <li id="item-3">Item 3</li>
          </ul>





          share|improve this answer























          • That is pretty perfect. I really don't mind the "misplaced" ID for the first item. Any idea why this works?

            – Mad Physicist
            May 2 '18 at 20:30












          • White space has meaning in reStructuredText. Indentation of the arbitrary link directive to align with the first character of the list item associates the directive to the context of the list item. More info: docutils.sourceforge.net/docs/user/rst/…

            – Steve Piercy
            May 2 '18 at 22:33















          4














          This is pretty close to the desired result, with funky white space.



           .. _item-1:

          - Item 1

          .. _item-2:

          - Item 2

          .. _item-3:

          - Item 3


          This yields the following output. Note the id attribute is on the parent <ul> instead of the first <li>, but effectively resolves to the same location on the page.



          <ul class="simple" id="item-1">
          <li>Item 1</li>
          <li id="item-2">Item 2</li>
          <li id="item-3">Item 3</li>
          </ul>





          share|improve this answer























          • That is pretty perfect. I really don't mind the "misplaced" ID for the first item. Any idea why this works?

            – Mad Physicist
            May 2 '18 at 20:30












          • White space has meaning in reStructuredText. Indentation of the arbitrary link directive to align with the first character of the list item associates the directive to the context of the list item. More info: docutils.sourceforge.net/docs/user/rst/…

            – Steve Piercy
            May 2 '18 at 22:33













          4












          4








          4







          This is pretty close to the desired result, with funky white space.



           .. _item-1:

          - Item 1

          .. _item-2:

          - Item 2

          .. _item-3:

          - Item 3


          This yields the following output. Note the id attribute is on the parent <ul> instead of the first <li>, but effectively resolves to the same location on the page.



          <ul class="simple" id="item-1">
          <li>Item 1</li>
          <li id="item-2">Item 2</li>
          <li id="item-3">Item 3</li>
          </ul>





          share|improve this answer













          This is pretty close to the desired result, with funky white space.



           .. _item-1:

          - Item 1

          .. _item-2:

          - Item 2

          .. _item-3:

          - Item 3


          This yields the following output. Note the id attribute is on the parent <ul> instead of the first <li>, but effectively resolves to the same location on the page.



          <ul class="simple" id="item-1">
          <li>Item 1</li>
          <li id="item-2">Item 2</li>
          <li id="item-3">Item 3</li>
          </ul>






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered May 2 '18 at 16:12









          Steve PiercySteve Piercy

          6,20611637




          6,20611637












          • That is pretty perfect. I really don't mind the "misplaced" ID for the first item. Any idea why this works?

            – Mad Physicist
            May 2 '18 at 20:30












          • White space has meaning in reStructuredText. Indentation of the arbitrary link directive to align with the first character of the list item associates the directive to the context of the list item. More info: docutils.sourceforge.net/docs/user/rst/…

            – Steve Piercy
            May 2 '18 at 22:33

















          • That is pretty perfect. I really don't mind the "misplaced" ID for the first item. Any idea why this works?

            – Mad Physicist
            May 2 '18 at 20:30












          • White space has meaning in reStructuredText. Indentation of the arbitrary link directive to align with the first character of the list item associates the directive to the context of the list item. More info: docutils.sourceforge.net/docs/user/rst/…

            – Steve Piercy
            May 2 '18 at 22:33
















          That is pretty perfect. I really don't mind the "misplaced" ID for the first item. Any idea why this works?

          – Mad Physicist
          May 2 '18 at 20:30






          That is pretty perfect. I really don't mind the "misplaced" ID for the first item. Any idea why this works?

          – Mad Physicist
          May 2 '18 at 20:30














          White space has meaning in reStructuredText. Indentation of the arbitrary link directive to align with the first character of the list item associates the directive to the context of the list item. More info: docutils.sourceforge.net/docs/user/rst/…

          – Steve Piercy
          May 2 '18 at 22:33





          White space has meaning in reStructuredText. Indentation of the arbitrary link directive to align with the first character of the list item associates the directive to the context of the list item. More info: docutils.sourceforge.net/docs/user/rst/…

          – Steve Piercy
          May 2 '18 at 22:33



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f50138672%2fhow-to-add-anchor-in-list-element%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          How to how show current date and time by default on contact form 7 in WordPress without taking input from user in datetimepicker

          Syphilis

          Darth Vader #20