Skip to content

rm MdElemRef #325

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Apr 11, 2025
Merged

rm MdElemRef #325

merged 10 commits into from
Apr 11, 2025

Conversation

yshavit
Copy link
Owner

@yshavit yshavit commented Apr 9, 2025

Just use MdElem directly. This simplifies the API (which we'll soon be making public).

Resolves #327.

@yshavit

This comment was marked as resolved.

@yshavit yshavit added the ai-review Tag a PR with this to get an AI review. label Apr 11, 2025
@yshavit yshavit marked this pull request as ready for review April 11, 2025 05:58
Copy link

coderabbitai bot commented Apr 11, 2025

📝 Walkthrough

Walkthrough

The pull request eliminates the intermediary type MdElemRef across the codebase in favor of using MdElem directly. Changes include updating export statements, function signatures, match patterns, and trait implementations. Modules related to Markdown element trees, formatting, serialization, queries, and selectors have been refactored to remove references to MdElemRef. Several enum variants and struct implementations have been renamed or restructured accordingly. The removal of MdElemRef necessitated updates to parsing logic, conversion implementations, and test utilities while ensuring that all Markdown element processing now consistently uses the MdElem type.

Assessment against linked issues

Objective Addressed Explanation
Remove MdElemRef and use MdElem exclusively (#327)

Grade: A

Tip

⚡💬 Agentic Chat (Pro Plan, General Availability)
  • We're introducing multi-step agentic chat in review comments and issue comments, within and outside of PR's. This feature enhances review and issue discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments and add commits to existing pull requests.

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9081585 and 6ce8ca2.

📒 Files selected for processing (3)
  • src/query/selector_try_from.rs (6 hunks)
  • src/select/sel_table.rs (6 hunks)
  • src/select/selector.rs (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/select/selector.rs
  • src/query/selector_try_from.rs
🔇 Additional comments (9)
src/select/sel_table.rs (9)

1-1: Import changes align with PR objective. Grade: A

The updates to imports correctly reflect the shift from MdElemRef to direct MdElem usage, supporting the PR's goal of API simplification.

Also applies to: 4-4


7-7: Struct renamed appropriately. Grade: A

The rename from TableSliceSelector to TableSelector is consistent with the broader refactoring goal of simplifying the API.


12-28: Implementation improves error handling with Result type. Grade: A

The updated implementation:

  1. Works directly with Table instead of TableSlice<'md>, removing lifetime dependencies
  2. Returns Result<MdElem, MdElem> instead of Option<MdElemRef<'md>>, providing better error handling
  3. Properly handles empty tables by returning the original table as an error value

This change improves both the API and error handling capabilities.


31-38: From implementation updated consistently. Grade: A

The implementation correctly uses TableMatcher instead of TableSliceMatcher, maintaining consistency with other changes.


57-65: Test case updated appropriately. Grade: A

The test case has been properly adapted to use TableSelector and handle the new Result return type.


87-94: Test case correctly adapted. Grade: A

This test case has been updated to match the new API, maintaining test coverage for column selection functionality.


108-115: Row selection test properly updated. Grade: A

The test for row selection has been correctly adapted to use the new API and return type.


142-149: Jagged table test updated correctly. Grade: A

This test case has been properly adapted while preserving its purpose of testing table normalization.


162-162: Helper function return type updated. Grade: A

The helper function's return type has been appropriately changed from Line to TableCell to align with the updated type system.


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@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

♻️ Duplicate comments (3)
src/query/selector_try_from.rs (3)

682-685: Same naming inconsistency present

Same observation as above: enum variant is Table but struct is TableSliceMatcher.

Grade: B


693-697: Same naming inconsistency present

Same observation as above: enum variant is Table but struct is TableSliceMatcher.

Grade: B


704-708: Same naming inconsistency present

Same observation as above: enum variant is Table but struct is TableSliceMatcher.

Grade: B

🧹 Nitpick comments (2)
src/query/selector_try_from.rs (2)

121-121: Consider renaming TableSliceMatcher for consistency

While the enum variant has been renamed from TableSlice to Table, the struct name TableSliceMatcher remains unchanged. This inconsistency might cause confusion. Consider renaming the struct to TableMatcher for better alignment with the enum variant.

Grade: B


671-674: Enum variant name updated but struct name unchanged

The enum variant name has been updated to Table, but it still uses the TableSliceMatcher struct. For consistency, consider updating the struct name throughout the codebase.

Grade: B

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a347870 and 9081585.

📒 Files selected for processing (21)
  • src/md_elem/mod.rs (0 hunks)
  • src/md_elem/tree.rs (11 hunks)
  • src/md_elem/tree_ref.rs (9 hunks)
  • src/md_elem/tree_test_utils.rs (1 hunks)
  • src/output/fmt_md.rs (34 hunks)
  • src/output/fmt_md_inlines.rs (2 hunks)
  • src/output/fmt_plain_inline.rs (27 hunks)
  • src/output/tree_ref_serde.rs (16 hunks)
  • src/query/selector_try_from.rs (5 hunks)
  • src/run/run.rs (4 hunks)
  • src/select/api.rs (7 hunks)
  • src/select/match_selector.rs (1 hunks)
  • src/select/sel_code_block.rs (1 hunks)
  • src/select/sel_link_like.rs (2 hunks)
  • src/select/sel_list_item.rs (2 hunks)
  • src/select/sel_section.rs (1 hunks)
  • src/select/sel_single_matcher.rs (2 hunks)
  • src/select/sel_table.rs (6 hunks)
  • src/select/selector.rs (2 hunks)
  • src/select/string_matcher.rs (2 hunks)
  • src/util/utils_for_test.rs (1 hunks)
💤 Files with no reviewable changes (1)
  • src/md_elem/mod.rs
🧰 Additional context used
🧬 Code Graph Analysis (14)
src/select/string_matcher.rs (2)
src/output/fmt_plain_inline.rs (2)
  • html (387-396)
  • inline (251-261)
src/output/fmt_md.rs (2)
  • html (1443-1451)
  • inline (2333-2358)
src/select/sel_list_item.rs (7)
src/select/sel_link_like.rs (2)
  • matches (18-21)
  • matches (36-38)
src/select/match_selector.rs (1)
  • matches (7-7)
src/select/sel_code_block.rs (1)
  • matches (22-34)
src/select/sel_section.rs (1)
  • matches (18-20)
src/select/sel_single_matcher.rs (1)
  • matches (46-48)
src/select/string_matcher.rs (1)
  • matches (20-22)
src/query/traversal.rs (3)
  • matches (7-7)
  • matches (124-126)
  • matches (139-144)
src/output/fmt_md_inlines.rs (1)
src/output/tree_ref_serde.rs (1)
  • doc (368-382)
src/run/run.rs (2)
src/output/fmt_md.rs (2)
  • write_md (61-81)
  • write_md (91-109)
src/output/fmt_plain_inline.rs (1)
  • write_plain (11-17)
src/md_elem/tree_test_utils.rs (1)
src/md_elem/tree.rs (5)
  • from (243-245)
  • from (368-370)
  • from (374-376)
  • from (380-382)
  • from (915-917)
src/util/utils_for_test.rs (7)
src/select/sel_link_like.rs (2)
  • matches (18-21)
  • matches (36-38)
src/select/match_selector.rs (1)
  • matches (7-7)
src/select/sel_code_block.rs (1)
  • matches (22-34)
src/select/sel_section.rs (1)
  • matches (18-20)
src/select/sel_list_item.rs (2)
  • matches (43-48)
  • matches (52-57)
src/select/sel_single_matcher.rs (1)
  • matches (46-48)
src/select/string_matcher.rs (1)
  • matches (20-22)
src/select/sel_single_matcher.rs (7)
src/select/sel_link_like.rs (2)
  • matches (18-21)
  • matches (36-38)
src/select/match_selector.rs (1)
  • matches (7-7)
src/select/sel_code_block.rs (1)
  • matches (22-34)
src/select/sel_section.rs (1)
  • matches (18-20)
src/select/sel_list_item.rs (2)
  • matches (43-48)
  • matches (52-57)
src/select/string_matcher.rs (1)
  • matches (20-22)
src/query/traversal.rs (3)
  • matches (7-7)
  • matches (124-126)
  • matches (139-144)
src/output/tree_ref_serde.rs (1)
src/output/fmt_md_inlines.rs (2)
  • new (74-84)
  • with_capacity (32-37)
src/md_elem/tree_ref.rs (3)
src/output/tree_ref_serde.rs (2)
  • new (151-177)
  • table (582-603)
src/md_elem/tree.rs (4)
  • new (27-32)
  • new (257-260)
  • new (800-812)
  • table (1960-1998)
src/select/sel_table.rs (1)
  • cell (162-167)
src/select/match_selector.rs (8)
src/select/sel_link_like.rs (2)
  • matches (18-21)
  • matches (36-38)
src/select/sel_code_block.rs (1)
  • matches (22-34)
src/select/sel_section.rs (1)
  • matches (18-20)
src/select/sel_list_item.rs (2)
  • matches (43-48)
  • matches (52-57)
src/select/sel_single_matcher.rs (1)
  • matches (46-48)
src/select/string_matcher.rs (1)
  • matches (20-22)
src/select/api.rs (1)
  • try_select (17-17)
src/select/sel_table.rs (1)
  • try_select (13-28)
src/select/sel_table.rs (3)
src/select/api.rs (1)
  • try_select (17-17)
src/md_elem/tree.rs (1)
  • table (1960-1998)
src/md_elem/tree_ref.rs (3)
  • alignments (10-12)
  • rows (14-16)
  • cell (269-274)
src/output/fmt_plain_inline.rs (5)
src/output/fmt_md.rs (3)
  • inline (2333-2358)
  • empty (552-554)
  • html (1443-1451)
src/md_elem/tree_ref.rs (1)
  • cell (269-274)
src/select/sel_table.rs (2)
  • cell (162-167)
  • from (32-37)
src/output/fmt_plain_writer.rs (2)
  • write (54-91)
  • empty (109-111)
src/md_elem/tree_test_utils.rs (1)
  • from (44-48)
src/output/fmt_md.rs (4)
src/output/fmt_plain_inline.rs (4)
  • table (349-364)
  • inline (251-261)
  • cell (614-624)
  • link (441-457)
src/md_elem/tree.rs (1)
  • table (1960-1998)
src/md_elem/tree_ref.rs (1)
  • cell (269-274)
src/util/output.rs (1)
  • without_text_wrapping (119-121)
src/md_elem/tree.rs (4)
src/md_elem/tree_test_utils.rs (1)
  • from (44-48)
src/output/fmt_md_inlines.rs (2)
  • from (392-409)
  • check (495-504)
src/output/fmt_plain_inline.rs (2)
  • html (387-396)
  • inline (251-261)
src/output/fmt_md.rs (2)
  • html (1443-1451)
  • inline (2333-2358)
🔇 Additional comments (166)
src/select/sel_code_block.rs (1)

21-21: Type parameter updated correctly from reference to value type

The implementation of MatchSelector has been correctly updated to use CodeBlock as a value type rather than a reference type (&CodeBlock). This aligns with the PR objective of eliminating MdElemRef in favor of using MdElem directly.

Grade: A

src/select/sel_section.rs (1)

17-17: Appropriate change from reference type to value type

The implementation of MatchSelector has been effectively updated to use Section as a value type rather than a reference type (&Section). This change is consistent with the PR objective of eliminating MdElemRef and using MdElem directly.

Grade: A

src/md_elem/tree_test_utils.rs (2)

40-40: Necessary import added for BlockHtml

The import statement for BlockHtml is correctly added to support the new implementation.

Grade: A


43-49: Appropriate From implementation for BlockHtml

The implementation of From<&str> for BlockHtml is well-structured and follows the standard pattern for this trait. This allows convenient conversion from string slices to BlockHtml instances in test code.

Grade: A

src/select/sel_list_item.rs (2)

1-1: Import changed to use the direct type

The import has been updated to use DetachedListItem directly, aligning with the PR's goal of removing MdElemRef references.

Grade: A


42-44: Implementation updated to work with direct types

The MatchSelector implementation has been properly updated to work with DetachedListItem instead of a reference type. The signature follows the trait's requirements and the destructuring pattern has been adjusted accordingly while preserving the same logic.

Grade: A

src/output/fmt_md_inlines.rs (2)

195-197: Added handling for Doc elements

New match arm correctly processes document elements by recursively searching for footnote references in nested elements. This ensures footnotes are properly processed regardless of their location in the document structure.

Grade: A


226-228: Added handling for ListItem elements

New match arm properly handles list items by recursively searching for footnote references in their content. This completes the implementation by ensuring all element types are properly processed.

Grade: A

src/select/string_matcher.rs (3)

34-34: Added document element handling

New match arm properly supports document elements by checking matches in all contained elements. This ensures consistent string matching behavior across the entire document structure.

Grade: A


55-55: Updated BlockHtml handling

The implementation now correctly accesses the HTML value property directly, which is a more type-safe approach and aligns with the direct element access pattern used throughout the PR.

Grade: A


57-57: Added ListItem handling

New match arm properly handles list items by checking if any of their content elements match the string pattern. This completes the implementation by ensuring all element types can be properly matched against.

Grade: A

src/select/selector.rs (1)

39-39: Improved TODO comment with issue reference

The TODO comment has been updated with a specific reference to issue #315, which improves code clarity and makes it easier to track the outstanding work.

Grade: A

src/util/utils_for_test.rs (1)

88-103: Excellent refactoring of the macro to make it more descriptive and aligned with direct element usage.

The renaming from checked_elem_ref to match_or_panic is a good improvement as it clearly communicates the macro's purpose. The implementation updates correctly handle the direct use of MdElem instead of converting to MdElemRef first, which aligns with the PR objective of eliminating MdElemRef.

Grade: A

src/select/sel_link_like.rs (2)

17-17: Good update to the trait implementation for LinkSelector.

The change from impl MatchSelector<&Link> to impl MatchSelector<Link> correctly shifts to working with the type directly while still using references in the method implementation. This maintains efficiency while simplifying the type system.

Grade: A


35-35: Consistent implementation of the same pattern for ImageSelector.

Like the LinkSelector change, this updates the trait implementation from impl MatchSelector<&Image> to impl MatchSelector<Image> while keeping the reference in the method signature. This maintains a consistent approach across similar selectors.

Grade: A

src/run/run.rs (3)

1-1: Good update to import statements.

Replaced MdElemRef with MdElem in the imports, which is consistent with the PR's goal of removing MdElemRef usage throughout the codebase.

Grade: A


151-151: Effective transition from reference-based to ownership-based model.

Changed from MdElemRef::Doc(&roots) to MdElem::Doc(roots), indicating a shift to an ownership model rather than references. This is a significant but positive change in line with the PR objective.

Grade: A


178-178: Appropriate update to iterator usage.

Changed from .into_iter() to .iter() for both write_md and write_plain calls, which is consistent with the functions now expecting references to MdElem rather than consuming MdElemRef instances.

Grade: A

Also applies to: 191-191

src/select/sel_single_matcher.rs (2)

15-15: Good update to the macro-generated trait implementations.

Changed from impl MatchSelector<&$name> to impl MatchSelector<$name>, consistent with the changes in other files to work with types directly rather than through references in the trait definition.

Grade: A


45-47: Correctly updated HtmlSelector implementation.

Changed from matching against HtmlRef<'_> to BlockHtml, with a corresponding update to access html.value instead of the previous array-like structure. This maintains consistency with the overall refactoring effort.

Grade: A

src/select/sel_table.rs (8)

7-10: Struct introduction looks neat
The new TableSelector struct with headers_matcher and rows_matcher is clear and well-defined.


12-27: Refined selection logic
try_select method correctly normalizes the table before filtering columns and rows. Returning Result<MdElem, MdElem> is consistent with the updated approach.


31-38: From trait
The conversion from TableSliceMatcher to TableSelector is straightforward and aligns with the removal of TableSlice.


57-73: Test: select_all_on_normalized_table
Verifies alignment and rows are maintained properly when fully matched. Implementation looks correct and thorough.


87-95: Test: select_columns_on_normalized_table
Ensures selective retention of columns based on headers. Logical flow is correct.


108-125: Test: select_rows_on_normalized_table
Checks row filtering after normalization. The test reliably covers edge cases.


132-148: Test: jagged_table
Demonstrates proper normalization of uneven rows. The error path is handled well, and the test logic is solid.


160-162: Helper: cell function
Creates a TableCell from a string. Straightforward implementation, no concerns.

src/select/match_selector.rs (2)

7-8: Switch to &I
Changing fn matches(&self, item: &I) -> bool; to take a reference is a memory-friendly choice.


10-22: Option to Result
Replacing Option<MdElemRef> with Result<MdElem, MdElem> provides better clarity for success and error cases. Nicely done.

src/md_elem/tree_ref.rs (11)

5-16: Module and Table impl
The new elem_ref module and Table methods (alignments, rows) maintain a clean interface. No issues found.


25-42: normalize method
Filling missing cells/alignments with defaults helps ensure consistent column counts. Implementation is logical and straightforward.


44-73: retain_columns_by_header
Filtering columns based on header matches is well structured, and the indexing logic is easy to follow.


75-94: retain_rows
Preserving the header row (index 0) while filtering others is sensible, and the short-circuit logic has no apparent pitfalls.


105-120: Test: retain_col
Ensures columns are pruned when header strings match a provided pattern. Behavior matches expectations.


125-156: Test: retain_all_columns_on_jagged_normalized_table
Combines normalization with column filtering to confirm consistent behavior. Good coverage.


159-183: Test: retain_row
Verifies row retention logic and ensures the header row remains intact. Implementation follows the plan correctly.


185-227: Test: retain_rows_on_jagged_normalized_table
Properly checks how rows are conditionally retained after normalization. No concerns.


229-235: cell_matches helper
Uses string-based matching to filter table cells. Straightforward closure approach.


269-274: cell function
Constructs a TableCell from text. Compliments the overall design well.


276-289: simple_to_string function
Generates a readable string for testing. Cleanly implemented.

src/output/tree_ref_serde.rs (16)

151-162: Refactor from slice of references to slice of owned elements
This update simplifies handling of MdElem by avoiding the extra reference layer. Good job on ensuring consistent usage throughout.


192-195: Consolidation of element types
Using MdElem::Doc(doc) and MdElem::BlockQuote(bq) directly streamlines the build logic. No issues spotted.


216-224: Inline Link & Image handling
Directly mapping link/image data into structured fields is clear and maintainable.


228-246: List building
Reading list items into LiSerde is neatly done, with capacity reserved for performance. Looks good.


248-248: Paragraph constructor
Switching to build for paragraphs is consistent with other variants.


252-252: Section logic
Capturing the depth, title, and body is straightforward and consistent with the new approach.


259-259: Table construction
Refined approach for rendering table rows with inline strings. No concerns.


263-264: Inline cells rendering
Extracting each cell's text via inlines_to_string is a clean solution.


274-274: Thematic break variant
Mapping directly to Self::ThematicBreak remains succinct and correct.


275-275: ListItem
Constructing a ListItem variant from MdElem::ListItem is cohesive with other patterns.


306-317: variants_checker! macro
Continuing to include BlockHtml(_) ensures coverage of all enumerations. Nothing to flag.


369-369: Transforming paragraphs
Using MdElem::Doc(paragraphs) in tests is consistent with the new approach.


445-452: Image test
Constructing MdElem::Inline(Inline::Image(...)) with updated structure is valid.


467-474: Link test
Ensuring link references are passed directly into MdElem::Inline(Inline::Link(...)) looks good.


606-606: Repeated variants_checker
Redundant but harmless. Confirms coverage of MdElem variants in tests.


617-624: Serialized output verification
Storing JSON output in actual_bytes and verifying correctness is a robust check.

src/output/fmt_plain_inline.rs (34)

13-13: Iterator signature change
Switching from MdElemRef to &'md MdElem is consistent with the new model.


21-21: Iterator signature in write_top_level
Aligned with direct references to MdElem. No issues.


36-36: write_plain_result signature
Again, the signature update matches the project-wide refactor.


50-50: write_node argument
Passing &MdElem instead of the now-removed reference type is a good simplification.


55-57: Match arms for Doc, BlockQuote, CodeBlock
Dereferencing is consistent, ensuring the correct iteration over child elements.


64-65: Inline & List
Logical transformations from inline and list items are coherent and correct.


67-67: List item iteration
Writing sub-elements with write_plain_result is consistent. Good approach.


154-163: Extended variants_checker
Ensures coverage for newly adjusted BlockHtml usage. No findings.


172-172: Doc empty test
Creating an empty MdElem::Doc to test is good for edge-case coverage.


184-184: Doc not empty test
Ensures multiline text correctness after refactor. Looks correct.


198-198: BlockQuote empty
Retains consistent approach for verifying empty block quotes.


212-212: BlockQuote with content
Checks basic block quote content after changes.


227-227: CodeBlock empty
Good coverage for empty code blocks.


242-242: CodeBlock non-empty
Ensures writing code block content is still correct.


252-255: Inline test
Correctly aggregates nested inline structures.


270-270: Empty list
Provides coverage for empty list scenario.


288-288: Single list item
Validates single-item expansion post-refactor.


312-312: Two items list
Checks multi-item output format.


324-324: Paragraph
Confirms standard paragraph rendering.


340-340: Section
Verifies title and body paragraphs are properly separated.


358-358: Table
Checks that row content is space-separated.


366-385: Table with empty cells
Tests corner cases of empty columns. Great coverage.


388-390: BlockHtml test
Ensures direct HTML pass-through is correct.


402-402: ThematicBreak
Properly ensures no content is printed.


417-417: ListItem single paragraph
Tests item content integrity.


432-432: ListItem multi-paragraph
Multi-paragraph handling is verified.


451-451: Link
Checks link text content in the new approach.


470-470: Image
Confirms alt text is extracted and printed.


488-488: Table slice
Again confirming table layout correctness.


535-535: BlockHtml inline
Checks multiple block structures together.


551-551: Doc with multiple blocks
Ensures break insertion logic is correct for final doc.


597-603: check_plain signature
Refactor from MdElemRef to MdElem in test harness validated thoroughly.


610-610: Check with no breaks
Confirms code correctness under include_breaks: false.


614-624: cell function
Building a table cell from string slices is elegantly done and remains clear.

src/select/api.rs (22)

4-5: Imports for ImageSelector & LinkSelector
Utilizing sel_link_like reaffirms that direct MdElem usage is in place.


11-11: Import TableSelector
Continuing the consistent approach of direct usage.


16-17: try_select returning Result
Refined error handling is more expressive than returning Option.


21-29: Macro-based adapter
Well-structured approach for enumerating adapters. The transformed pattern-matching is neat.


44-55: try_select_node
Matching MdElem variants directly allows precise adapter usage or fallback.


80-80: find_nodes
Swapping MdElemRef with MdElem in search logic is consistent. Capacity usage is a small performance plus.


89-93: Depth-first style recursion
Recursively building results is a robust approach; no concurrency issues visible.


106-106: find_children definition
Centralizing child-finding logic in the selector code is beneficial for clarity.


108-115: Doc variant children
Wrapping each child to unify them under MdElem::Doc as needed. No issues.


116-117: Section & ListItem
Appropriately drilling into the body or items. This mirrors the prior code for direct MdElem usage.


118-119: Paragraph & BlockQuote
Mapping paragraphs/quotes to doc structure or inline sets. Straightforward.


122-123: List iteration
Translating list items into ListItem variants. Nicely done.


135-138: Table row expansions
Capturing each cell as MdElem::Inline is consistent with the rest.


144-144: CodeBlock or ThematicBreak
Returning an empty vector for these ensures no hidden children.


146-147: Inline::Span
Expanding children into inline elements. Clear approach for nested spans.


150-152: Footnote cycle prevention
Tracking with a HashSet to avoid infinite recursion is clever.


158-158: HTML inline as BlockHtml
Separating HTML strings out as block elements. Straightforward.


160-161: Inline link & text
Delegating text into inline children or ignoring if plain text. Correct as per design.


163-163: BlockHtml with no children
Correctly yields no further nodes.


170-170: SearchContext
seen_footnotes approach is consistent with other updates.


201-201: Inline Link test
Replacing MdElemRef with direct MdElem::Inline suits the broader refactor.


210-210: Chained child
Ensures children are recognized as inline text elements.

src/output/fmt_md.rs (21)

63-63: Refactored iterator to use &'md MdElem instead of MdElemRef.
These signature changes look consistent with the overall removal of MdElemRef references.

Grade: A

Also applies to: 93-93


72-72: Switched to passing nodes.into_iter() directly.
This aligns well with the updated iterator signature and cleans up usage of the new approach.

Grade: A


113-113: Inline thematic break via MdElem::ThematicBreak.
Good call to pass the item directly, ensuring consistent code styling with the rest of the match arms.

Grade: A


119-119: Updated write_one_md parameter to use &'md MdElem.
This is a natural extension of removing MdElemRef, ensuring uniform usage across the codebase.

Grade: A


127-128: Match arms simplified to match MdElem directly.
All these case changes from MdElemRef to MdElem reduce indirection. Nicely done.

Grade: A

Also applies to: 130-130, 145-145, 148-148, 156-156, 159-162, 166-167


193-194: Block quote logic now references block body directly.
This straightforward change ensures consistent iteration over the block content.

Grade: A


211-211: Refined write_table function signature.
Using a direct &'md Table parameter aligns with the new approach, maintaining clarity.

Grade: A


233-233: Replaced self.line_to_string(&cell) usage.
Clean usage of borrowed cell references, matching the refactor’s guidelines.

Grade: A


338-338: Using count_longest_opening_backticks(&value).
Consistent pointer usage, avoids unnecessary allocations. Looks good.

Grade: A


350-350: meta_with_space.push_str(&meta).
Clear approach for metadata handling, no concerns here.

Grade: A


502-502: Expanded variants_checker! macro to include BlockHtml(..).
Accurate coverage of the newly supported variant.

Grade: A

Also applies to: 506-506


583-584: Testing multi-paragraph doc with MdElem::Doc(...).
Solid test scenario to ensure the new reference model handles multiple paragraphs.

Grade: A


894-895: Detaching list items under None index with MdElem::ListItem(...).
This clarifies the test for multiple list items in an unordered list scenario.

Grade: A


921-922: Another unordered list test with DetachedListItem(None, ...).
Consistent approach confirming we handle multiple items correctly.

Grade: A


1908-1908: Using vec![link_elem(...)] for inline link creation.
Streamlines link usage, removing MdElemRef references.

Grade: A


1922-1925: Introduced helper fn link_elem(link: Link) -> MdElem.
A neat utility function to reduce repetition, aligning with the new reference style.

Grade: A


2002-2004: Added helper fn image_elem(link: Image) -> MdElem.
Mirrors the link approach for image creation, ensuring consistent test patterns.

Grade: A


2387-2388: Replaced direct slice extension with a for loop.
Slightly more explicit logic that is straightforward to follow.

Grade: A


2393-2393: Refined fn check_render_refs.
This matches the new signature and maintains code uniformity.

Grade: A


2397-2397: Updated fn check_render_refs_with signature.
Aligns seamlessly with the rest of the refactor.

Grade: A


2401-2401: check_render_refs_with_ctx uses nodes.iter().
Ensures references are borrowed within the refactored approach. Nicely done.

Grade: A

Also applies to: 2406-2406

src/md_elem/tree.rs (32)

40-42: Add Doc variant and derive Clone
The new Doc(Vec<MdElem>) variant and Clone derivation enhance flexibility for containing multiple elements.
Grade: A


55-55: Refactor BlockHtml usage
Switching to BlockHtml struct for this variant improves type safety and clarity.
Grade: A


57-59: Consider single-element list vs. detached list
The DetachedListItem question in the comment (#328) is valid. Confirm if fully needed or a single-element list would suffice.
Grade: B


62-64: New DetachedListItem struct
Straightforward tuple usage. No apparent issues, though a named-field struct could improve clarity.
Grade: A


182-183: Added type aliases for table
TableRow and TableCell clarify usage. Nicely done.
Grade: A


185-185: Derive on CodeVariant
Adding Clone and Hash keeps it consistent with the rest of the enum usage.
Grade: A


202-213: BlockHtml struct & Display impl
Providing a Display impl helps with printing, but confirm whether raw HTML output needs sanitization against XSS. Derive expansions look consistent.
Grade: B


219-220: Derive expansions for Text
Eq, Hash, and Clone are aligned with broader usage.
Grade: A


225-226: Add Clone to Link
Consistent addition. No concerns.
Grade: A


231-232: Add Clone to Image
Straightforward and matches other clone derivations.
Grade: A


237-238: Add Clone to FootnoteId
No issues, consistent with other changes.
Grade: A


263-264: Add Clone to LinkDefinition
Keeps the link definition in sync with the rest.
Grade: A


273-274: Add Clone to ListItem
No immediate problems, matches overall pattern.
Grade: A


279-280: Derive expansions for SpanVariant
Makes sense for hashing/ comparisons.
Grade: A


286-287: Derive expansions for TextVariant
Consistent with the rest of the code.
Grade: A


294-295: Add Clone to Section
Seems beneficial for structural copying.
Grade: A


301-302: Add Clone to Paragraph
Straightforward clone usage.
Grade: A


306-307: Add Clone to BlockQuote
Consistent approach, no issues.
Grade: A


311-312: Add Clone to List
Appropriate for duplication scenarios.
Grade: A


317-318: Add Clone to Table
No problems, in line with other derivations.
Grade: A


323-324: Add Clone to CodeBlock
Facilitates copying code blocks as needed.
Grade: A


339-340: Extend CodeOpts with Clone
pub language: String also now hashed. Looks fine.
Grade: A


343-343: Blank line
No functional change here.
Grade: A


344-355: from_for_md_elem! macro
Macro-based approach to reduce boilerplate is neat.
Grade: A


356-356: Blank line
No functional effect.
Grade: A


357-366: Macro expansions for From
Enables easy conversions to MdElem. Good clarity.
Grade: A


367-371: From<String> for BlockHtml
Straightforward approach. No concerns.
Grade: A


372-372: Blank line
No code changes to review.
Grade: A


373-377: Convert Image to MdElem
Implementation neatly inlines the Image.
Grade: A


379-383: Convert Link to MdElem
Mirrors the approach for Image. Looks consistent.
Grade: A


599-599: Handle HTML node as BlockHtml
Consistent with the new BlockHtml struct usage.
Grade: A


730-730: Convert BlockHtml to inline HTML
Double-check if block HTML is intentionally treated as inline text.
Grade: B

@yshavit
Copy link
Owner Author

yshavit commented Apr 11, 2025

@coderabbitai please re-review

Copy link

coderabbitai bot commented Apr 11, 2025

Tip

For best results, initiate chat on the files or code changes.

@yshavit I'll initiate a new review of your PR that removes MdElemRef in favor of using MdElem directly. This will trigger a fresh analysis of all the changes you've made across the codebase.

Grade: A - Your systematic approach to eliminating MdElemRef throughout the codebase while maintaining functionality demonstrates excellent refactoring practice for API simplification.

@yshavit yshavit merged commit 133de33 into main Apr 11, 2025
7 checks passed
@yshavit yshavit deleted the rm-elemref branch April 11, 2025 06:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ai-review Tag a PR with this to get an AI review.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

remove MdElemRef
1 participant