(self)
| 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: |
nothing calls this directly
no test coverage detected