Debian Codegraph @

tests/test_vectors/sphinx_roles_compat.rst

raw
1 Sphinx Roles with Compatibility Mode
2 =====================================
3
4 This test demonstrates how rich-rst handles Sphinx-specific roles with
5 ``sphinx_compat=True`` (the default behavior).
6
7 Common Sphinx Roles
8 -------------------
9
10 These roles are commonly used in Python docstrings and render as inline code:
11
12 - Function reference: :func:`os.path.join`
13 - Method reference: :meth:`str.format`
14 - Class reference: :class:`pathlib.Path`
15 - Module reference: :mod:`collections.abc`
16 - Attribute reference: :attr:`object.__name__`
17 - Object reference: :obj:`sys.stdout`
18 - Data reference: :data:`sys.maxsize`
19 - Exception reference: :exc:`ValueError`
20 - Type reference: :type:`int`
21
22 Python Domain Roles
23 -------------------
24
25 With explicit python domain prefix:
26
27 - :py:func:`open`
28 - :py:class:`dict`
29 - :py:meth:`list.append`
30 - :py:mod:`os.path`
31
32 Explicit Reference Text
33 -----------------------
34
35 When using explicit reference text (custom display text), only the display text
36 should be shown, not the full reference:
37
38 - :func:`custom name <os.path.join>` should show "custom name"
39 - :class:`MyPath <pathlib.Path>` should show "MyPath"
40 - :meth:`format method <str.format>` should show "format method"
41
42 Mixed Content
43 -------------
44
45 Sphinx roles work seamlessly with other RST markup:
46
47 This paragraph contains a :func:`function_call` and **bold text** and
48 ``regular code`` all together. You can also have :class:`MyClass` in lists:
49
50 - Item with :meth:`method_name` reference
51 - Another :func:`function_ref` here
52 - Regular text without roles
53
54 Realistic Example
55 -----------------
56
57 Here's a realistic Python docstring example::
58
59 def read_config(path, encoding='utf-8'):
60 """
61 Read configuration file from filesystem.
62
63 Parameters
64 ----------
65 path : :class:`pathlib.Path` or str
66 Path to configuration file
67 encoding : str
68 File encoding, see :func:`open` for details
69
70 Returns
71 -------
72 :class:`dict`
73 Parsed configuration dictionary
74
75 See Also
76 --------
77 :func:`write_config` : Write configuration to file
78 :meth:`dict.update` : Update configuration values
79 """
80 pass