Skip to content

Conversation

@ZmeiGorynych
Copy link
Member

@ZmeiGorynych ZmeiGorynych commented Jan 20, 2026

Summary by CodeRabbit

  • New Features

    • Added a public UnsupportedMarkdownError export for signaling unsupported Markdown.
    • Added a strict (default: true) option across Markdown parsing and text-writing APIs — strict mode raises on unsupported constructs; lenient mode logs and skips them.
    • Propagated strict behavior to text elements, shapes, and table cell text writing.
  • Tests

    • Added tests covering unsupported Markdown handling in strict and lenient modes, and top-level import of the new error.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 20, 2026

📝 Walkthrough

Walkthrough

Adds an UnsupportedMarkdownError exception and a strict: bool = True flag across the markdown-to-IR pipeline and text-writing APIs; when strict is True unsupported Markdown raises the exception, otherwise elements are logged and skipped.

Changes

Cohort / File(s) Summary
Core markdown parser
gslides_api/agnostic/markdown_parser.py
Adds UnsupportedMarkdownError; adds strict: bool = True to parse_markdown_to_ir and all internal helpers; unsupported-element handling now raises in strict mode or logs-and-skips when non-strict.
Top-level export
gslides_api/__init__.py
Re-exports UnsupportedMarkdownError from gslides_api.agnostic.markdown_parser.
Element text writers
gslides_api/element/shape.py, gslides_api/element/text_content.py, gslides_api/element/table.py
Thread strict: bool = True through public write APIs (ShapeElement.write_text, TextContent.write_text_requests, TableElement.write_text_to_cell_requests / write_text_to_cell) to propagate markdown strictness.
Markdown helper
gslides_api/markdown/from_markdown.py
Adds strict: bool = True to markdown_to_text_elements() and forwards it to parse_markdown_to_ir().
Tests
tests/test_markdown_features.py
Adds TestUnsupportedMarkdownElements verifying strict vs non-strict behavior for fenced code blocks, quotes, code blocks, images, auto-links; verifies top-level import of UnsupportedMarkdownError.

Sequence Diagram(s)

(omitted)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

🐰 In a burrow of lines and tags I play,

I sniff for markdown that goes astray.
If strict I stand, I thump and declare,
If gentle, I skip with soft rabbit care.
Hopping through changes — hooray! 🥕

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely describes the main change: adding a strict mode option to the markdown parser to raise errors on unsupported elements.
Docstring Coverage ✅ Passed Docstring coverage is 90.91% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Comment @coderabbitai help to get the list of available commands and usage tips.

… egor/dev-1067-add-option-for-gslides-markdown-parser-to-raise-on

# Conflicts:
#	gslides_api/element/table.py
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@tests/test_markdown_features.py`:
- Around line 278-282: In test_exception_is_exported remove the stray orphaned
comment line ("# Some malformed markdown might legitimately fail") inside the
test function; edit the test_exception_is_exported method so it only contains
the docstring, the import aliasing of UnsupportedMarkdownError and the assertion
(i.e. reference the test_exception_is_exported function and
UnsupportedMarkdownError to locate and delete that leftover comment).
🧹 Nitpick comments (3)
gslides_api/agnostic/markdown_parser.py (2)

14-17: Consider removing redundant pass statement.

The pass statement is unnecessary when a class body already contains a docstring.

♻️ Suggested simplification
 class UnsupportedMarkdownError(ValueError):
     """Raised when markdown contains elements that cannot be converted to the target format."""
-
-    pass

142-149: Consider centralizing error message construction.

The error message pattern is repeated in three locations (lines 143-146, 269-272, 344-347). This could be simplified by adding a factory method to UnsupportedMarkdownError, which would also address the Ruff TRY003 hint about long messages outside exception classes.

♻️ Suggested refactor

Update the exception class:

class UnsupportedMarkdownError(ValueError):
    """Raised when markdown contains elements that cannot be converted to the target format."""

    `@classmethod`
    def for_element(cls, element_type: str, node_name: str) -> "UnsupportedMarkdownError":
        return cls(
            f"Unsupported {element_type} element: {node_name}. "
            f"Use strict=False to skip unsupported elements."
        )

Then replace the inline raises:

-            raise UnsupportedMarkdownError(
-                f"Unsupported block element: {type(node).__name__}. "
-                f"Use strict=False to skip unsupported elements."
-            )
+            raise UnsupportedMarkdownError.for_element("block", type(node).__name__)
gslides_api/element/table.py (1)

152-215: Expose strict on higher-level table update helpers.

Now that strict is plumbed into the cell write path, consider threading a strict parameter through content_update_requests(...) and create_element_from_markdown_requests(...) so table creation from markdown can opt into lenient behavior too.

Comment on lines +278 to 282
def test_exception_is_exported(self):
"""Test that UnsupportedMarkdownError can be imported from the package."""
from gslides_api import UnsupportedMarkdownError as ImportedError
assert ImportedError is UnsupportedMarkdownError
# Some malformed markdown might legitimately fail
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Remove orphaned comment.

Line 282 contains an orphaned comment that appears to be a leftover from a previous test case.

🧹 Suggested fix
     def test_exception_is_exported(self):
         """Test that UnsupportedMarkdownError can be imported from the package."""
         from gslides_api import UnsupportedMarkdownError as ImportedError
         assert ImportedError is UnsupportedMarkdownError
-                # Some malformed markdown might legitimately fail
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
def test_exception_is_exported(self):
"""Test that UnsupportedMarkdownError can be imported from the package."""
from gslides_api import UnsupportedMarkdownError as ImportedError
assert ImportedError is UnsupportedMarkdownError
# Some malformed markdown might legitimately fail
def test_exception_is_exported(self):
"""Test that UnsupportedMarkdownError can be imported from the package."""
from gslides_api import UnsupportedMarkdownError as ImportedError
assert ImportedError is UnsupportedMarkdownError
🤖 Prompt for AI Agents
In `@tests/test_markdown_features.py` around lines 278 - 282, In
test_exception_is_exported remove the stray orphaned comment line ("# Some
malformed markdown might legitimately fail") inside the test function; edit the
test_exception_is_exported method so it only contains the docstring, the import
aliasing of UnsupportedMarkdownError and the assertion (i.e. reference the
test_exception_is_exported function and UnsupportedMarkdownError to locate and
delete that leftover comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants