converter.QmdToPyConverter
convert.converter.QmdToPyConverter(tool, *, lint_non_exec=False, mode='lint')Convert lines from a .qmd file to .py file.
Attributes
| Name | Type | Description |
|---|---|---|
| lint_non_exec | bool | If True, also lint non-executable Python code chunks. |
| mode | ({'lint', 'format'}, optional) | Conversion mode. lint preserves line alignment for diagnostics. format emits a formatter-friendly Python file with block separators so code can later be spliced back into the original QMD document. |
| python_blocks | list[dict] | List to store metadata for all Python blocks. |
| preserve_line_count | bool | If True, will preserve line alignment. |
| spacing_rules | bool | Whether specified linter reports pycodestyle-style vertical spacing checks, such as blank-line errors between top-level functions, classes, and methods (e.g., E301, E302, E303, E305, and E306). |
Methods
| Name | Description |
|---|---|
| convert | Convert QMD source lines into a lintable Python view. |
convert
convert.converter.QmdToPyConverter.convert(qmd_lines)Convert QMD source lines into a lintable Python view.
This parses the QMD document with Tree-sitter, locates fenced Python code blocks, analyses chunk options and YAML front matter, and then builds an aligned list of Python lines suitable for a linter.
In lint mode, it will typically produce a line-aligned Python file suitable for lint diagnostics. In format mode, it produces a compact Python file containing only the format-eligible code blocks, separated by stable marker comments.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| qmd_lines | list of str | Lines from the input QMD file. | required |
Returns
| Name | Type | Description |
|---|---|---|
| list of str | Python lines representing the lintable view of the QMD file. Depending on configuration, non-Python regions are replaced by placeholder lines so that line numbers stay aligned. |