Consume this block and add actions to the give queue for formatting. This may trim lines from the end of the block and add them to the queue for printing as-is. For example, this happens when there are trailing empty lines, as we would like to preserve those since they aren't generally treated as part of the code block.
(mut self, queue: &mut VecDeque<CodeExampleAddAction<'src>>)
| 1248 | /// empty lines, as we would like to preserve those since they aren't |
| 1249 | /// generally treated as part of the code block. |
| 1250 | fn push_format_action(mut self, queue: &mut VecDeque<CodeExampleAddAction<'src>>) { |
| 1251 | let has_non_whitespace = |line: &CodeExampleLine| { |
| 1252 | line.original |
| 1253 | .line |
| 1254 | .chars() |
| 1255 | .any(|ch| !is_python_whitespace(ch)) |
| 1256 | }; |
| 1257 | let first_trailing_empty_line = self |
| 1258 | .lines |
| 1259 | .iter() |
| 1260 | .rposition(has_non_whitespace) |
| 1261 | .map_or(0, |i| i + 1); |
| 1262 | let trailing_lines = self.lines.split_off(first_trailing_empty_line); |
| 1263 | queue.push_back(CodeExampleAddAction::Format { |
| 1264 | kind: CodeExampleKind::Rst(self), |
| 1265 | }); |
| 1266 | queue.extend( |
| 1267 | trailing_lines |
| 1268 | .into_iter() |
| 1269 | .map(|line| CodeExampleAddAction::Print { |
| 1270 | original: line.original, |
| 1271 | }), |
| 1272 | ); |
| 1273 | } |
| 1274 | |
| 1275 | /// Consume this block and turn it into a reset action. |
| 1276 | /// |
no test coverage detected