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

Method run

sphinx/directives/code.py:119–185  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

117 }
118
119 def run(self) -> list[Node]:
120 document = self.state.document
121 code = '\n'.join(self.content)
122 source, line = self.state_machine.get_source_and_line(self.lineno)
123 location: tuple[str, int] | None = (
124 (source, line) if source is not None and line is not None else None
125 )
126
127 linespec = self.options.get('emphasize-lines')
128 if linespec:
129 try:
130 nlines = len(self.content)
131 hl_lines = parse_line_num_spec(linespec, nlines)
132 if any(i >= nlines for i in hl_lines):
133 logger.warning(
134 __('line number spec is out of range(1-%d): %r'),
135 nlines,
136 self.options['emphasize-lines'],
137 location=location,
138 )
139
140 hl_lines = [x + 1 for x in hl_lines if x < nlines]
141 except ValueError as err:
142 return [document.reporter.warning(err, line=self.lineno)]
143 else:
144 hl_lines = None
145
146 if 'dedent' in self.options:
147 lines = code.splitlines(True)
148 lines = dedent_lines(lines, self.options['dedent'], location=location)
149 code = ''.join(lines)
150
151 literal: Element = nodes.literal_block(code, code)
152 if 'linenos' in self.options or 'lineno-start' in self.options:
153 literal['linenos'] = True
154 literal['classes'] += self.options.get('class', [])
155 literal['force'] = 'force' in self.options
156 if self.arguments:
157 # highlight language specified
158 literal['language'] = self.arguments[0]
159 else:
160 # no highlight language specified. Then this directive refers the current
161 # highlight setting via ``highlight`` directive or ``highlight_language``
162 # configuration.
163 literal['language'] = (
164 self.env.current_document.highlight_language
165 or self.config.highlight_language
166 )
167 extra_args = literal['highlight_args'] = {}
168 if hl_lines is not None:
169 extra_args['hl_lines'] = hl_lines
170 if 'lineno-start' in self.options:
171 extra_args['linenostart'] = self.options['lineno-start']
172 self.set_source_info(literal)
173
174 caption = self.options.get('caption')
175 if caption:
176 try:

Callers

nothing calls this directly

Calls 8

parse_line_num_specFunction · 0.90
dedent_linesFunction · 0.85
container_wrapperFunction · 0.85
joinMethod · 0.45
getMethod · 0.45
warningMethod · 0.45
set_source_infoMethod · 0.45
add_nameMethod · 0.45

Tested by

no test coverage detected