Handle Literals in the markdown parser, eg escaped back quotes#56
Conversation
📝 WalkthroughWalkthroughAdds support for marko inline Literal nodes in the markdown parser by treating them identically to RawText nodes, returning a single FormattedTextRun with base styling. Includes version bump and new test coverage for escaped character handling. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@tests/test_markdown_features.py`:
- Around line 284-332: Create a pytest fixture (e.g., parse_markdown) to call
markdown_to_text_elements(markdown) and reuse it across the escaped-character
tests (test_escaped_backtick, test_escaped_asterisk, test_escaped_underscore,
test_escaped_bracket, test_multiple_escaped_characters,
test_escaped_characters_in_list); for each test use the fixture to get the
parsed elements, assert result is non-empty, then assert the parsed elements can
be serialized to the API format (call the existing request/serializer utility
your suite uses) and that the resulting domain model validates (call the domain
model's validate/clean method), failing the test if serialization or validation
raises/errors.
| class TestEscapedCharacters: | ||
| """Test that escaped characters (Literal elements) are handled correctly.""" | ||
|
|
||
| def test_escaped_backtick(self): | ||
| """Test that escaped backticks are handled as Literal elements.""" | ||
| markdown = r"Total SaaS Spend Managed \`25" | ||
| result = markdown_to_text_elements(markdown) | ||
| assert result is not None | ||
| assert len(result) > 0 | ||
| # Verify the escaped backtick was processed correctly | ||
| text_content = "".join( | ||
| elem.text if hasattr(elem, "text") else "" for elem in result | ||
| ) | ||
| assert "`25" in text_content or "25" in text_content | ||
|
|
||
| def test_escaped_asterisk(self): | ||
| """Test that escaped asterisks are handled as Literal elements.""" | ||
| markdown = r"5 \* 10 = 50" | ||
| result = markdown_to_text_elements(markdown) | ||
| assert result is not None | ||
| assert len(result) > 0 | ||
|
|
||
| def test_escaped_underscore(self): | ||
| """Test that escaped underscores are handled as Literal elements.""" | ||
| markdown = r"snake\_case\_variable" | ||
| result = markdown_to_text_elements(markdown) | ||
| assert result is not None | ||
| assert len(result) > 0 | ||
|
|
||
| def test_escaped_bracket(self): | ||
| """Test that escaped brackets are handled as Literal elements.""" | ||
| markdown = r"\[not a link\]" | ||
| result = markdown_to_text_elements(markdown) | ||
| assert result is not None | ||
| assert len(result) > 0 | ||
|
|
||
| def test_multiple_escaped_characters(self): | ||
| """Test multiple escaped characters in one string.""" | ||
| markdown = r"Use \` for code, \* for bold, and \_ for italic" | ||
| result = markdown_to_text_elements(markdown) | ||
| assert result is not None | ||
| assert len(result) > 0 | ||
|
|
||
| def test_escaped_characters_in_list(self): | ||
| """Test escaped characters within list items.""" | ||
| markdown = r"* Item with \`escaped\` backticks" | ||
| result = markdown_to_text_elements(markdown) | ||
| assert result is not None | ||
| assert len(result) > 0 |
There was a problem hiding this comment.
Add fixture reuse and assert serialization/validation for escaped literals.
The new tests repeat setup and only check non-empty results. Please use a pytest fixture for the parse helper and add assertions that requests can be serialized (API format) and that the domain model validates for these cases.
✅ Suggested update
-from gslides_api.agnostic.markdown_parser import UnsupportedMarkdownError
+from gslides_api.agnostic.markdown_parser import UnsupportedMarkdownError, parse_markdown_to_ir
@@
+@pytest.fixture
+def parse_markdown():
+ def _parse(md: str):
+ return markdown_to_text_elements(md)
+ return _parse
@@
- def test_escaped_backtick(self):
+ def test_escaped_backtick(self, parse_markdown):
@@
- result = markdown_to_text_elements(markdown)
+ result = parse_markdown(markdown)
+ # API format serialization check
+ for req in result:
+ if hasattr(req, "model_dump"):
+ req.model_dump(by_alias=True, exclude_none=True)
+ # Domain model validation check
+ parse_markdown_to_ir(markdown).model_dump()(Apply the fixture + validation pattern across the other escaped-character tests.)
As per coding guidelines, “Use pytest fixtures for common setup patterns in tests” and “Test both API format serialization and domain model validation in test files”.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@tests/test_markdown_features.py` around lines 284 - 332, Create a pytest
fixture (e.g., parse_markdown) to call markdown_to_text_elements(markdown) and
reuse it across the escaped-character tests (test_escaped_backtick,
test_escaped_asterisk, test_escaped_underscore, test_escaped_bracket,
test_multiple_escaped_characters, test_escaped_characters_in_list); for each
test use the fixture to get the parsed elements, assert result is non-empty,
then assert the parsed elements can be serialized to the API format (call the
existing request/serializer utility your suite uses) and that the resulting
domain model validates (call the domain model's validate/clean method), failing
the test if serialization or validation raises/errors.
Summary by CodeRabbit
Bug Fixes
Chores