网页
综合
更新时间 2026-11-17 02:33:46
Roles — Sphinx documentation
自动蜘蛛
www.sphinx-doc.org
正文约 4896 字
Sphinx uses interpreted text roles to insert semantic markup into documents. They are written as :rolename:`content`.
The default role (`content`) has no special meaning by default. You are free to use it for anything you like, e.g. variable names; use the default_role config value to set it to a known role – the any role to find anything or the py:obj role to find Python objects are very useful for this.
See Domains for roles added by domains.
See Cross-references.
Cross-reference roles include:
option (and the deprecated cmdoption)
An inline code example. When used directly, this role just displays the text without syntax highlighting, as a literal.
Displays: By default, inline code such as 1 + 2 just displays without highlighting.
Unlike the code-block directive, this role does not respect the default language set by the highlight directive.
To enable syntax highlighting, you must first use the Docutils role directive to define a custom role associated with a specific language:
To display a multi-line code example, use the code-block directive instead.
Role for inline math. Use like this:
Displays: Since Pythagoras, we know that \(a^2 + b^2 = c^2\).
Same as math:numref.
The following roles don’t do anything special except formatting the text in a different style:
An abbreviation. If the role content contains a parenthesized explanation, it will be treated specially: it will be shown in a tool-tip in HTML, and output only once in LaTeX.
For example: :abbr:`LIFO (last-in, first-out)` displays LIFO.
Added in version 0.6.
The name of an OS-level command, such as rm.
Mark the defining instance of a term in the text. (No index entries are generated.)
For example: binary mode
The name of a file or directory. Within the contents, you can use curly braces to indicate a “variable” part, for example:
Displays: … is installed in /usr/lib/python3.x/site-packages …
In the built documentation, the x will be displayed differently to indicate that it is to be replaced by the Python minor version.
Labels presented as part of an interactive user interface should be marked using guilabel. This includes labels from text-based interfaces such as those created using curses or other text-based libraries. Any label used in the interface should be marked with this role, including button labels, window titles, field names, menu and menu selection names, and even values in selection lists.
Changed in version 1.0: An accelerator key for the GUI label can be included using an ampersand; this will be stripped and displayed underlined in the output (for example: :guilabel:`&Cancel` displays Cancel). To include a literal ampersand, double it.
Mark a sequence of keystrokes. What form the key sequence takes may depend on platform- or application-specific conventions. When there are no relevant conventions, the names of modifier keys should be spelled out, to improve accessibility for new users and non-native speakers. For example, an xemacs key sequence may be marked like :kbd:`C-x C-f`, but without reference to a specific application or platform, the same sequence should be marked as :kbd:`Control-x Control-f`, displaying C-x C-f and Control-x Control-f respectively.
The name of an RFC 822-style mail header. This markup does not imply that the header is being used in an email message, but can be used to refer to any header of the same “style.” This is also used for headers defined by the various MIME specifications. The header name should be entered in the same way it would normally be found in practice, with the camel-casing conventions being preferred where there is more than one common usage. For example: :mailheader:`Content-Type` displays Content-Type.
The name of a make variable.
A reference to a Unix manual page including the section, e.g. :manpage:`ls(1)` displays ls(1). Creates a hyperlink to an external site rendering the manpage if manpages_url is defined.
Changed in version 7.3: Allow specifying a target with <>, like hyperlinks. For example, :manpage:`blah <ls(1)>` displays blah.
Menu selections should be marked using the menuselection role. This is used to mark a complete sequence of menu selections, including selecting submenus and choosing a specific operation, or any subsequence of such a sequence. The names of individual selections should be separated by -->.
For example, to mark the selection “Start > Programs”, use this markup:
Displays: Start ‣ Programs
When including a selection that includes some trailing indicator, such as the ellipsis some operating systems use to indicate that the command opens a dialog, the indicator should be omitted from the selection name.
menuselection also supports ampersand accelerators just like guilabel.
The name of a MIME type, or a component of a MIME type (the major or minor portion, taken alone).
For example: text/plain
The name of a Usenet newsgroup.
For example: comp.lang.python
本页为82搜索生成的网页快照,内容来自站内索引;演示数据的原文链接仅作示例。