Return `true` if it's a valid code cell. A valid code cell is a cell where: 1. The cell type is [`Cell::Code`] 2. The source doesn't contain a cell magic 3. If the language id is set, it should be `python`
(&self)
| 58 | /// 2. The source doesn't contain a cell magic |
| 59 | /// 3. If the language id is set, it should be `python` |
| 60 | pub(crate) fn is_valid_python_code_cell(&self) -> bool { |
| 61 | let source = match self { |
| 62 | Cell::Code(cell) |
| 63 | if cell |
| 64 | .metadata |
| 65 | .vscode |
| 66 | .as_ref() |
| 67 | .is_none_or(|vscode| vscode.language_id == "python") => |
| 68 | { |
| 69 | &cell.source |
| 70 | } |
| 71 | _ => return false, |
| 72 | }; |
| 73 | // Ignore cells containing cell magic as they act on the entire cell |
| 74 | // as compared to line magic which acts on a single line. |
| 75 | !match source { |
| 76 | SourceValue::String(string) => Self::is_magic_cell(string.lines()), |
| 77 | SourceValue::StringArray(string_array) => { |
| 78 | Self::is_magic_cell(string_array.iter().map(String::as_str)) |
| 79 | } |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | /// Returns `true` if a cell should be ignored due to the use of cell magics. |
| 84 | fn is_magic_cell<'a>(lines: impl Iterator<Item = &'a str>) -> bool { |
no test coverage detected