o $a @sdZddlZddlmZmZmZmZddlmZm Z ddl m Z m Z ddl mZddlZddlmZddlmZdd lmZdd lmZd ed ed edefddZdeddfddZdedeeeffddZdS)a sphinx.ext.extlinks ~~~~~~~~~~~~~~~~~~~ Extension to save typing and prevent hard-coding of base URLs in the reST files. This adds a new config value called ``extlinks`` that is created like this:: extlinks = {'exmpl': ('https://example.invalid/%s.html', caption), ...} Now you can use e.g. :exmpl:`foo` in your documents. This will create a link to ``https://example.invalid/foo.html``. The link caption depends on the *caption* value given: - If it is ``None``, the caption will be the full URL. - If it is a string, it must contain ``%s`` exactly once. In this case the caption will be *caption* with the role content substituted for ``%s``. You can also give an explicit caption, e.g. :exmpl:`Foo `. Both, the url string and the caption string must escape ``%`` as ``%%``. :copyright: Copyright 2007-2021 by the Sphinx team, see AUTHORS. :license: BSD, see LICENSE for details. N)AnyDictListTuple)nodesutils)Nodesystem_message)Inliner)Sphinx)RemovedInSphinx60Warning)split_explicit_title) RoleFunctionnamebase_urlcaptionreturncszdWnttfytdtdddYnwdurDzdWnttfyCtdtdddYnwigfdtdtd td td td t d t tdt t t t t fffdd }|S)Ndummyztextlinks: Sphinx-6.0 will require base URL to contain exactly one '%s' and all other '%' need to be escaped as '%%'.%z%%z%sz|extlinks: Sphinx-6.0 will require a caption string to contain exactly one '%s' and all other '%' need to be escaped as '%%'.typrawtexttextlinenoinlineroptionscontentrc sVt|}t|\}}} | } |sdur| }n| }tj||d| d} | ggfS)NF)internalrefuri)runescaper r reference) rrrrrrrhas_explicit_titletitlepartfull_urlpnoderr5/usr/lib/python3/dist-packages/sphinx/ext/extlinks.pyrole@s  zmake_link_role..role) TypeError ValueErrorwarningswarnr replacestrintr rrrrr )rrrr(r&r%r'make_link_role*s8   r0appcCs2|jjD]\}\}}||t|||qdS)N)configextlinksitemsadd_roler0)r1rrrr&r&r'setup_link_rolesPsr6cCs&|did|dttjddS)Nr3envzbuilder-initedT)versionparallel_read_safe)add_config_valueconnectr6sphinx__display_version__)r1r&r&r'setupUs  r>)__doc__r+typingrrrrdocutilsrrdocutils.nodesrr docutils.parsers.rst.statesr r<sphinx.applicationr sphinx.deprecationr sphinx.util.nodesr sphinx.util.typingrr.r0r6r>r&r&r&r's     &