Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added documentation for R() #69832

Merged
merged 6 commits into from Jun 16, 2020
Merged

added documentation for R() #69832

merged 6 commits into from Jun 16, 2020

Conversation

samccann
Copy link
Contributor

@samccann samccann commented Jun 2, 2020

SUMMARY

A recent PR added support for R() within module docstrings. This works much like the sphinx :ref: but requires both the link text and the rst label.

ISSUE TYPE
  • Docs Pull Request
COMPONENT NAME

docs.ansible.com

ADDITIONAL INFORMATION

@samccann samccann added affects_2.10 This issue/PR affects Ansible v2.10 docs This issue/PR relates to or includes documentation. labels Jun 2, 2020
@samccann samccann added this to To do in OLD Ansible Documentation via automation Jun 2, 2020
@samccann samccann moved this from To do to In progress in OLD Ansible Documentation Jun 2, 2020
@@ -273,15 +273,18 @@ Linking within module documentation

You can link from your module documentation to other module docs, other resources on docs.ansible.com, and resources elsewhere on the internet. The correct formats for these links are:

* ``L()`` for Links with a heading. For example: ``See L(IOS Platform Options guide,../network/user_guide/platform_ios.html).``
* ``L()`` for links with a heading. For example: ``See L(Ansible Tower,https://www.ansible.com/products/tower).`` As of Ansible 2.10, do not use ``L()`` for relative links to other Ansible documentation. Use ``R()`` instead.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As of Ansible 2.10, do not use L() for relative links to other Ansible documentation. Use R() instead.

So care needed if backporting docs fixes from devel to stable-2.9?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. This is predominantly driven by collections, but it's safer to just start using R() imo. @abadger can correct me if I'm confused on that point :-)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, except that R() inside of options and returndocs won't form a link. At the moment, the tables for options and returns are created using raw-html embedded in rst. Because of that, sphinx doesn't get a chance to process them and thus can't turn it into a link

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't the above true for all links? I don't think L() or U() would create a link within the options or return docs either. Would they?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

L() and U() should form links in the options and return docs. Those take a URL (relative or absolute) and therefore it has all the needed information to make a link in html without having to be processed by sphinx. Here's an example which should show the difference between those two and R()/M():

Here's what could be in the DOCUMENTATION variable:

options:
    - name: verify_certs
      description:
         - Verify the L(certificate, https://en.wikipedia.org/wiki/Public_key_certificate) of the server when True.
         - Use M(community.crypto.openssl_cert) to manage that on your server

Here's an approximation of the jinja template:

.. raw:: html
   <table><tr>
  <td>{% for line in option['description'] %}
    @{line | html_ify}@
  {% endfor %}</td>
  </tr></table>

And here's what combining those two should generate in the rst file:

.. raw:: html
   <table><tr>
   <td>
      Verify the <a href="https://en.wikipedia.org/wiki/Public_key_certificate">certificate</a> of the server when True.
      Use <span class="module">community.crypto.openssl_cert</span> to manage that on your server
  </td>
  </tr></table>

The difference between U() / L() and M() / R() is that the former have enough information to generate an <a href=URL> on their own. The latter only have enough information to generate a sphinx :ref:. The sphinx ref would have to be processed by sphinx (ie: outside of a .. raw:: html block in the rst) in order to turn into a link.

@ansibot ansibot added core_review In order to be merged, this PR must follow the core review workflow. docsite This issue/PR relates to the documentation website. needs_triage Needs a first human triage before being processed. support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels Jun 2, 2020
@samdoran samdoran removed the needs_triage Needs a first human triage before being processed. label Jun 4, 2020
Co-authored-by: John R Barker <john@johnrbarker.com>
Co-authored-by: Alicia Cozine <879121+acozine@users.noreply.github.com>
* ``I()`` for option names. For example: ``Required if I(state=present).``
* ``C()`` for files and option values. For example: ``If not set the environment variable C(ACME_PASSWORD) will be used.``
* ``M()`` for module names. For example: ``See also M(win_copy) or M(win_template).``

.. note::

For modules in a collection, you can only use ``L()`` and ``M()`` for content within that collection. Use ``U()`` to refer to content in a different collection.
For modules in a collection, you can only use ``L()`` and ``M()`` for content within that collection. Use ``U()`` to refer to content in a different collection, or ``R()`` for cross-references to other Ansible documentation, based on the anchor for the page or section of the ``.rst`` file.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few notes about this section

  • L() can be used for content outside the collection. So maybe that part is better phrased as:

    you should only use relative links with L() and U() if the content lives within the collection.

  • relative links can work outside of the collection, but only if you know the directory structure outside of the collection. In particular, that means that a relative link that works with docs-pipeline probably won't work on the collection maintainer's website and vice versa.
  • M() and R() should work inside of a collection always. Pointing outside of a collection, they can work in the docs pipeline. They may be able to work on a collection maintainer's website if they have intersphinx setup appropriately and there's no conflicts in the ref names.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused now.

  1. I thought U() was only for full urls, not relative links? At least that is the example we use.

  2. For L() as a relative link, is that to the collection docs folder? to..??? not sure what a relative link within a collection looks like.

  3. For relative links outside a collection, that just seems problematic and I suggest we don't advertise it.

  4. M() and R() - @acozine - I'm of two minds here - it's a good point that people building their own docsite would need to know they need intersphinx to get them working, but I'm not sure we are/should be in the business of documenting how someone builds their own docsite from module content. I could just add a phrase after that last sentence to say something like "These cross-references to other Ansible documentation work based on the intersphinx extention'. ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. The only difference between 'U()' and 'L()' that I can see in the code is whether to include the bare link or to include a heading. for example:
    <!--  U("../../collections/index.html") turns into -->
    <a href="../../collections/index.html">../../collections/index.html</a>
    
    <!-- L(List of collections, "../../collections/index.html") turns into -->
    <a href="../../collections/index.html">List of collections</a>
    (absolute URLS will work for both of those as well)
  2. Relative links are relative to the html page. So, if I am working on documentation in the yum module from ansible-base, I could refer to the apt module's documentation via: L(The apt module,apt_module.html) because the apt module is also in ansible-base and will therefore be placed in the same directory. If I am working on the yum module docs and i wanted to reference something in another collection, I could use L(Ansible documentation,../../../index.html) to reference the toplevel index page of the docs.ansible.com website. (But on a collection owner's website, that might not be the correct location for what they want to reference).
  3. Yep. Agreed
  4. I know you're really asking acozine but I just wanted to say I agree, something that says this is possible but points them elsewhere to get the details seems like a good compromise. Although, we may want people to know that if they're only developing for publication on docs.ansible.com, they don't have to know about intersphinx?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay so U() is for raw links so to speak (no title) and L() includes a title for the link.
Relative linking needs more explanation, and I think we should limit it to -use docs.ansible.com relative links only if you are in ansible base. Use relative links in your collection only to your own collection. Use L() or U() to link from your collection to docs.ansible.com pages outside your collection.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed in #ansible-doc and we will mention intersphinx w/ a link to the intersphinx docs for how to get M() and R() working on a separate docsite.

@acozine acozine merged commit c9c8cd3 into ansible:devel Jun 16, 2020
@samccann samccann deleted the doc_r branch June 24, 2020 15:03
@samccann samccann moved this from In progress to Done in OLD Ansible Documentation Jun 29, 2020
@ansible ansible locked and limited conversation to collaborators Jul 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.10 This issue/PR affects Ansible v2.10 core_review In order to be merged, this PR must follow the core review workflow. docs This issue/PR relates to or includes documentation. docsite This issue/PR relates to the documentation website. support:core This issue/PR relates to code supported by the Ansible Engineering Team.
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

6 participants