MCPcopy
hub / github.com/sphinx-doc/sphinx / code_role

Function code_role

sphinx/roles.py:577–599  ·  view source on GitHub ↗
(
    name: str,
    rawtext: str,
    text: str,
    lineno: int,
    inliner: docutils.parsers.rst.states.Inliner,
    options: dict[str, Any] | None = None,
    content: Sequence[str] = (),
)

Source from the content-addressed store, hash-verified

575#
576# TODO: Change to use `SphinxRole` once SphinxRole is fixed to support options.
577def code_role(
578 name: str,
579 rawtext: str,
580 text: str,
581 lineno: int,
582 inliner: docutils.parsers.rst.states.Inliner,
583 options: dict[str, Any] | None = None,
584 content: Sequence[str] = (),
585) -> tuple[list[Node], list[system_message]]:
586 options = _normalize_options(options)
587 language = options.get('language', '')
588 classes = ['code']
589 if language:
590 classes.append('highlight')
591 if 'classes' in options:
592 classes.extend(options['classes'])
593
594 if language and language not in classes:
595 classes.append(language)
596
597 node = nodes.literal(rawtext, text, classes=classes, language=language)
598
599 return [node], []
600
601
602code_role.options = { # type: ignore[attr-defined]

Callers

nothing calls this directly

Calls 3

_normalize_optionsFunction · 0.90
getMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…