QmdToPyConverter
converter.QmdToPyConverter(linter)
Convert lines from a .qmd file to .py file.
Attributes
in_chunk_options
bool
True if currently at the start of a code chunk, parsing Quarto chunk options or leading blank lines.
in_python
bool
True if currently processing lines inside a Python code chunk.
py_lines
list
Stores the lines to be written to the output Python file.
yaml_eval_default
bool
Default eval setting from YAML front matter.
current_chunk_eval
Optional[bool]
Eval setting for current chunk from chunk options (None if not set).
Methods
convert
converter.QmdToPyConverter.convert(qmd_lines)
Run converter on the provided lines.
Parameters
qmd_lines
List[str]
List containing each line from the Quarto file.
required
Returns
py_lines
List[str]
List of each line for the output Python file.
parse_chunk_eval_option
converter.QmdToPyConverter.parse_chunk_eval_option(stripped)
Parse chunk options to extract eval setting.
Searches for lines like “#| eval: false” or “#| eval: true” within chunk options.
Parameters
stripped
str
The line to parse (with blank space at start removed).
required
Returns
None
Stores the eval setting in self.current_chunk_eval attribute. Sets to True for “true”/“yes”/“1”, False for “false”/“no”/“0”, Does not modify self.current_chunk_eval if no eval option found.
parse_yaml_front_matter
converter.QmdToPyConverter.parse_yaml_front_matter(qmd_lines)
Parse YAML front matter and extract execute.eval setting.
Parameters
qmd_lines
List[str]
List containing each line from the Quarto file.
required
Returns
None
Stores the eval setting in self.yaml_eval_default attribute. Sets to True if no YAML front matter is found or if parsing fails.
process_line
converter.QmdToPyConverter.process_line(original_line)
Process individual lines with state tracking.
Parameters
original_line
str
Line to process.
required
reset
converter.QmdToPyConverter.reset()
Reset the state (except linter and YAML eval default).
should_lint_current_chunk
converter.QmdToPyConverter.should_lint_current_chunk()
Determine if the current chunk should be linted.
Returns
bool
True if chunk should be linted (eval is True), False otherwise.