Add indent code - #68
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR adds support for Markdown indented code blocks (code blocks created by indenting lines with 4+ spaces) through a new MdIndentCode class. This complements the existing MdCode class which handles fenced code blocks and inline code.
- Implements
MdIndentCodeclass that indents each line with 4 spaces (configurable) - Validates indent parameter (minimum 4 spaces per Markdown spec)
- Provides comprehensive test coverage for edge cases
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| mdfy/elements/indent_code.py | New element class for indented code blocks with validation and configurable indentation |
| tests/elements/indent_code_test.py | Comprehensive test suite covering single/multi-line code, empty lines, whitespace preservation, and special characters |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| """ | ||
|
|
||
| if code is None: | ||
| raise ValueError("Code content cannot be None.") |
There was a problem hiding this comment.
This validation is inconsistent with the existing MdCode class, which logs a warning and sets None to an empty string instead of raising an exception. Consider using the same pattern (warning + default) for consistency across the codebase.
| raise ValueError("Code content cannot be None.") | |
| logger.warning("Code content is None; setting code to empty string.") | |
| code = "" |
| str: String representation of the indented code with 4-space indentation. | ||
|
|
||
| The method: | ||
| - Adds 4 spaces indentation to each line |
There was a problem hiding this comment.
The docstring hardcodes '4-space indentation' but the method uses self.indent which is configurable. Update to reflect that the indentation uses the configured value (e.g., 'String representation of the indented code with configured indentation').
| str: String representation of the indented code with 4-space indentation. | |
| The method: | |
| - Adds 4 spaces indentation to each line | |
| str: String representation of the indented code with configured indentation. | |
| The method: | |
| - Adds configured indentation (self.indent spaces) to each line |
| str: String representation of the indented code with 4-space indentation. | ||
|
|
||
| The method: | ||
| - Adds 4 spaces indentation to each line |
There was a problem hiding this comment.
The documentation hardcodes '4 spaces' but the method uses self.indent which is configurable. Update to reflect that the indentation uses the configured value (e.g., 'Adds configured indentation to each line').
| str: String representation of the indented code with 4-space indentation. | |
| The method: | |
| - Adds 4 spaces indentation to each line | |
| str: String representation of the indented code with configured indentation. | |
| The method: | |
| - Adds configured indentation to each line |
#57