╔══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╗
║ Sphinx Roles with Compatibility Mode ║
╚══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╝
This test demonstrates how rich-rst handles Sphinx-specific roles with sphinx_compat=True (the default behavior).
╔══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╗
║ Common Sphinx Roles ║
╚══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╝
These roles are commonly used in Python docstrings and render as inline code:
• Function reference: os.path.join
• Method reference: str.format
• Class reference: pathlib.Path
• Module reference: collections.abc
• Attribute reference: object.__name__
• Object reference: sys.stdout
• Data reference: sys.maxsize
• Exception reference: ValueError
• Type reference: int
╔══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╗
║ Python Domain Roles ║
╚══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╝
With explicit python domain prefix:
• open
• dict
• list.append
• os.path
╔══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╗
║ Explicit Reference Text ║
╚══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╝
When using explicit reference text (custom display text), only the display text should be shown, not the full reference:
• custom name should show "custom name"
• MyPath should show "MyPath"
• format method should show "format method"
╔══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╗
║ Mixed Content ║
╚══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╝
Sphinx roles work seamlessly with other RST markup:
This paragraph contains a function_call and bold text and regular code all together. You can also have MyClass in lists:
• Item with method_name reference
• Another function_ref here
• Regular text without roles
╔══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╗
║ Realistic Example ║
╚══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╝
Here's a realistic Python docstring example:
┌─────────────────────────────────────────────────────── python ───────────────────────────────────────────────────────┐
│ def read_config(path, encoding='utf-8'): │
│ """ │
│ Read configuration file from filesystem. │
│ │
│ Parameters │
│ ---------- │
│ path : :class:`pathlib.Path` or str │
│ Path to configuration file │
│ encoding : str │
│ File encoding, see :func:`open` for details │
│ │
│ Returns │
│ ------- │
│ :class:`dict` │
│ Parsed configuration dictionary │
│ │
│ See Also │
│ -------- │
│ :func:`write_config` : Write configuration to file │
│ :meth:`dict.update` : Update configuration values │
│ """ │
│ pass │
└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘