Skip to content

Handle Literals in the markdown parser, eg escaped back quotes#56

Merged
ZmeiGorynych merged 1 commit intomainfrom
egor/dev-1122-handle-literal-objects-eg-escaped-back-quotes-in-the
Feb 18, 2026
Merged

Handle Literals in the markdown parser, eg escaped back quotes#56
ZmeiGorynych merged 1 commit intomainfrom
egor/dev-1122-handle-literal-objects-eg-escaped-back-quotes-in-the

Conversation

@ZmeiGorynych
Copy link
Member

@ZmeiGorynych ZmeiGorynych commented Feb 17, 2026

Summary by CodeRabbit

  • Bug Fixes

    • Fixed markdown parser to properly handle escaped characters (backticks, asterisks, underscores, brackets), rendering them as literal text without applying unintended formatting.
  • Chores

    • Version updated to 0.3.5

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 17, 2026

📝 Walkthrough

Walkthrough

Adds 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

Cohort / File(s) Summary
Markdown Parser Enhancement
gslides_api/agnostic/markdown_parser.py
Added handling for marko Literal nodes in _process_inline_node to preserve escaped character content without additional styling.
Test Coverage
tests/test_markdown_features.py
Added TestEscapedCharacters class with test methods validating escaped backticks, asterisks, underscores, and brackets are correctly parsed as Literal elements.
Version Bump
pyproject.toml
Updated package version from 0.3.4 to 0.3.5.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 With whiskers twitched at escaped chars so bright,
Literal nodes now parse just right!
Backticks and asterisks, no more astray,
A version hop marks this perfect day!

🚥 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 captures the main change: adding support for Literal nodes (escaped characters like backticks) in the markdown parser.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch egor/dev-1122-handle-literal-objects-eg-escaped-back-quotes-in-the

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

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

🤖 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.

Comment on lines +284 to +332
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
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 | 🟠 Major

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.

@ZmeiGorynych ZmeiGorynych merged commit 605b785 into main Feb 18, 2026
3 checks passed
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.

1 participant