Repository navigation
Table fix - #68
Table fix#68
Conversation
WalkthroughThe pull request introduces support for detecting and formatting math content within span elements (using LaTeX notation), enhances table cell handling to detect block-level children, and updates several dependencies. The Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Possibly related PRs
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 inconclusive)
✅ 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: 0
🧹 Nitpick comments (3)
tests/basic_tests.rs (1)
548-553: Use of.anyimproves clarity without changing behavior.Switching from
find(...).is_some()to.any(...)onelement.attrsis idiomatic and keeps the fallback logic unchanged.src/element_handler/td_th.rs (1)
3-8: Faithful‑mode handling fortd/thwith block children is sound and matches the new tests.The
has_block_elementscheck, gated onTranslationMode::Faithful, and the use ofserialize_if_faithful!with-1cleanly force HTML serialization for table cells containing block elements while preserving prior behavior for “simple” cells and all non‑faithful modes. Delegation tohandle_or_serialize_by_parentstill correctly enforces<td>/<th>inside<tr>.If you ever want to micro‑optimize, consider changing
handle_or_serialize_by_parentto accept a slice (&[&str]) so you can pass a static&["tr"]instead of allocating aVecon each call.Also applies to: 11-26
src/element_handler/span.rs (1)
1-36: Span math handling and faithful‑mode behavior are well factored.The handler correctly:
- Detects simple math spans (
class="math math-inline"/"math math-display", single text child) and emits$…$/$$…$$in all modes.- Preserves prior faithful‑mode semantics for non‑math spans by using
serialize_if_faithful!(…, -1)to always serialize as HTML.- Unwraps generic spans to their contents in non‑faithful modes via
walk_children, which is a sensible default.Minor nits you can ignore or address later:
- The doc comment string
"math math-inline/display>looks slightly off; consider fixing the"/>placement.- If you ever need to support more flexible class ordering (e.g. additional classes around
math-inline), you could expand the class check to split on whitespace instead of strict equality.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (8)
Cargo.toml(1 hunks)src/element_handler/element_util.rs(1 hunks)src/element_handler/mod.rs(3 hunks)src/element_handler/span.rs(1 hunks)src/element_handler/table.rs(1 hunks)src/element_handler/td_th.rs(1 hunks)tests/basic_tests.rs(2 hunks)tests/table_tests.rs(2 hunks)
🧰 Additional context used
🧬 Code graph analysis (4)
src/element_handler/mod.rs (1)
src/element_handler/span.rs (1)
span_handler(10-36)
tests/table_tests.rs (2)
src/lib.rs (2)
convert(30-32)convert(106-144)tests/common/mod.rs (1)
convert(8-16)
src/element_handler/td_th.rs (3)
src/dom_walker.rs (1)
is_block_element(433-435)src/element_handler/element_util.rs (1)
handle_or_serialize_by_parent(16-42)src/node_util.rs (1)
get_node_tag_name(5-11)
src/element_handler/element_util.rs (2)
src/element_handler/mod.rs (2)
options(317-317)options(354-356)src/lib.rs (1)
options(171-174)
🔇 Additional comments (6)
Cargo.toml (1)
15-19: Dependency moves and bumps look consistent; rely on test suite for compatibility.Moving
indocto[dependencies]for integration tests and bumpinghtml5ever,markup5ever_rcdom,scraper, andcriterionare all reasonable and self‑contained here. Just make sure the full test suite passes to catch any behavioral changes in parsing/serialization from these version upgrades.Also applies to: 23-24
src/element_handler/table.rs (1)
126-132: Faithful‑mode fallback condition remains correct.The
TranslationMode::Faithful && !all_children_translatedguard is unchanged logically and still correctly forces HTML serialization when any child fails Markdown translation.tests/table_tests.rs (1)
7-7: New block‑cell table test correctly captures the faithful‑mode behavior.Importing
indochere and asserting that a table with<th><p>…</p></th>round‑trips as HTML in faithful mode is aligned with the newtd_th/tablelogic and should guard against regressions in block‑content handling.Also applies to: 183-224
src/element_handler/mod.rs (1)
17-18: Span handler wiring is consistent with existing handler registration.Adding the
spanmodule, importingspan_handler, and registering it for"span"integrates cleanly intoElementHandlerswithout altering other tag behavior. The ordering is safe sincespanhad no prior handler.Also applies to: 49-49, 181-182
src/element_handler/element_util.rs (1)
188-203: Updatedserialize_if_faithfulmacro correctly supports negative thresholds.Documenting
-1as “always serialize in faithful mode” and comparingelement.attrs.len() as i64 > $num_attrs_allowedgives the intended behavior while preserving existing semantics for non‑negative thresholds and non‑faithful modes.tests/basic_tests.rs (1)
656-673: Verify backslash count in the math escaping test expectation.The final assertion tests escaping behavior with input
… a \; bin the HTML, expecting output… a \\; b$$in the result. This requires verification of thespan_handlerimplementation to confirm whether it preserves the original single backslash or if additional escaping is applied. Check the actual behavior and adjust the expected string accordingly if needed.
Please review and merge #67 before this.
This fixes a bug -- table cells in faithful mode cannot be translated to Markdown if they contain block elements.
Summary by CodeRabbit
New Features
Improvements
Tests
Chores
✏️ Tip: You can customize this high-level summary in your review settings.