Repository navigation
Add: support pulldown-cmark math. - #66
Conversation
WalkthroughAdds a new span handler to detect and convert math-marked spans to Markdown ( Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Possibly related PRs
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
src/element_handler/element_util.rs (1)
192-192: Consider using a more explicit sentinel mechanism than -1.Using
-1as a sentinel value requires thei64cast and makes the API less type-safe. Consider alternatives such as passing anOption<i64>or a dedicated enum to make the "always serialize" case more explicit.For example:
enum AttrLimit { Max(usize), AlwaysSerialize, }This would make the intent clearer and avoid the need for casting and negative sentinels.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
src/element_handler/element_util.rs(1 hunks)src/element_handler/mod.rs(3 hunks)src/element_handler/span.rs(1 hunks)tests/basic_tests.rs(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
src/element_handler/span.rs (2)
src/element_handler/list.rs (1)
attr(88-88)src/element_handler/code.rs (1)
content(121-121)
src/element_handler/mod.rs (2)
src/element_handler/element_util.rs (1)
serialize_element(46-177)src/element_handler/span.rs (1)
span_handler(10-36)
🔇 Additional comments (7)
tests/basic_tests.rs (1)
669-673: Good test coverage for escaping behavior.This test correctly verifies that Markdown special characters (like
_,*,[,],<,>) inside math delimiters are not escaped, which is the expected behavior for math content.src/element_handler/mod.rs (1)
17-17: LGTM! Proper integration of the span handler.The span module is correctly declared, imported, and registered following the established pattern for other element handlers. The handler is registered before the generic block handlers, which ensures the specific span logic takes precedence.
Also applies to: 26-26, 180-180
src/element_handler/span.rs (4)
19-20: Verify that HTML entities are properly decoded before wrapping in math delimiters.The code accesses text content via
contents.borrow().to_string(), which should provide decoded text. Confirm that HTML entities like<,>,&are properly decoded to their character equivalents before being wrapped in$or$$delimiters.The test on line 672 of
tests/basic_tests.rsincludes HTML entities and expects them decoded in the output, which suggests this works correctly. However, explicit verification would be valuable.Also applies to: 23-24
29-29: Note: Reliance on i64 cast in serialize_if_faithful macro.This call uses
-1as a sentinel value to mean "always serialize in faithful mode", which requires theas i64cast added to theserialize_if_faithful!macro inelement_util.rsline 192. While functional, this creates a subtle dependency between this handler and the macro implementation.
31-35: Fallback logic is appropriate.The fallback correctly returns the concatenated text content of children when not in faithful mode and when the span doesn't match the math pattern. This aligns with the expected behavior for generic span elements.
10-26: [rewritten comment]
[classification tag]src/element_handler/element_util.rs (1)
192-192: Verify that the cast to i64 doesn't affect other usages of this macro.The cast from
usizetoi64enables the use of-1as a sentinel value (as seen inspan.rs). Ensure that all existing call sites ofserialize_if_faithful!throughout the codebase are compatible with this change. Check that all invocations pass values appropriate for i64 parameters and that no edge cases arise from the type conversion.
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (2)
src/element_handler/element_util.rs (1)
188-194: serialize_if_faithful sentinel semantics look correctCasting
attrs.len()toi64makes the-1sentinel work as documented: in faithful mode, any attribute count (including zero) will trigger HTML serialization when$num_attrs_allowedis-1. This aligns with the new comment and keeps the existing “more than N attributes” behavior for non‑negative limits. If you expect broader usage, you might consider explicitly documenting that$num_attrs_allowedis intended to be ani64to avoid surprising type errors at call sites.tests/basic_tests.rs (1)
657-674: Math conversion tests are well‑targeted and readableThe three assertions cover the core behaviors: inline vs. display math wrapping and the “no extra escaping inside math” requirement with a good variety of characters. This is solid coverage for the new span handler. If you later expand math support, you might add follow‑up tests for mixed content (e.g., math spans adjacent to regular text) or faithful mode, but that’s not required for this PR.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/element_handler/element_util.rs(1 hunks)tests/basic_tests.rs(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/element_handler/element_util.rs (2)
src/element_handler/mod.rs (2)
options(316-316)options(353-355)src/lib.rs (1)
options(171-174)
Summary by CodeRabbit
New Features
Bug Fixes
Tests
✏️ Tip: You can customize this high-level summary in your review settings.